• Адміністратор
  •  
    Support Ukraine
    If you experience any problems with the forum (it is not visible, there is no way to post messages, or some functionality does not work), please let us know. If you have problems with registration or you did not receive confirmation letter, let us know and we will activate your account manually.
    If you get an "The submitted form was invalid. Try submitting again" error, delete cookies, then try again.
     

Change data type of widget

A branch of the forum to discuss everything that is connected with Huami Zepp OS.

Модератори: asoo, Watchmens

Правила форуму
All communication in this branch should only be in English.
Відповісти
toolsrme
Повідомлень: 19
З нами з: 04 серпня 2023, 18:36
Звідки: Missouri
Has thanked: 9 times
Контактна інформація:

Change data type of widget

Повідомлення 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:

Код: Виділити все

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:

Код: Виділити все

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.
Аватар користувача
SashaCX75
Повідомлень: 820
З нами з: 26 жовтня 2019, 15:18
Звідки: Ukraine
Has thanked: 13 times
Been thanked: 1029 times
Контактна інформація:

Повідомлення SashaCX75 »

I don't know if you can change the widget type. But you can definitely make several different widgets and change their visibility.
toolsrme
Повідомлень: 19
З нами з: 04 серпня 2023, 18:36
Звідки: Missouri
Has thanked: 9 times
Контактна інформація:

Повідомлення 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.
Jason Henry
Повідомлень: 7
З нами з: 05 січня 2024, 10:16
Звідки: London
Has thanked: 1 time
Контактна інформація:

Повідомлення 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.
toolsrme
Повідомлень: 19
З нами з: 04 серпня 2023, 18:36
Звідки: Missouri
Has thanked: 9 times
Контактна інформація:

Повідомлення 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. :)
Відповісти

Повернутись до “Zepp OS”

Хто зараз онлайн

Зараз переглядають цей форум: Немає зареєстрованих користувачів і 2 гостей