Jump to content

Recommended Posts

A widget like that (spin box) is on the ToDo list but with a very low priority. Due to other more important tasks we won't tackle this within the next couple of months.

However, as you mentioned it's possible to create a widget yourself. I can recommend you having a look at our brand new "HowTo: Create a widget" article that is currently work in progress but already very usable: http://wiki.ugfx.org/index.php/Creating_a_widget
Any feedback is highly welcomed.

Let us know if you have any questions. We are happy to help you wherever we can.

Link to post
Share on other sites
  • 2 years later...

I took a stab at this, basing my widget off of the Textedit widget.

So far I have it ignoring letters and safely handling decimals. (If a new decimal point is inserted, the old decimal point is removed)

Those are mostly cosmetic, though. Here's what I intend to do:

  • Create a method to read the number, as a floating point.
  • Change from insertion mode to overwrite mode, as this seems more intuitive for numeric entry.
  • Add support for dial inputs
  • Add support for negative numbers

To make it more like the LabVIEW Numeric Control, you would also need those up/down arrows that emulate a dial input. I think this would make more sense as a separate widget. Honestly, I think they're hard to use, so I'm not planning on implementing that.

Something that bothers me about the Textedit implementation is the dynamic memory allocation. I suppose it's memory-efficient, but since we're limited to 16 digits of precision in Double Floating Point, it seems reasonable to allocate 19 bytes and be done with it. (That's an extra byte each for the decimal and negative symbols and terminating character)

Link to post
Share on other sites

From Valgrind:

==19659== Invalid read of size 1
==19659==    at 0x11300D: strip_spaces 
==19659==    by 0x1132E7: mf_render_aligned 
==19659==    by 0x10E30C: gdispGFillStringBox 
==19659==    by 0x11A6E6: gwinSpinboxDefaultDraw 
==19659==    by 0x1168C9: _gwidgetRedraw 
==19659==    by 0x11781F: WM_Redraw 
==19659==    by 0x117069: _gwinFlushRedraws 
==19659==    by 0x116E1F: RedrawTimerFn 
==19659==    by 0x11503C: GTimerThreadHandler 
==19659==    by 0x49CBFC1: start_thread (in /usr/lib32/libpthread-2.28.so)
==19659==    by 0x4AE0CA5: clone (in /usr/lib32/libc-2.28.so)
==19659==  Address 0x0 is not stack'd, malloc'd or (recently) free'd


I've attached the demo I'm using, which I put in ugfx/demos/gwin/spinbox

Strangely, it works ok for 4 items, but not for 5. (Although the first item is replaced with "f", and the last item doesn't show up)


Anway, I'm done playing with this one for now. It doesn't quite do what I want, and I don't really want to debug the drawing routine. However, storing the value as an integer instead of a float is a good idea, and might very well be more effecient. I think I'll make a function for that too.




Link to post
Share on other sites
  • 3 weeks later...

Hi everyone,

I know it's been a while. I haven't gotten the dial working yet, because as far as I can tell, events aren't triggering the geventEventWait() function on my laptop. I haven't tried on my stm32.

Anyway, I'm running out of time before classes start, and so I wanted to upload my progress for the benefit of the community. I sqaushed it into a single git patch.

What I settled on for the dial input was overwriting the first n digits of the value. This seemed to make more sense than modifying the least significant digit, since the dial input seems to be for analog dials with limited range, rather than rotary encoders. Also, it allows use of the dial without the keyboard - it didn't seem to make much sense to use the dial in conjunction with the keyboard. If someone wanted an exact number, they would just type it in. Anyway, that's what the gwinNumericSetIntVal() is intended for.


Link to post
Share on other sites
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...