[fxruby-users] FXTextField and number of digits after decimal point
Michèle Garoche
migatine at gmail.com
Sat Dec 6 01:55:33 EST 2008
Le 6 déc. 2008 à 01:31, Joel VanderWerf a écrit :
> Lyle Johnson wrote:
>> On Nov 11, 2008, at 11:25 AM, Michèle Garoche wrote:
>>> My question is: Is there a way to use either a TEXTFIELD_INTEGER
>>> or a TEXTFIELD_REAL without losing digits after the decimal point?
>> The lack of display precision has to do with the fact that you're
>> using an FXDataTarget to update the value of the text field.
>> When the FXTextField sets its text from the double-precision float
>> value that it gets from the FXDataTarget, it uses a fixed format
>> like:
>> sprintf(str, "%.*G", 6, value);
>> To use a custom formatting, you'd need to stop using FXDataTarget
>> and instead use a combination of SEL_COMMAND and SEL_UPDATE, e.g.
>> @value_value.connect(SEL_COMMAND) do
>> @value = @value_value.text.to_f
>> end
>> @value_value.connect(SEL_UPDATE) do
>> @value_value.text = @value.to_s # or however you want to
>> format it
>> end
>> Hope this helps,
>> Lyle
>
> Sorry, this is a late response, but for the record:
>
> If you don't want to give up the functionality of data targets, you
> could do this using FoxTails (http://redshift.sourceforge.net/
> foxtails/).
>
> The "observable" attribute and the #field method combine to give
> you similar functionality: attrs that sync with their gui
> representation, and which can be observed by your own handlers.
> Specifying precision is just a bonus. Here's an example and
> screenshot:
>
> require 'foxtails'
>
> include Fox
> include FoxTails
>
> class Thing
> extend Observable
> observable :x, :y
> end
>
> class FieldsWindow < FXMainWindow
> include FTField
> observable :z, :msg
>
> def initialize(*args)
> super
>
> thing = Thing.new
> thing.x = 1.23456
> thing.y = 1.23456789
>
> self.z = 1.23456789
>
> field("x = %6.2f and y = %12.8f and z = %f",
> [thing, :x], [thing, :y], :z)
>
> field("message: %60s", :msg)
>
> thing.when_y CHANGES do |val, old_val|
> if old_val
> self.msg = "You changed y from #{old_val} to #{val}"
> end
> end
> end
>
> def create
> super
> show
> end
> end
>
> class FieldsApp < FTApp
> def initialize
> super("Fields", "TEST")
> FieldsWindow.new(self, "Fields")
> end
> end
>
> FieldsApp.new.run
Thank you very much.
Cheers,
Michèle
<http://micmacfr.homeunix.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081206/8880dd96/attachment-0001.html>
More information about the fxruby-users
mailing list