rename on_xxx

This commit is contained in:
ruki
2020-05-05 00:41:09 +08:00
parent db81539967
commit af5bfc8c50
17 changed files with 56 additions and 59 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -46,8 +46,8 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> or <Back> 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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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