fix(msgbox): fix micropython example
This commit is contained in:
@@ -1,155 +0,0 @@
|
||||
class KeyboardEncoder:
|
||||
def __init__(self):
|
||||
self.g = lv.group_create()
|
||||
self.g.set_default()
|
||||
|
||||
cur_drv = lv.indev_t()
|
||||
cur_drv = cur_drv.get_next()
|
||||
|
||||
while cur_drv != None:
|
||||
|
||||
if cur_drv.get_type() == lv.INDEV_TYPE.KEYPAD:
|
||||
print("Found keypad")
|
||||
cur_drv.set_group(self.g)
|
||||
if cur_drv.get_type() == lv.INDEV_TYPE.ENCODER:
|
||||
print("Found encoder")
|
||||
cur_drv.set_group(self.g)
|
||||
|
||||
cur_drv = cur_drv.get_next()
|
||||
|
||||
self.tv = lv.tabview(lv.screen_active())
|
||||
|
||||
self.t1 = self.tv.add_tab("Selectors")
|
||||
self.t2 = self.tv.add_tab("Text input")
|
||||
|
||||
self.selectors_create(self.t1)
|
||||
self.text_input_create(self.t2)
|
||||
|
||||
self.msgbox_create()
|
||||
|
||||
def selectors_create(self,parent):
|
||||
parent.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
parent.set_flex_align(lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
||||
|
||||
obj = lv.table(parent)
|
||||
obj.set_cell_value(0, 0, "00")
|
||||
obj.set_cell_value(0, 1, "01")
|
||||
obj.set_cell_value(1, 0, "10")
|
||||
obj.set_cell_value(1, 1, "11")
|
||||
obj.set_cell_value(2, 0, "20")
|
||||
obj.set_cell_value(2, 1, "21")
|
||||
obj.set_cell_value(3, 0, "30")
|
||||
obj.set_cell_value(3, 1, "31")
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
|
||||
obj = lv.calendar(parent)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
|
||||
obj = lv.buttonmatrix(parent)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
obj = lv.checkbox(parent)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS);
|
||||
|
||||
obj = lv.slider(parent)
|
||||
obj.set_range(0, 10)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
|
||||
obj = lv.switch(parent)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
|
||||
obj = lv.spinbox(parent)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
|
||||
obj = lv.dropdown(parent)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
|
||||
obj = lv.roller(parent)
|
||||
obj.add_flag(lv.obj.FLAG.SCROLL_ON_FOCUS)
|
||||
|
||||
list = lv.list(parent)
|
||||
list.update_layout()
|
||||
if list.get_height() > parent.get_content_height() :
|
||||
list.set_height(parent.get_content_height())
|
||||
|
||||
list.add_button(lv.SYMBOL.OK, "Apply")
|
||||
list.add_button(lv.SYMBOL.CLOSE, "Close")
|
||||
list.add_button(lv.SYMBOL.EYE_OPEN, "Show")
|
||||
list.add_button(lv.SYMBOL.EYE_CLOSE, "Hide")
|
||||
list.add_button(lv.SYMBOL.TRASH, "Delete")
|
||||
list.add_button(lv.SYMBOL.COPY, "Copy")
|
||||
list.add_button(lv.SYMBOL.PASTE, "Paste")
|
||||
|
||||
def text_input_create(self,parent) :
|
||||
|
||||
parent.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
|
||||
ta1 = lv.textarea(parent)
|
||||
ta1.set_width(lv.pct(100))
|
||||
ta1.set_one_line(True)
|
||||
ta1.set_placeholder_text("Click with an encoder to show a keyboard")
|
||||
|
||||
ta2 = lv.textarea(parent)
|
||||
ta2.set_width(lv.pct(100))
|
||||
ta2.set_one_line(True)
|
||||
ta2.set_placeholder_text("Type something")
|
||||
|
||||
self.kb = lv.keyboard(lv.screen_active())
|
||||
self.kb.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
|
||||
ta1.add_event_cb(self.ta_event_cb, lv.EVENT.ALL, None)
|
||||
ta2.add_event_cb(self.ta_event_cb, lv.EVENT.ALL, None)
|
||||
|
||||
|
||||
def msgbox_create(self):
|
||||
|
||||
buttons = ["Ok", "Cancel", ""]
|
||||
mbox = lv.msgbox(None, "Hi", "Welcome to the keyboard and encoder demo", buttons, False)
|
||||
mbox.add_event_cb(self.msgbox_event_cb, lv.EVENT.ALL, None)
|
||||
lv.group_focus_obj(mbox.get_buttons())
|
||||
mbox.get_buttons().add_state(lv.STATE.FOCUS_KEY)
|
||||
self.g.focus_freeze(True)
|
||||
|
||||
mbox.align(lv.ALIGN.CENTER, 0, 0)
|
||||
|
||||
bg = mbox.get_parent()
|
||||
bg.set_style_bg_opa(lv.OPA._70, 0)
|
||||
bg.set_style_bg_color(lv.palette_main(lv.PALETTE.GREY), 0)
|
||||
|
||||
|
||||
def msgbox_event_cb(self,e):
|
||||
|
||||
code = e.get_code();
|
||||
msgbox = e.get_target()
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
txt = msgbox.get_active_button_text()
|
||||
if txt:
|
||||
msgbox.close()
|
||||
self.g.focus_freeze(False)
|
||||
lv.group_focus_obj(self.t1.get_child(0))
|
||||
self.t1.scroll_to(0, 0, lv.ANIM.OFF)
|
||||
|
||||
def ta_event_cb(self,e) :
|
||||
|
||||
indev = lv.indev_active()
|
||||
if indev == None :
|
||||
return
|
||||
indev_type = indev.get_type()
|
||||
|
||||
code = e.get_code()
|
||||
ta = e.get_target_obj()
|
||||
|
||||
if code == lv.EVENT.CLICKED and indev_type == lv.INDEV_TYPE.ENCODER:
|
||||
self.kb.set_textarea(ta)
|
||||
self.kb.remove_flag(lv.obj.FLAG.HIDDEN)
|
||||
self.kb.group_focus_obj()
|
||||
self.kb.get_group().set_editing()
|
||||
self.tv.set_height(lv.pct(50))
|
||||
lv_obj_align(kb, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
|
||||
if code == lv.EVENT.READY or code == lv.EVENT.CANCEL:
|
||||
self.kb.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
self.tv.set_height(lv.pct(100))
|
||||
|
||||
|
||||
keyboard_encoder = KeyboardEncoder()
|
||||
@@ -1,8 +1,10 @@
|
||||
def back_event_handler(e):
|
||||
obj = e.get_target_obj()
|
||||
if menu.back_button_is_root(obj):
|
||||
mbox1 = lv.msgbox(lv.screen_active(), "Hello", "Root back button click.", None, True)
|
||||
mbox1.center()
|
||||
mbox1 = lv.msgbox(lv.screen_active())
|
||||
mbox1.add_title("Hello")
|
||||
mbox1.add_text("Root back button click.")
|
||||
mbox1.add_close_button()
|
||||
|
||||
# Create a menu object
|
||||
menu = lv.menu(lv.screen_active())
|
||||
|
||||
@@ -57,7 +57,10 @@ def back_event_handler(e,menu):
|
||||
# menu = lv_event_get_user_data(e);
|
||||
|
||||
if menu.back_button_is_root(obj) :
|
||||
mbox1 = lv.msgbox(None, "Hello", "Root back button click.", None, True)
|
||||
mbox1 = lv.msgbox(None)
|
||||
mbox1.add_title("Hello")
|
||||
mbox1.add_text("Root back button click.")
|
||||
mbox1.add_close_button()
|
||||
mbox1.center()
|
||||
|
||||
def switch_handler(e,menu):
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
def event_cb(e):
|
||||
mbox = e.get_target_obj()
|
||||
print("Button %s clicked" % mbox.get_active_button_text())
|
||||
btn = e.get_target_obj()
|
||||
label = btn.get_child(btn)
|
||||
print("Button %s clicked" % label.get_text())
|
||||
|
||||
buttons = ["Apply", "Close", ""]
|
||||
|
||||
mbox1 = lv.msgbox(lv.screen_active(), "Hello", "This is a message box with two buttons.", buttons, True)
|
||||
mbox1.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
mbox1.center()
|
||||
mbox1 = lv.msgbox(lv.screen_active())
|
||||
mbox1.add_title("Hello")
|
||||
mbox1.add_text("This is a message box with two buttons")
|
||||
mbox1.add_close_button()
|
||||
|
||||
btn = mbox1.add_footer_button("Apply")
|
||||
btn.add_event_cb(event_cb, lv.EVENT.CLICKED, None)
|
||||
btn = mbox1.add_footer_button("Cancel")
|
||||
btn.add_event_cb(event_cb, lv.EVENT.CLICKED, None)
|
||||
|
||||
@@ -273,9 +273,9 @@ static int32_t _dave2d_evaluate(lv_draw_unit_t * u, lv_draw_task_t * t)
|
||||
|
||||
case LV_DRAW_TASK_TYPE_IMAGE: {
|
||||
#if USE_D2
|
||||
//TODO
|
||||
// t->preferred_draw_unit_id = DRAW_UNIT_ID_DAVE2D;
|
||||
// t->preference_score = 0;
|
||||
//TODO
|
||||
// t->preferred_draw_unit_id = DRAW_UNIT_ID_DAVE2D;
|
||||
// t->preference_score = 0;
|
||||
#endif
|
||||
ret = 0;
|
||||
break;
|
||||
@@ -362,7 +362,7 @@ static int32_t _dave2d_evaluate(lv_draw_unit_t * u, lv_draw_task_t * t)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define DAVE2D_REFFERING_WATERMARK 10
|
||||
#define DAVE2D_REFERRING_WATERMARK 10
|
||||
|
||||
static int32_t lv_draw_dave2d_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer)
|
||||
{
|
||||
@@ -395,7 +395,7 @@ static int32_t lv_draw_dave2d_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t *
|
||||
#if (0 == D2_RENDER_EACH_OPERATION)
|
||||
ref_count += lv_draw_get_dependent_count(t);
|
||||
|
||||
if(DAVE2D_REFFERING_WATERMARK < ref_count) {
|
||||
if(DAVE2D_REFERRING_WATERMARK < ref_count) {
|
||||
ref_count = 0;
|
||||
dave2d_execute_dlist_and_flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user