Page 1 of 1
Change data type of widget
Posted: 21 Jan 2024, 04:16
by toolsrme
Is there a way to change the data type of a widget and thus the data it displays?
For example if I have the following:
Code: Select all
text_font = hmUI.createWidget(hmUI.widget.TEXT_FONT, {
x: 0, y: 0, w: 120, h: 96, text_size: 55,
char_space: 0, line_space: 0,
color: 0xFFFF0000,
align_h: hmUI.align.CENTER_H,
align_v: hmUI.align.TOP,
text_style: hmUI.text_style.ELLIPSIS,
type: hmUI.data_type.HEART,
show_level: hmUI.show_level.ONLY_NORMAL,
});
and a button runs code like:
Code: Select all
text_font.setProperty(hmUI.prop.MORE, {type: hmUI.data_type.CAL});
How can I get that change to take and display calories instead of heart rate? Or is this not possible?
Trying to get this to work on a T-Rex 2.
Re: Change data type of widget
Posted: 21 Jan 2024, 14:46
by SashaCX75
I don't know if you can change the widget type. But you can definitely make several different widgets and change their visibility.
Re: Change data type of widget
Posted: 21 Jan 2024, 16:31
by toolsrme
Thanks @SashaCX75
That’s how I’ve done it currently. I have a number of widgets that are the same in all ways except for data_type and rotate through them via display settings. Just trying to simplify the script and cut down on duplication.
Re: Change data type of widget
Posted: 27 Jan 2024, 10:08
by Jason Henry
Possibly related to fitness tracking or health data. In the provided code snippets, you're creating a text widget (`text_font`) initially set to display heart rate (`hmUI.data_type.HEART`). Later, you're attempting to change the data type to calories (`hmUI.data_type.CAL`) with the `setProperty` method.
The approach you've taken seems correct based on the code you've shared. If the library supports dynamic updates to the data type, calling `setProperty` with the new data type should update the widget to display calories instead of heart rate. However, the success of this operation depends on the capabilities and documentation of the library you're using (T-Rex 2 in this case).
Make sure that the library supports the switching of data types for widgets, and check the documentation for any specific instructions or considerations when changing the data type dynamically. If the provided code doesn't work as expected.
It's also worth verifying that the widget (`text_font`) is correctly linked to the UI element you want to modify, and that there are no conflicting settings or restrictions preventing the data type switch.
Re: Change data type of widget
Posted: 28 Jan 2024, 03:13
by toolsrme
Thanks Jason. Yes it is correctly linked as setting its visibility is working just fine. I've looked for documentation on data_type and haven't found anything yet, either way, on whether dynamically changing it is supported or not. Unfortunately not everything is documented as thoroughly as I would like though.
The one thing I haven't checked yet is if you can create the widget initially without defining the data type and then set it for the first time and see if it works. Not sure if it is only settable in the creation or if it's only recognized the first time. This is one of those things that would be nice to have, but hasn't become necessary yet.
