• 管理员
  •  
    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.

版主: asooWatchmens

版面规则
All communication in this branch should only be in English.
回复
toolsrme
帖子: 19
注册时间: 04 8月 2023, 18:36
来自: Missouri
Has thanked: 9 time
联系:

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
帖子: 823
注册时间: 26 10月 2019, 15:18
来自: Ukraine
Has thanked: 13 time
Been thanked: 1036 time
联系:

帖子 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 8月 2023, 18:36
来自: Missouri
Has thanked: 9 time
联系:

帖子 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 1月 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 8月 2023, 18:36
来自: Missouri
Has thanked: 9 time
联系:

帖子 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”

在线用户

正浏览此版面之用户: 没有注册用户 和 1 访客