Skip to content

Commit b821cdb

Browse files
MposKeyboard: scroll into view when opening, restore scroll after closing
1 parent eaab2ce commit b821cdb

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

internal_filesystem/lib/mpos/ui/keyboard.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,18 @@ class MposKeyboard:
101101
}
102102

103103
_current_mode = None
104+
_parent = None
105+
_saved_scroll_y = 0
106+
# Store textarea reference (we DON'T pass it to LVGL to avoid double-typing)
107+
_textarea = None
104108

105109
def __init__(self, parent):
106110
# Create underlying LVGL keyboard widget
107111
self._keyboard = lv.keyboard(parent)
112+
self._parent = parent # store it for later
108113
# self._keyboard.set_popovers(True) # disabled for now because they're quite ugly on LVGL 9.3 - maybe better on 9.4?
109114
self._keyboard.set_style_text_font(lv.font_montserrat_20,0)
110-
111-
# Store textarea reference (we DON'T pass it to LVGL to avoid double-typing)
112-
self._textarea = None
115+
#self._keyboard.add_flag(lv.obj.FLAG.FLOATING) # removed from parent layout, immunte to scrolling
113116

114117
self.set_mode(self.MODE_LOWERCASE)
115118

@@ -250,8 +253,26 @@ def __getattr__(self, name):
250253
# Forward to the underlying keyboard object
251254
return getattr(self._keyboard, name)
252255

256+
def scroll_after_show(self, timer):
257+
self._keyboard.scroll_to_view_recursive(True)
258+
# in a flex container, this is not needed, but without it, it might be needed:
259+
#self._keyboard.move_to_index(10)
260+
#self._textarea.scroll_to_view_recursive(True)
261+
#self._keyboard.add_flag(lv.obj.FLAG.FLOATING) # removed from parent layout, immune to scrolling
262+
#self._keyboard.move_foreground() # this causes it to be moved to the bottom of the screen in a flex container
263+
264+
def scroll_back_after_hide(self, timer):
265+
self._parent.scroll_to_y(self._saved_scroll_y, True)
266+
#self._keyboard.remove_flag(lv.obj.FLAG.FLOATING) # removed from parent layout, immune to scrolling
267+
253268
def show_keyboard(self):
254-
mpos.ui.anim.smooth_show(self._keyboard)
269+
self._saved_scroll_y = self._parent.get_scroll_y()
270+
mpos.ui.anim.smooth_show(self._keyboard, duration=500)
271+
# Scroll to view on a timer because it will be hidden initially
272+
scroll_timer = lv.timer_create(self.scroll_after_show,250,None)
273+
scroll_timer.set_repeat_count(1)
255274

256275
def hide_keyboard(self):
257-
mpos.ui.anim.smooth_hide(self._keyboard)
276+
mpos.ui.anim.smooth_hide(self._keyboard, duration=500)
277+
scroll_timer = lv.timer_create(self.scroll_back_after_hide,550,None) # do it after the hide so the scrollbars disappear automatically if not needed
278+
scroll_timer.set_repeat_count(1)

0 commit comments

Comments
 (0)