1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-12 15:24:14 +03:00

lvgui: Add events to text area

This commit is contained in:
Samuel Dionne-Riel 2022-09-15 18:52:16 -04:00
parent a01a9ac0f7
commit 3816ff7e31

View File

@ -36,6 +36,7 @@ class LVGUI::TextArea < LVGUI::Widget
when LVGL::EVENT::CLICKED
LVGUI::Keyboard.instance.set_ta(self)
LVGUI::Keyboard.instance.show()
@on_click.call() if @on_click
when LVGL::EVENT::INSERT
# Not exactly right, but right enough.
char = LVGUI::Native.lv_event_get_data().ref_to_char()
@ -45,9 +46,11 @@ class LVGUI::TextArea < LVGUI::Widget
LVGUI::Keyboard.instance.set_ta(nil)
LVGUI::Keyboard.instance.hide()
# Create a new string
# get_text() gives us a Fiddle::Pointer (leaky abstraction!!!)
value = "#{get_text()}"
value = get_text()
@on_submit.call(value) if @on_submit
else
value = [get_text(), char].join("")
@on_modified.call(value) if @on_modified
end
#else
# puts "Unhandled event for #{self}: #{LVGL::EVENT.from_value(event)}"
@ -86,6 +89,12 @@ class LVGUI::TextArea < LVGUI::Widget
end
end
def on_click=(cb)
@on_click = cb
end
def on_modified=(cb)
@on_modified = cb
end
def on_submit=(cb)
@on_submit = cb
end