[Solved] Spinner with precision setting

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Baarnus
Just popping in
Just popping in
Posts: 3
Joined: Sun Jul 07, 2013 11:17
Location: Diósd, Hungary

[Solved] Spinner with precision setting

Postby Baarnus » Wed Apr 16, 2014 10:48

Hello everybody!

My question is, how can I limit the digits of a spinner, to set displayed procision.

eg.: 1.00000231 -> 1 or 0.3000021 -> 0.3 etc.

I'm using the setValue(double) function to set the value of the spinner. Do I need to use the setText or there is an inbuilt method for this?

Thanks!

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Spinner with precision setting

Postby Ident » Wed Apr 16, 2014 12:19

I am not sure how you run into this problem because the spinner has a defined offset for each increase/decrease so you can simply set it ti something like "0.01".

The displayed precision should be fine in that case. If you set the value differently then you have to make an even handler for when the value is changed and edit the value using a function that rounds to your desired number of after-comma digits. How to do this is well covered on many sites on the internet. So basically you just need that event handler to make it work for your spinner.
CrazyEddie: "I don't like GUIs"

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Spinner with precision setting

Postby Ident » Thu Apr 17, 2014 12:40

I must correct my last post. Here is the excerpt from #cegui at freenode IRC:

Code: Select all

[14:27:30]   mpreisler   Ident: btw, regarding your reply to the Spinner guy on the forums
[14:27:35]   mpreisler   0.01 is not a nice number for a float
[14:27:43]   mpreisler   it ends up being 0.0100000000000002 or something
[14:27:55]   mpreisler   this is why he gets issues
[14:28:07]   mpreisler   if he uses 2^(-x) he'll be fine
[14:28:07]   Ident   i dont remember having that issue
[14:28:09]   mpreisler   ;-)
[14:28:14]   Ident   and i used 0.01 etc
[14:28:25]   mpreisler   we should use decimal, not float
[14:28:27]   mpreisler   for spinner
[14:28:32]   Ident   decimal?
[14:28:37]   mpreisler   since people think in decimal
[14:28:46]   Ident   we have a decimal type?
[14:28:47]   mpreisler   fixed point
[14:28:49]   mpreisler   no
[14:28:53]   mpreisler   but we can make it
[14:28:55]   mpreisler   easily
[14:29:02]   Ident   do it!
[14:29:05]   Ident   *whip*
[14:29:07]   mpreisler   I would look into how Qt does this
[14:29:11]   mpreisler   yeah, I will do this for 1.0
[14:29:16]   Ident   i guess u just used a long?
[14:29:20]   Ident   alala lala long
[14:29:21]   mpreisler   yeah
[14:29:33]   mpreisler   you can easily convert to float if people want that
[14:29:53]   mpreisler   you just use long and you remember how many digits should be used for fractional part
[14:31:03]   Ident   actually you could just use int for pre and int for after comma
[14:31:06]   Ident   so 2 variables
[14:31:17]   Ident   ah
[14:31:20]   Ident   but that sucks
[14:31:22]   Ident   with increasing
[14:31:31]   Ident   also what will u do if someone tries to type a number in?
[14:31:32]   mpreisler   yes, that sucks
[14:31:33]   Ident   convert it
[14:31:35]   Ident   ?
[14:31:36]   mpreisler   you don't care how you interpret it
[14:31:47]   mpreisler   long long and you remember how many numbers are after the comma/dot/whatever


So clearly I remembered stuff wrong from my last spinner usage, and it also makes sense that it doesn't work so easily, when thinking of float precision. The only way to fix this is really only for us to use some scientific number type or a fixed-comma type, as mpreisler(Kulik) suggested, in CEGUI.
Currently this is not implemented. Increasing by something like 0,125 should work fine though. But I assume you wouldnt like that, nor would I.

Actually this should work as a workaround giving you 100% flexibility: make an event handler for changed-value of your spinner. In the event handler you parse the value to a float in the way you want to display it (using stringstream and precision for example) and then you retrieve the editbox from the spinner, set it to muted (so no events are fired) and then set the text via setText() and then unmute it.
CrazyEddie: "I don't like GUIs"

User avatar
Baarnus
Just popping in
Just popping in
Posts: 3
Joined: Sun Jul 07, 2013 11:17
Location: Diósd, Hungary

Re: Spinner with precision setting

Postby Baarnus » Tue Apr 22, 2014 10:36

Thanks! The rounding solution and setText() work just fine. I was only curoius about are there a simplier way.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: Spinner with precision setting

Postby Ident » Tue Apr 22, 2014 11:37

Glad I could help.
CrazyEddie: "I don't like GUIs"


Return to “Help”

Who is online

Users browsing this forum: No registered users and 6 guests