mirror of https://github.com/arendst/Tasmota.git
HASPmota support for (#22707)
This commit is contained in:
parent
3412761881
commit
4fd3d9465c
|
@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
|
|||
- Command ``SetOption163 1`` to disable display of Device name in GUI header
|
||||
- Berry `animate.crenel` primitive (#22673)
|
||||
- Berry scroll to Leds_matrix (#22693)
|
||||
- HASPmota support for `tabview`
|
||||
|
||||
### Breaking Changed
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ extern const bclass be_class_lv_qrcode;
|
|||
extern const bclass be_class_lv_chart;
|
||||
extern const bclass be_class_lv_spangroup;
|
||||
extern const bclass be_class_lv_span;
|
||||
extern const bclass be_class_lv_tabview;
|
||||
extern const bclass be_class_lv_button;
|
||||
extern const bclass be_class_lv_image;
|
||||
extern const bclass be_class_lv_buttonmatrix;
|
||||
|
|
|
@ -16,7 +16,7 @@ var classes = [
|
|||
# ported from LVGL 8
|
||||
"colorwheel",
|
||||
# new internal names
|
||||
"button", "image", "buttonmatrix", "msgbox"
|
||||
"button", "image", "buttonmatrix", "msgbox", "tabview"
|
||||
]
|
||||
|
||||
for cl: classes
|
||||
|
|
|
@ -1462,12 +1462,12 @@ class lvh_spinner : lvh_arc
|
|||
# obj: (opt) LVGL object if it already exists and was created prior to init()
|
||||
# parent_lvh: HASPmota parent object defined by `parentid`
|
||||
#====================================================================
|
||||
def init(parent, page, jline)
|
||||
def init(parent, page, jline, lv_instance, parent_obj)
|
||||
var angle = jline.find("angle", 60)
|
||||
var speed = jline.find("speed", 1000)
|
||||
self._lv_obj = lv.spinner(parent)
|
||||
self._lv_obj.set_anim_params(speed, angle)
|
||||
super(self).init(parent, page, jline, self._lv_obj)
|
||||
super(self).init(parent, page, jline, self._lv_obj, parent_obj)
|
||||
end
|
||||
|
||||
def set_angle(t) end
|
||||
|
@ -1735,7 +1735,7 @@ class lvh_dropdown_list : lvh_obj
|
|||
if isinstance(self._parent_lvh, self._page._hm.lvh_dropdown)
|
||||
self._lv_obj = lv.list(self._parent_lvh._lv_obj.get_list()._p)
|
||||
else
|
||||
print("HSP: '_dropdown_list' should have a parent of type 'dropdown'")
|
||||
print("HSP: 'dropdown_list' should have a parent of type 'dropdown'")
|
||||
end
|
||||
super(self).post_init()
|
||||
end
|
||||
|
@ -2056,6 +2056,8 @@ class lvh_span : lvh_root
|
|||
# print(">>> GOOD")
|
||||
self._lv_obj = self._parent_lvh._lv_obj.new_span()
|
||||
self._style = self._lv_obj.get_style()
|
||||
else
|
||||
print("HSP: 'span' should have a parent of type 'spangroup'")
|
||||
end
|
||||
# super(self).post_init() # call super - not needed for lvh_root
|
||||
end
|
||||
|
@ -2160,6 +2162,182 @@ class lvh_span : lvh_root
|
|||
|
||||
end
|
||||
|
||||
#====================================================================
|
||||
# tabview
|
||||
#====================================================================
|
||||
#@ solidify:lvh_tabview,weak
|
||||
class lvh_tabview : lvh_obj
|
||||
static var _lv_class = lv.tabview
|
||||
var _tab_list # list of tabs
|
||||
|
||||
# label do not need a sub-label
|
||||
def post_init()
|
||||
self._tab_list = []
|
||||
super(self).post_init() # call super -- not needed
|
||||
end
|
||||
|
||||
#====================================================================
|
||||
# direction for buttons
|
||||
#====================================================================
|
||||
static var _direction = [
|
||||
lv.DIR_NONE, # 0 = none
|
||||
lv.DIR_TOP, # 1 = top
|
||||
lv.DIR_BOTTOM, # 2 = bottom
|
||||
lv.DIR_LEFT, # 3 = left
|
||||
lv.DIR_RIGHT, # 4 = right
|
||||
]
|
||||
def set_btn_pos(v)
|
||||
v = int(v)
|
||||
if (v == nil) || (v < 0) || (v >= size(self._direction))
|
||||
v = 0
|
||||
end
|
||||
var direction = self._direction[v]
|
||||
self._lv_obj.set_tab_bar_position(direction)
|
||||
end
|
||||
|
||||
#====================================================================
|
||||
# management of `_tab_list` list
|
||||
#====================================================================
|
||||
# add lvh_tab instance as they are created
|
||||
def push_tab(t)
|
||||
self._tab_list.push(t)
|
||||
end
|
||||
# returns the index of the tab instance, or `nil` if not found
|
||||
def find_tab(t)
|
||||
return self._tab_list.find(t)
|
||||
end
|
||||
|
||||
#====================================================================
|
||||
# count read-only attribute, returns number of tabs
|
||||
#====================================================================
|
||||
def get_count()
|
||||
return self._lv_obj.get_tab_count()
|
||||
end
|
||||
def get_val()
|
||||
return self._lv_obj.get_tab_active()
|
||||
end
|
||||
# change current tab
|
||||
# v: value of new tab
|
||||
# stop: (opt) if true, don't defer again to avoid infinite loop
|
||||
def set_val(v, stop)
|
||||
var v_max = self.get_count()
|
||||
if (v_max == 0)
|
||||
# probably not constructed yet
|
||||
if (!stop)
|
||||
tasmota.set_timer(0, def () self.set_val(v, true #-stop propagation-#) end)
|
||||
end
|
||||
else
|
||||
if (v == nil) v = 0 end
|
||||
if (v < 0) v = 0 end
|
||||
if (v >= v_max) v = v_max - 1 end
|
||||
|
||||
self._lv_obj.set_active(v, lv.ANIM_OFF)
|
||||
end
|
||||
end
|
||||
def get_text()
|
||||
var val = self.get_val()
|
||||
if (val >= 0) && (val < self.get_count())
|
||||
return self._tab_list[val].get_text()
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#====================================================================
|
||||
# tab
|
||||
#====================================================================
|
||||
#@ solidify:lvh_tab.lvh_btn_tab,weak
|
||||
#@ solidify:lvh_tab,weak
|
||||
class lvh_tab : lvh_obj
|
||||
static var _lv_class = nil
|
||||
# label do not need a sub-label
|
||||
var _text # text label of the tab
|
||||
var _btn # btn lvh object
|
||||
|
||||
static class lvh_btn_tab : lvh_obj
|
||||
static var _lv_class = lv.button
|
||||
#====================================================================
|
||||
# specific post-init wihtout events
|
||||
#====================================================================
|
||||
def post_init()
|
||||
self._lv_obj.set_style_radius(0, 0) # set default radius to `0` for rectangle tabs
|
||||
# self.register_event_cb()
|
||||
end
|
||||
end
|
||||
|
||||
#====================================================================
|
||||
# init
|
||||
#
|
||||
# parent: LVGL parent object (used to create a sub-object)
|
||||
# page: HASPmota page object
|
||||
# jline: JSONL definition of the object from HASPmota template (used in sub-classes)
|
||||
# obj: (opt) LVGL object if it already exists and was created prior to init()
|
||||
# parent_lvh: HASPmota parent object defined by `parentid`
|
||||
#====================================================================
|
||||
def init(parent, page, jline, lv_instance, parent_obj)
|
||||
self.set_text(jline.find("text")) # anticipate reading 'text' for creation
|
||||
super(self).init(parent, page, jline, lv_instance, parent_obj)
|
||||
end
|
||||
|
||||
def post_init()
|
||||
self._lv_obj = nil # default to nil object, whatever it was initialized with
|
||||
# check if it is the parent is a spangroup
|
||||
if isinstance(self._parent_lvh, self._page._hm.lvh_tabview)
|
||||
if (self._text != nil)
|
||||
self._lv_obj = self._parent_lvh._lv_obj.add_tab(self._text)
|
||||
|
||||
# get the last button object of the tab bar and create an instance of simplified btn
|
||||
var tab_bar = self._parent_lvh._lv_obj.get_tab_bar()
|
||||
var btn_class = lv.obj_class(lv.button._class)
|
||||
var btn_count = tab_bar.get_child_count_by_type(btn_class)
|
||||
var btn_obj = tab_bar.get_child_by_type(btn_count - 1, btn_class) # get last button
|
||||
self._btn = self.lvh_btn_tab(nil, self._page, {}, btn_obj, self) # instanciate a local lvh object
|
||||
|
||||
# add to parent list
|
||||
self._parent_lvh.push_tab(self)
|
||||
else
|
||||
print("HSP: 'tab' requires 'text' attribute")
|
||||
end
|
||||
else
|
||||
print("HSP: 'tab' should have a parent of type 'tabview'")
|
||||
end
|
||||
# super(self).post_init() # call super - not needed for lvh_root
|
||||
end
|
||||
|
||||
#====================================================================
|
||||
def set_text(t)
|
||||
self._text = str(t)
|
||||
end
|
||||
def get_text()
|
||||
return self._text
|
||||
end
|
||||
|
||||
#- ------------------------------------------------------------#
|
||||
# `setmember` virtual setter
|
||||
#
|
||||
# If the key starts with `bar_`
|
||||
# send to the corresponding object
|
||||
#- ------------------------------------------------------------#
|
||||
def setmember(k, v)
|
||||
import string
|
||||
if string.startswith(k, 'tab_')
|
||||
self._btn.setmember(k[4..], v)
|
||||
else
|
||||
super(self).setmember(k, v)
|
||||
end
|
||||
end
|
||||
def member(k)
|
||||
import string
|
||||
if string.startswith(k, 'tab_')
|
||||
return self._btn.member(k[4..])
|
||||
else
|
||||
return super(self).member(k)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#################################################################################
|
||||
# Special case for lv.chart
|
||||
# Adapted to getting values one after the other
|
||||
|
@ -2621,6 +2799,8 @@ class HASPmota
|
|||
static lvh_scale_line = lvh_scale_line
|
||||
static lvh_spangroup = lvh_spangroup
|
||||
static lvh_span = lvh_span
|
||||
static lvh_tabview = lvh_tabview
|
||||
static lvh_tab = lvh_tab
|
||||
static lvh_qrcode = lvh_qrcode
|
||||
# special cases
|
||||
static lvh_chart = lvh_chart
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1276,7 +1276,7 @@
|
|||
#define BE_LV_WIDGET_SPINNER
|
||||
#define BE_LV_WIDGET_SPANGROUP
|
||||
#define BE_LV_WIDGET_SPAN
|
||||
// #define BE_LV_WIDGET_TABVIEW
|
||||
#define BE_LV_WIDGET_TABVIEW
|
||||
// #define BE_LV_WIDGET_TILEVIEW
|
||||
|
||||
// -- Matter protocol ---------------------------------
|
||||
|
|
Loading…
Reference in New Issue