Skip to content

Commit 4fd3d94

Browse files
authored
HASPmota support for (#22707)
1 parent 3412761 commit 4fd3d94

File tree

6 files changed

+3137
-2210
lines changed

6 files changed

+3137
-2210
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- Command ``SetOption163 1`` to disable display of Device name in GUI header
99
- Berry `animate.crenel` primitive (#22673)
1010
- Berry scroll to Leds_matrix (#22693)
11+
- HASPmota support for `tabview`
1112

1213
### Breaking Changed
1314

lib/libesp32_lvgl/lv_haspmota/src/be_lv_haspmota.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern const bclass be_class_lv_qrcode;
2828
extern const bclass be_class_lv_chart;
2929
extern const bclass be_class_lv_spangroup;
3030
extern const bclass be_class_lv_span;
31+
extern const bclass be_class_lv_tabview;
3132
extern const bclass be_class_lv_button;
3233
extern const bclass be_class_lv_image;
3334
extern const bclass be_class_lv_buttonmatrix;

lib/libesp32_lvgl/lv_haspmota/src/embedded/lv_0_module.be

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var classes = [
1616
# ported from LVGL 8
1717
"colorwheel",
1818
# new internal names
19-
"button", "image", "buttonmatrix", "msgbox"
19+
"button", "image", "buttonmatrix", "msgbox", "tabview"
2020
]
2121

2222
for cl: classes

lib/libesp32_lvgl/lv_haspmota/src/embedded/lv_haspmota.be

Lines changed: 183 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,12 +1462,12 @@ class lvh_spinner : lvh_arc
14621462
# obj: (opt) LVGL object if it already exists and was created prior to init()
14631463
# parent_lvh: HASPmota parent object defined by `parentid`
14641464
#====================================================================
1465-
def init(parent, page, jline)
1465+
def init(parent, page, jline, lv_instance, parent_obj)
14661466
var angle = jline.find("angle", 60)
14671467
var speed = jline.find("speed", 1000)
14681468
self._lv_obj = lv.spinner(parent)
14691469
self._lv_obj.set_anim_params(speed, angle)
1470-
super(self).init(parent, page, jline, self._lv_obj)
1470+
super(self).init(parent, page, jline, self._lv_obj, parent_obj)
14711471
end
14721472

14731473
def set_angle(t) end
@@ -1735,7 +1735,7 @@ class lvh_dropdown_list : lvh_obj
17351735
if isinstance(self._parent_lvh, self._page._hm.lvh_dropdown)
17361736
self._lv_obj = lv.list(self._parent_lvh._lv_obj.get_list()._p)
17371737
else
1738-
print("HSP: '_dropdown_list' should have a parent of type 'dropdown'")
1738+
print("HSP: 'dropdown_list' should have a parent of type 'dropdown'")
17391739
end
17401740
super(self).post_init()
17411741
end
@@ -2056,6 +2056,8 @@ class lvh_span : lvh_root
20562056
# print(">>> GOOD")
20572057
self._lv_obj = self._parent_lvh._lv_obj.new_span()
20582058
self._style = self._lv_obj.get_style()
2059+
else
2060+
print("HSP: 'span' should have a parent of type 'spangroup'")
20592061
end
20602062
# super(self).post_init() # call super - not needed for lvh_root
20612063
end
@@ -2160,6 +2162,182 @@ class lvh_span : lvh_root
21602162

21612163
end
21622164

2165+
#====================================================================
2166+
# tabview
2167+
#====================================================================
2168+
#@ solidify:lvh_tabview,weak
2169+
class lvh_tabview : lvh_obj
2170+
static var _lv_class = lv.tabview
2171+
var _tab_list # list of tabs
2172+
2173+
# label do not need a sub-label
2174+
def post_init()
2175+
self._tab_list = []
2176+
super(self).post_init() # call super -- not needed
2177+
end
2178+
2179+
#====================================================================
2180+
# direction for buttons
2181+
#====================================================================
2182+
static var _direction = [
2183+
lv.DIR_NONE, # 0 = none
2184+
lv.DIR_TOP, # 1 = top
2185+
lv.DIR_BOTTOM, # 2 = bottom
2186+
lv.DIR_LEFT, # 3 = left
2187+
lv.DIR_RIGHT, # 4 = right
2188+
]
2189+
def set_btn_pos(v)
2190+
v = int(v)
2191+
if (v == nil) || (v < 0) || (v >= size(self._direction))
2192+
v = 0
2193+
end
2194+
var direction = self._direction[v]
2195+
self._lv_obj.set_tab_bar_position(direction)
2196+
end
2197+
2198+
#====================================================================
2199+
# management of `_tab_list` list
2200+
#====================================================================
2201+
# add lvh_tab instance as they are created
2202+
def push_tab(t)
2203+
self._tab_list.push(t)
2204+
end
2205+
# returns the index of the tab instance, or `nil` if not found
2206+
def find_tab(t)
2207+
return self._tab_list.find(t)
2208+
end
2209+
2210+
#====================================================================
2211+
# count read-only attribute, returns number of tabs
2212+
#====================================================================
2213+
def get_count()
2214+
return self._lv_obj.get_tab_count()
2215+
end
2216+
def get_val()
2217+
return self._lv_obj.get_tab_active()
2218+
end
2219+
# change current tab
2220+
# v: value of new tab
2221+
# stop: (opt) if true, don't defer again to avoid infinite loop
2222+
def set_val(v, stop)
2223+
var v_max = self.get_count()
2224+
if (v_max == 0)
2225+
# probably not constructed yet
2226+
if (!stop)
2227+
tasmota.set_timer(0, def () self.set_val(v, true #-stop propagation-#) end)
2228+
end
2229+
else
2230+
if (v == nil) v = 0 end
2231+
if (v < 0) v = 0 end
2232+
if (v >= v_max) v = v_max - 1 end
2233+
2234+
self._lv_obj.set_active(v, lv.ANIM_OFF)
2235+
end
2236+
end
2237+
def get_text()
2238+
var val = self.get_val()
2239+
if (val >= 0) && (val < self.get_count())
2240+
return self._tab_list[val].get_text()
2241+
else
2242+
return nil
2243+
end
2244+
end
2245+
end
2246+
2247+
#====================================================================
2248+
# tab
2249+
#====================================================================
2250+
#@ solidify:lvh_tab.lvh_btn_tab,weak
2251+
#@ solidify:lvh_tab,weak
2252+
class lvh_tab : lvh_obj
2253+
static var _lv_class = nil
2254+
# label do not need a sub-label
2255+
var _text # text label of the tab
2256+
var _btn # btn lvh object
2257+
2258+
static class lvh_btn_tab : lvh_obj
2259+
static var _lv_class = lv.button
2260+
#====================================================================
2261+
# specific post-init wihtout events
2262+
#====================================================================
2263+
def post_init()
2264+
self._lv_obj.set_style_radius(0, 0) # set default radius to `0` for rectangle tabs
2265+
# self.register_event_cb()
2266+
end
2267+
end
2268+
2269+
#====================================================================
2270+
# init
2271+
#
2272+
# parent: LVGL parent object (used to create a sub-object)
2273+
# page: HASPmota page object
2274+
# jline: JSONL definition of the object from HASPmota template (used in sub-classes)
2275+
# obj: (opt) LVGL object if it already exists and was created prior to init()
2276+
# parent_lvh: HASPmota parent object defined by `parentid`
2277+
#====================================================================
2278+
def init(parent, page, jline, lv_instance, parent_obj)
2279+
self.set_text(jline.find("text")) # anticipate reading 'text' for creation
2280+
super(self).init(parent, page, jline, lv_instance, parent_obj)
2281+
end
2282+
2283+
def post_init()
2284+
self._lv_obj = nil # default to nil object, whatever it was initialized with
2285+
# check if it is the parent is a spangroup
2286+
if isinstance(self._parent_lvh, self._page._hm.lvh_tabview)
2287+
if (self._text != nil)
2288+
self._lv_obj = self._parent_lvh._lv_obj.add_tab(self._text)
2289+
2290+
# get the last button object of the tab bar and create an instance of simplified btn
2291+
var tab_bar = self._parent_lvh._lv_obj.get_tab_bar()
2292+
var btn_class = lv.obj_class(lv.button._class)
2293+
var btn_count = tab_bar.get_child_count_by_type(btn_class)
2294+
var btn_obj = tab_bar.get_child_by_type(btn_count - 1, btn_class) # get last button
2295+
self._btn = self.lvh_btn_tab(nil, self._page, {}, btn_obj, self) # instanciate a local lvh object
2296+
2297+
# add to parent list
2298+
self._parent_lvh.push_tab(self)
2299+
else
2300+
print("HSP: 'tab' requires 'text' attribute")
2301+
end
2302+
else
2303+
print("HSP: 'tab' should have a parent of type 'tabview'")
2304+
end
2305+
# super(self).post_init() # call super - not needed for lvh_root
2306+
end
2307+
2308+
#====================================================================
2309+
def set_text(t)
2310+
self._text = str(t)
2311+
end
2312+
def get_text()
2313+
return self._text
2314+
end
2315+
2316+
#- ------------------------------------------------------------#
2317+
# `setmember` virtual setter
2318+
#
2319+
# If the key starts with `bar_`
2320+
# send to the corresponding object
2321+
#- ------------------------------------------------------------#
2322+
def setmember(k, v)
2323+
import string
2324+
if string.startswith(k, 'tab_')
2325+
self._btn.setmember(k[4..], v)
2326+
else
2327+
super(self).setmember(k, v)
2328+
end
2329+
end
2330+
def member(k)
2331+
import string
2332+
if string.startswith(k, 'tab_')
2333+
return self._btn.member(k[4..])
2334+
else
2335+
return super(self).member(k)
2336+
end
2337+
end
2338+
2339+
end
2340+
21632341
#################################################################################
21642342
# Special case for lv.chart
21652343
# Adapted to getting values one after the other
@@ -2621,6 +2799,8 @@ class HASPmota
26212799
static lvh_scale_line = lvh_scale_line
26222800
static lvh_spangroup = lvh_spangroup
26232801
static lvh_span = lvh_span
2802+
static lvh_tabview = lvh_tabview
2803+
static lvh_tab = lvh_tab
26242804
static lvh_qrcode = lvh_qrcode
26252805
# special cases
26262806
static lvh_chart = lvh_chart

0 commit comments

Comments
 (0)