Skip to content

Commit

Permalink
HASPmota support for
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger committed Dec 23, 2024
1 parent 3412761 commit 2a2a310
Show file tree
Hide file tree
Showing 6 changed files with 3,137 additions and 2,210 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/libesp32_lvgl/lv_haspmota/src/be_lv_haspmota.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/libesp32_lvgl/lv_haspmota/src/embedded/lv_0_module.be
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
186 changes: 183 additions & 3 deletions lib/libesp32_lvgl/lv_haspmota/src/embedded/lv_haspmota.be
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2a2a310

Please sign in to comment.