Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » Questions about Large Numbers and Margins

Author: milesg
03/08/2022 01:31:47
Hello all!

I just ran into a couple of concerns and I was wondering if anyone knows a workaround or further options that I haven't been able to find in the documentation/forums:

I just setup some "Very large numeric values" in the tcMenu designer, but I'm noticing that they don't function the same way that normal int/float items work.

Primarily, I see that if I set them to "0", they aren't displayed in the menu at all. Once I set them to anything larger, I can see the value in the menu items list as normal. Is there a way to display "0" values?

Also, I would like to set a limited range of values that these items can take (similar to int/float items,) Example: 0-1,000,000. However, if I set the item to have 7 digits, there's no way to limit the user from inputting a number larger than 1 on the left-most digit. In this case, I'm actually okay setting the limit to 6 digits (999,999 is close enough), but it would be nice to have such a feature if possible.

When working with these items, just using a setCurrentValue(int) would make this much more intuitive. I'm not sure why we have to use strings, but it works, so no big deal.

----

Regarding margins, I have found some properties while digging through the source code regarding position of menu values, but I can't seem to get anything to work by changing these values. What I'd like to do, is push the menu item values a pixel or 2 off the right edge of the screen (ili9341 in this case) so that they have a little breathing room. This is just an aesthetic preference, but some characters with long vertical lines (M, I, etc.) on right side do appear to be slightly cut off/crowded at the moment.

As always any insight and advice is greatly appreciated.

Thank you so much!


Author: davetcc
03/08/2022 11:44:06
Hi there for the first question it may be that nobody has yet tried to display zero in one of those. Let me try it myself and see what happens.

For the limit, if you need to prevent values within the range then you could handle this using a menu manager observer. It allows you to prevent commit IIRC. See:

http://thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/#listening-for-changes-on-menu-manager

In terms of drawing you can set your own margins at many levels. The code put in the theme file allows you to modify this behaviour and theme files are not overwritten so safe to edit. See:

http://thecoderscorner.com/products/arduino-libraries/tc-menu/themes/rendering-with-themes-icons-grids/

Author: milesg
03/08/2022 20:10:49
Thank you Dave,

I'll look deeper into the observer functions, but at a glance it looks like it might be more trouble than it's worth for my use case.

I increased the itemPadding in the theme file and that seems to help for a quick fix (it increases the padding all around, not just on the right side, but that's fine). I noticed that values which contain the number 1 seem to be pushed further to the right. Must be some quirk of the Adafruit font.

For reference I've attached a photo showing this alignment quirk as well as the 0 value items showing blank (Minimum and Maximum Position items are both Large Number items.)

Thanks again!

EDIT: Whoops, the darn thing shows up in Australia mode on the forums. If you download it, you'll get a clearer view and it should be right-side-up.

[Thumb - IMG_20220803_124332483_HDR.jpg]
Filename IMG_20220803_124332483_HDR.jpg
Description No description given
Filesize 1008 Kbytes
Downloaded 388 time(s)
[Disk] Download


Author: davetcc
04/08/2022 08:19:05


I increased the itemPadding in the theme file and that seems to help for a quick fix (it increases the padding all around, not just on the right side, but that's fine). I noticed that values which contain the number 1 seem to be pushed further to the right. Must be some quirk of the Adafruit font.


For the incorrect sizing, it may be worth creating a test sketch with these characters in and seeing if it is the font, or a problem in tcMenu. Although we are just getting the text bounds direct from the library.

If you have a look at the menu padding object though, it can be configured either with equal values for each side, or a value for each side:

MenuPadding(int top_, int right_, int bottom_, int left_) {
            top = top_;
            bottom = bottom_;
            right = right_;
            left = left_;
        }


This should allow you to set each side separately.

For reference I've attached a photo showing this alignment quirk as well as the 0 value items showing blank (Minimum and Maximum Position items are both Large Number items.)


Yep, wrong way around smilie I'll take a look at these two later, and raise an issue if needed against TcMenuLib.


Author: milesg
10/08/2022 18:02:22
Ah! excellent, I set the right margin to be a few more pixels than the other sides and now things are looking real sharp (The extra pixel shift of the number 1 is barely noticeable when everything is 6 pixels from the edge already) Thank you!

Regarding the empty lines for 0 values on large number items, I'm surprised no one has noticed already, since a new project seems to default the value to 0 on any item that doesn't yet have a different value saved in EEPROM. I'd be very curious to know if I'm somehow the only one seeing this issue, and how I might rectify it.

Thanks again for the advice! Your help is very much appreciated.

Author: davetcc
20/08/2022 07:47:28
Something struck me, I already fixed the issue with initial startup, but have not fully tried it yet in either the example or my own stuff.

What you can do is to use the overloaded version of menuMgr.load, there is an overload now that allows a function that takes no parameteters and returns void to be provided as the 2nd parameter:

menuMgr.load(myMagicKey, [] {
    // do your work when not initialised here.
});


Could you let me know if after using that to pre-initialise it of the first run, you still see odd values in the large number value type.

Author: milesg
21/08/2022 06:59:30
Hi Dave,
Please forgive my ignorance, but I'm not sure if you're asking me to add anything specific to the "do your work..." area in the code snipped you gave. I replaced my menuMgr.load line with yours as written (but added the default magicKey of 0xfade) and found no change in behavior.

But to be clear, I'm also seeing the blank column immediately upon exiting the value-editor after having toggled the value back to zero. This doesn't seem to be directly related to saving/loading the value from EEPROM.

Likewise, I continue to see a blank line in the value column of these menu items even if I had a non-zero value saved already, and then change the value back to zero. This display of the blank column persists through reboots (loading the saved zero value from EEPROM).

In other words, I NEVER see "0" in that column at any time, regardless of reboots/reading from EEPROM, OR even just while navigating the menu before saving any changes to EEPROM.

Please let me know if you'd like me to try anything else. I'm happy to experiment if it can help you.

Thanks!

Author: davetcc
22/08/2022 16:43:25
I've found it, I had an STM32 board in the debugger and found the issue (and already fixed it locally)

https://github.com/davetcc/tcMenuLib/issues/147


Author: davetcc
22/08/2022 17:11:21
Ah yes, that callback allows you to configure things when the board didn't load any settings, IE normally on the first run. But in this case there was an actual bug.

Author: milesg
22/08/2022 18:26:51
Very cool! You're awesome Dave. Thanks so much for your help.




Register / Login  |  Desktop view  |  Jump to top of page