From af5bfc8c50c833c1ef653e36ae0930add0c2338d Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 5 May 2020 00:41:09 +0800 Subject: [PATCH] rename on_xxx --- src/ltui/application.lua | 4 ++-- src/ltui/button.lua | 2 +- src/ltui/choicebox.lua | 2 +- src/ltui/choicedialog.lua | 8 ++++---- src/ltui/dialog.lua | 4 ++-- src/ltui/mconfdialog.lua | 10 +++++----- src/ltui/menuconf.lua | 2 +- src/ltui/panel.lua | 14 +++++++------- src/ltui/program.lua | 27 ++++++++++++--------------- src/ltui/rect.lua | 2 +- src/ltui/textarea.lua | 2 +- src/ltui/textdialog.lua | 6 +++--- src/ltui/textedit.lua | 4 ++-- src/ltui/view.lua | 14 +++++++------- src/ltui/window.lua | 4 ++-- tests/desktop.lua | 4 ++-- tests/dialog.lua | 6 +++--- 17 files changed, 56 insertions(+), 59 deletions(-) diff --git a/src/ltui/application.lua b/src/ltui/application.lua index 577f05f..e4869e7 100644 --- a/src/ltui/application.lua +++ b/src/ltui/application.lua @@ -84,8 +84,8 @@ function application:statusbar() end -- on event -function application:event_on(e) - program.event_on(self, e) +function application:on_event(e) + program.on_event(self, e) end -- run application diff --git a/src/ltui/button.lua b/src/ltui/button.lua index 26e0a4e..523dae6 100644 --- a/src/ltui/button.lua +++ b/src/ltui/button.lua @@ -73,7 +73,7 @@ function button:draw(transparent) end -- on event -function button:event_on(e) +function button:on_event(e) -- selected? if not self:state("selected") then diff --git a/src/ltui/choicebox.lua b/src/ltui/choicebox.lua index 2213e6d..8530a22 100644 --- a/src/ltui/choicebox.lua +++ b/src/ltui/choicebox.lua @@ -43,7 +43,7 @@ function choicebox:init(name, bounds) end -- on event -function choicebox:event_on(e) +function choicebox:on_event(e) -- select config if e.type == event.ev_keyboard then diff --git a/src/ltui/choicedialog.lua b/src/ltui/choicedialog.lua index 1628852..94b39a4 100644 --- a/src/ltui/choicedialog.lua +++ b/src/ltui/choicedialog.lua @@ -42,7 +42,7 @@ function choicedialog:init(name, bounds, title) -- init buttons self:button_add("select", "< Select >", function (v, e) - self:choicebox():event_on(event.command {"cm_enter"}) + self:choicebox():on_event(event.command {"cm_enter"}) self:quit() end) self:button_add("cancel", "< Cancel >", function (v, e) @@ -68,7 +68,7 @@ function choicedialog:choicebox() end -- on event -function choicedialog:event_on(e) +function choicedialog:on_event(e) -- load values first if e.type == event.ev_idle then @@ -79,10 +79,10 @@ function choicedialog:event_on(e) -- select value elseif e.type == event.ev_keyboard then if e.key_name == "Down" or e.key_name == "Up" or e.key_name == " " then - return self:choicebox():event_on(e) + return self:choicebox():on_event(e) end end - return boxdialog.event_on(self, e) + return boxdialog.on_event(self, e) end -- return module diff --git a/src/ltui/dialog.lua b/src/ltui/dialog.lua index 17652ef..0e772f2 100644 --- a/src/ltui/dialog.lua +++ b/src/ltui/dialog.lua @@ -102,12 +102,12 @@ function dialog:quit() end -- on event -function dialog:event_on(e) +function dialog:on_event(e) if e.type == event.ev_keyboard and e.key_name == "Esc" then self:quit() return true end - return window.event_on(self, e) + return window.on_event(self, e) end -- return module diff --git a/src/ltui/mconfdialog.lua b/src/ltui/mconfdialog.lua index c1e1ecc..cb69df5 100644 --- a/src/ltui/mconfdialog.lua +++ b/src/ltui/mconfdialog.lua @@ -46,8 +46,8 @@ Pressing includes, excludes. Enter or to go back, for H ]]) -- init buttons - self:button_add("select", "< Select >", function (v, e) self:menuconf():event_on(event.command {"cm_enter"}) end) - self:button_add("back", "< Back >", function (v, e) self:menuconf():event_on(event.command {"cm_back"}) end) + self:button_add("select", "< Select >", function (v, e) self:menuconf():on_event(event.command {"cm_enter"}) end) + self:button_add("back", "< Back >", function (v, e) self:menuconf():on_event(event.command {"cm_back"}) end) self:button_add("exit", "< Exit >", function (v, e) self:quit() end) self:button_add("help", "< Help >", function (v, e) self:show_help() end) self:button_add("save", "< Save >", function (v, e) self:action_on(action.ac_on_save) end) @@ -288,12 +288,12 @@ function mconfdialog:show_result(text) end -- on event -function mconfdialog:event_on(e) +function mconfdialog:on_event(e) -- select config if e.type == event.ev_keyboard then if e.key_name == "Down" or e.key_name == "Up" or e.key_name == " " or e.key_name == "Esc" or e.key_name:lower() == "y" or e.key_name:lower() == "n" then - return self:menuconf():event_on(e) + return self:menuconf():on_event(e) elseif e.key_name == "?" then self:show_help() return true @@ -302,7 +302,7 @@ function mconfdialog:event_on(e) return true end end - return boxdialog.event_on(self, e) + return boxdialog.on_event(self, e) end -- return module diff --git a/src/ltui/menuconf.lua b/src/ltui/menuconf.lua index 2e05caa..7b5caca 100644 --- a/src/ltui/menuconf.lua +++ b/src/ltui/menuconf.lua @@ -43,7 +43,7 @@ function menuconf:init(name, bounds) end -- on event -function menuconf:event_on(e) +function menuconf:on_event(e) -- select config local back = false diff --git a/src/ltui/panel.lua b/src/ltui/panel.lua index 04aa422..bd2487b 100644 --- a/src/ltui/panel.lua +++ b/src/ltui/panel.lua @@ -276,7 +276,7 @@ function panel:select_prev(start) end -- on event -function panel:event_on(e) +function panel:on_event(e) -- select view? if e.type == event.ev_keyboard then @@ -320,22 +320,22 @@ function panel:draw(transparent) end -- resize panel -function panel:resize() +function panel:on_resize() -- resize panel - view.resize(self) + view.on_resize(self) -- resize all child views for v in self:views() do v:state_set("resize", true) if v:state("visible") then - v:resize() + v:on_resize() end end end -- refresh panel -function panel:refresh() +function panel:on_refresh() -- need not refresh? do not refresh it if not self:state("refresh") or not self:state("visible") then @@ -345,13 +345,13 @@ function panel:refresh() -- refresh all child views for v in self:views() do if v:state("refresh") then - v:refresh() + v:on_refresh() v:state_set("refresh", false) end end -- refresh it - view.refresh(self) + view.on_refresh(self) -- clear mark self:state_set("refresh", false) diff --git a/src/ltui/program.lua b/src/ltui/program.lua index e8f3bf1..3d830c3 100644 --- a/src/ltui/program.lua +++ b/src/ltui/program.lua @@ -140,7 +140,7 @@ function program:event() end -- on event -function program:event_on(e) +function program:on_event(e) -- get the top focused view local focused_view = self @@ -151,7 +151,7 @@ function program:event_on(e) -- do event for focused views while focused_view and focused_view ~= self do local parent = focused_view:parent() - if focused_view:event_on(e) then + if focused_view:on_event(e) then return true end focused_view = parent @@ -180,7 +180,7 @@ function program:event_on(e) end -- put an event to view -function program:event_put(e) +function program:put_event(e) -- init event queue self._EVENT_QUEUE = self._EVENT_QUEUE or {} @@ -191,7 +191,7 @@ end -- send command function program:send(command, extra) - self:event_put(event.command {command, extra}) + self:put_event(event.command {command, extra}) end -- quit program @@ -213,11 +213,11 @@ function program:loop(argv) -- do event if e then event.dump(e) - self:event_on(e) + self:on_event(e) sleep = false else -- do idle event - self:event_on(event.idle()) + self:on_event(event.idle()) sleep = true end @@ -228,14 +228,16 @@ function program:loop(argv) -- resize views if self:state("resize") then - self:resize() + self:on_resize() end -- draw views self:draw() -- refresh views - self:refresh() + if self:state("refresh") then + self:on_refresh() + end -- wait some time, 50ms if sleep then @@ -245,15 +247,10 @@ function program:loop(argv) end -- refresh program -function program:refresh() - - -- need not refresh? do not refresh it - if not self:state("refresh") then - return - end +function program:on_refresh() -- refresh views - panel.refresh(self) + panel.on_refresh(self) -- trace log:print("%s: refresh ..", self) diff --git a/src/ltui/rect.lua b/src/ltui/rect.lua index 47a02a8..34869ea 100644 --- a/src/ltui/rect.lua +++ b/src/ltui/rect.lua @@ -52,7 +52,7 @@ function rect:height() end -- resize rect -function rect:resize(w, h) +function rect:on_resize(w, h) self.ex = self.sx + w self.ey = self.sy + h end diff --git a/src/ltui/textarea.lua b/src/ltui/textarea.lua index e860688..c2a09f4 100644 --- a/src/ltui/textarea.lua +++ b/src/ltui/textarea.lua @@ -100,7 +100,7 @@ function textarea:scroll_to_end() end -- on event -function textarea:event_on(e) +function textarea:on_event(e) if e.type == event.ev_keyboard then if e.key_name == "Up" then self:scroll(-5) diff --git a/src/ltui/textdialog.lua b/src/ltui/textdialog.lua index 7a78092..9c1f88c 100644 --- a/src/ltui/textdialog.lua +++ b/src/ltui/textdialog.lua @@ -51,16 +51,16 @@ function textdialog:text() end -- on event -function textdialog:event_on(e) +function textdialog:on_event(e) -- pass event to dialog - if dialog.event_on(self, e) then + if dialog.on_event(self, e) then return true end -- pass keyboard event to text area to scroll if e.type == event.ev_keyboard then - return self:text():event_on(e) + return self:text():on_event(e) end end diff --git a/src/ltui/textedit.lua b/src/ltui/textedit.lua index 1a682ea..ec522ff 100644 --- a/src/ltui/textedit.lua +++ b/src/ltui/textedit.lua @@ -71,7 +71,7 @@ function textedit:text_set(text) end -- on event -function textedit:event_on(e) +function textedit:on_event(e) -- update text if e.type == event.ev_keyboard then @@ -97,7 +97,7 @@ function textedit:event_on(e) end -- do textarea event - return textarea.event_on(self, e) + return textarea.on_event(self, e) end -- return module diff --git a/src/ltui/view.lua b/src/ltui/view.lua index ffd75e5..eac4a41 100644 --- a/src/ltui/view.lua +++ b/src/ltui/view.lua @@ -59,8 +59,8 @@ function view:init(name, bounds) state.selected = false -- is selected? state.focused = false -- is focused? state.redraw = true -- need redraw - state.refresh = true -- need refresh - state.resize = true -- need resize + state.on_refresh = true -- need refresh + state.on_resize = true -- need resize self._STATE = state -- init options @@ -188,7 +188,7 @@ function view:draw(transparent) end -- refresh view -function view:refresh() +function view:on_refresh() -- refresh to the parent view local parent = self:parent() @@ -209,7 +209,7 @@ function view:refresh() end -- resize bounds of inner child views (abstract) -function view:resize() +function view:on_resize() -- trace log:print("%s: resize ..", self) @@ -265,7 +265,7 @@ end -- -- @return true: done and break dispatching, false/nil: continous to dispatch to other views -- -function view:event_on(e) +function view:on_event(e) end -- get the current event @@ -274,8 +274,8 @@ function view:event() end -- put an event to view -function view:event_put(e) - return self:parent() and self:parent():event_put(e) +function view:put_event(e) + return self:parent() and self:parent():put_event(e) end -- get type diff --git a/src/ltui/window.lua b/src/ltui/window.lua index cab72f6..8e953bb 100644 --- a/src/ltui/window.lua +++ b/src/ltui/window.lua @@ -58,7 +58,7 @@ function window:init(name, bounds, title, shadow) self:title():action_set(action.ac_on_text_changed, function (v) if v:text() then local bounds = v:bounds() - v:bounds():resize(#v:text(), v:height()) + v:bounds():on_resize(#v:text(), v:height()) bounds:move2(math.max(0, math.floor((self:frame():width() - v:width()) / 2)), bounds.sy) v:invalidate(true) end @@ -113,7 +113,7 @@ function window:border() end -- on event -function window:event_on(e) +function window:on_event(e) -- select panel? if e.type == event.ev_keyboard then diff --git a/tests/desktop.lua b/tests/desktop.lua index f0a360c..dea4336 100755 --- a/tests/desktop.lua +++ b/tests/desktop.lua @@ -59,8 +59,8 @@ function demo:init() end -- on event -function demo:event_on(e) - if application.event_on(self, e) then +function demo:on_event(e) + if application.on_event(self, e) then return true end if e.type == event.ev_keyboard then diff --git a/tests/dialog.lua b/tests/dialog.lua index 7bf149b..2fba14a 100644 --- a/tests/dialog.lua +++ b/tests/dialog.lua @@ -123,12 +123,12 @@ function demo:dialog_tips() return dialog_tips end --- resize dialog -function demo:resize() +-- on resize +function demo:on_resize() self:dialog_main():bounds_set(rect {1, 1, self:width() - 1, self:height() - 1}) self:center(self:dialog_input(), {centerx = true, centery = true}) self:center(self:dialog_tips(), {centerx = true, centery = true}) - application.resize(self) + application.on_resize(self) end -- run demo