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 end
-- on event -- on event
function application:event_on(e) function application:on_event(e)
program.event_on(self, e) program.on_event(self, e)
end end
-- run application -- run application

View File

@@ -73,7 +73,7 @@ function button:draw(transparent)
end end
-- on event -- on event
function button:event_on(e) function button:on_event(e)
-- selected? -- selected?
if not self:state("selected") then if not self:state("selected") then

View File

@@ -43,7 +43,7 @@ function choicebox:init(name, bounds)
end end
-- on event -- on event
function choicebox:event_on(e) function choicebox:on_event(e)
-- select config -- select config
if e.type == event.ev_keyboard then if e.type == event.ev_keyboard then

View File

@@ -42,7 +42,7 @@ function choicedialog:init(name, bounds, title)
-- init buttons -- init buttons
self:button_add("select", "< Select >", function (v, e) 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() self:quit()
end) end)
self:button_add("cancel", "< Cancel >", function (v, e) self:button_add("cancel", "< Cancel >", function (v, e)
@@ -68,7 +68,7 @@ function choicedialog:choicebox()
end end
-- on event -- on event
function choicedialog:event_on(e) function choicedialog:on_event(e)
-- load values first -- load values first
if e.type == event.ev_idle then if e.type == event.ev_idle then
@@ -79,10 +79,10 @@ function choicedialog:event_on(e)
-- select value -- select value
elseif e.type == event.ev_keyboard then elseif e.type == event.ev_keyboard then
if e.key_name == "Down" or e.key_name == "Up" or e.key_name == " " 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
end end
return boxdialog.event_on(self, e) return boxdialog.on_event(self, e)
end end
-- return module -- return module

View File

@@ -102,12 +102,12 @@ function dialog:quit()
end end
-- on event -- on event
function dialog:event_on(e) function dialog:on_event(e)
if e.type == event.ev_keyboard and e.key_name == "Esc" then if e.type == event.ev_keyboard and e.key_name == "Esc" then
self:quit() self:quit()
return true return true
end end
return window.event_on(self, e) return window.on_event(self, e)
end end
-- return module -- return module

View File

@@ -46,8 +46,8 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> or <Back> to go back, <?> for H
]]) ]])
-- init buttons -- init buttons
self:button_add("select", "< Select >", function (v, e) self:menuconf():event_on(event.command {"cm_enter"}) 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():event_on(event.command {"cm_back"}) 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("exit", "< Exit >", function (v, e) self:quit() end)
self:button_add("help", "< Help >", function (v, e) self:show_help() 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) 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 end
-- on event -- on event
function mconfdialog:event_on(e) function mconfdialog:on_event(e)
-- select config -- select config
if e.type == event.ev_keyboard then 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 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 elseif e.key_name == "?" then
self:show_help() self:show_help()
return true return true
@@ -302,7 +302,7 @@ function mconfdialog:event_on(e)
return true return true
end end
end end
return boxdialog.event_on(self, e) return boxdialog.on_event(self, e)
end end
-- return module -- return module

View File

@@ -43,7 +43,7 @@ function menuconf:init(name, bounds)
end end
-- on event -- on event
function menuconf:event_on(e) function menuconf:on_event(e)
-- select config -- select config
local back = false local back = false

View File

@@ -276,7 +276,7 @@ function panel:select_prev(start)
end end
-- on event -- on event
function panel:event_on(e) function panel:on_event(e)
-- select view? -- select view?
if e.type == event.ev_keyboard then if e.type == event.ev_keyboard then
@@ -320,22 +320,22 @@ function panel:draw(transparent)
end end
-- resize panel -- resize panel
function panel:resize() function panel:on_resize()
-- resize panel -- resize panel
view.resize(self) view.on_resize(self)
-- resize all child views -- resize all child views
for v in self:views() do for v in self:views() do
v:state_set("resize", true) v:state_set("resize", true)
if v:state("visible") then if v:state("visible") then
v:resize() v:on_resize()
end end
end end
end end
-- refresh panel -- refresh panel
function panel:refresh() function panel:on_refresh()
-- need not refresh? do not refresh it -- need not refresh? do not refresh it
if not self:state("refresh") or not self:state("visible") then if not self:state("refresh") or not self:state("visible") then
@@ -345,13 +345,13 @@ function panel:refresh()
-- refresh all child views -- refresh all child views
for v in self:views() do for v in self:views() do
if v:state("refresh") then if v:state("refresh") then
v:refresh() v:on_refresh()
v:state_set("refresh", false) v:state_set("refresh", false)
end end
end end
-- refresh it -- refresh it
view.refresh(self) view.on_refresh(self)
-- clear mark -- clear mark
self:state_set("refresh", false) self:state_set("refresh", false)

View File

@@ -140,7 +140,7 @@ function program:event()
end end
-- on event -- on event
function program:event_on(e) function program:on_event(e)
-- get the top focused view -- get the top focused view
local focused_view = self local focused_view = self
@@ -151,7 +151,7 @@ function program:event_on(e)
-- do event for focused views -- do event for focused views
while focused_view and focused_view ~= self do while focused_view and focused_view ~= self do
local parent = focused_view:parent() local parent = focused_view:parent()
if focused_view:event_on(e) then if focused_view:on_event(e) then
return true return true
end end
focused_view = parent focused_view = parent
@@ -180,7 +180,7 @@ function program:event_on(e)
end end
-- put an event to view -- put an event to view
function program:event_put(e) function program:put_event(e)
-- init event queue -- init event queue
self._EVENT_QUEUE = self._EVENT_QUEUE or {} self._EVENT_QUEUE = self._EVENT_QUEUE or {}
@@ -191,7 +191,7 @@ end
-- send command -- send command
function program:send(command, extra) function program:send(command, extra)
self:event_put(event.command {command, extra}) self:put_event(event.command {command, extra})
end end
-- quit program -- quit program
@@ -213,11 +213,11 @@ function program:loop(argv)
-- do event -- do event
if e then if e then
event.dump(e) event.dump(e)
self:event_on(e) self:on_event(e)
sleep = false sleep = false
else else
-- do idle event -- do idle event
self:event_on(event.idle()) self:on_event(event.idle())
sleep = true sleep = true
end end
@@ -228,14 +228,16 @@ function program:loop(argv)
-- resize views -- resize views
if self:state("resize") then if self:state("resize") then
self:resize() self:on_resize()
end end
-- draw views -- draw views
self:draw() self:draw()
-- refresh views -- refresh views
self:refresh() if self:state("refresh") then
self:on_refresh()
end
-- wait some time, 50ms -- wait some time, 50ms
if sleep then if sleep then
@@ -245,15 +247,10 @@ function program:loop(argv)
end end
-- refresh program -- refresh program
function program:refresh() function program:on_refresh()
-- need not refresh? do not refresh it
if not self:state("refresh") then
return
end
-- refresh views -- refresh views
panel.refresh(self) panel.on_refresh(self)
-- trace -- trace
log:print("%s: refresh ..", self) log:print("%s: refresh ..", self)

View File

@@ -52,7 +52,7 @@ function rect:height()
end end
-- resize rect -- resize rect
function rect:resize(w, h) function rect:on_resize(w, h)
self.ex = self.sx + w self.ex = self.sx + w
self.ey = self.sy + h self.ey = self.sy + h
end end

View File

@@ -100,7 +100,7 @@ function textarea:scroll_to_end()
end end
-- on event -- on event
function textarea:event_on(e) function textarea:on_event(e)
if e.type == event.ev_keyboard then if e.type == event.ev_keyboard then
if e.key_name == "Up" then if e.key_name == "Up" then
self:scroll(-5) self:scroll(-5)

View File

@@ -51,16 +51,16 @@ function textdialog:text()
end end
-- on event -- on event
function textdialog:event_on(e) function textdialog:on_event(e)
-- pass event to dialog -- pass event to dialog
if dialog.event_on(self, e) then if dialog.on_event(self, e) then
return true return true
end end
-- pass keyboard event to text area to scroll -- pass keyboard event to text area to scroll
if e.type == event.ev_keyboard then if e.type == event.ev_keyboard then
return self:text():event_on(e) return self:text():on_event(e)
end end
end end

View File

@@ -71,7 +71,7 @@ function textedit:text_set(text)
end end
-- on event -- on event
function textedit:event_on(e) function textedit:on_event(e)
-- update text -- update text
if e.type == event.ev_keyboard then if e.type == event.ev_keyboard then
@@ -97,7 +97,7 @@ function textedit:event_on(e)
end end
-- do textarea event -- do textarea event
return textarea.event_on(self, e) return textarea.on_event(self, e)
end end
-- return module -- return module

View File

@@ -59,8 +59,8 @@ function view:init(name, bounds)
state.selected = false -- is selected? state.selected = false -- is selected?
state.focused = false -- is focused? state.focused = false -- is focused?
state.redraw = true -- need redraw state.redraw = true -- need redraw
state.refresh = true -- need refresh state.on_refresh = true -- need refresh
state.resize = true -- need resize state.on_resize = true -- need resize
self._STATE = state self._STATE = state
-- init options -- init options
@@ -188,7 +188,7 @@ function view:draw(transparent)
end end
-- refresh view -- refresh view
function view:refresh() function view:on_refresh()
-- refresh to the parent view -- refresh to the parent view
local parent = self:parent() local parent = self:parent()
@@ -209,7 +209,7 @@ function view:refresh()
end end
-- resize bounds of inner child views (abstract) -- resize bounds of inner child views (abstract)
function view:resize() function view:on_resize()
-- trace -- trace
log:print("%s: resize ..", self) log:print("%s: resize ..", self)
@@ -265,7 +265,7 @@ end
-- --
-- @return true: done and break dispatching, false/nil: continous to dispatch to other views -- @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 end
-- get the current event -- get the current event
@@ -274,8 +274,8 @@ function view:event()
end end
-- put an event to view -- put an event to view
function view:event_put(e) function view:put_event(e)
return self:parent() and self:parent():event_put(e) return self:parent() and self:parent():put_event(e)
end end
-- get type -- 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) self:title():action_set(action.ac_on_text_changed, function (v)
if v:text() then if v:text() then
local bounds = v:bounds() 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) bounds:move2(math.max(0, math.floor((self:frame():width() - v:width()) / 2)), bounds.sy)
v:invalidate(true) v:invalidate(true)
end end
@@ -113,7 +113,7 @@ function window:border()
end end
-- on event -- on event
function window:event_on(e) function window:on_event(e)
-- select panel? -- select panel?
if e.type == event.ev_keyboard then if e.type == event.ev_keyboard then

View File

@@ -59,8 +59,8 @@ function demo:init()
end end
-- on event -- on event
function demo:event_on(e) function demo:on_event(e)
if application.event_on(self, e) then if application.on_event(self, e) then
return true return true
end end
if e.type == event.ev_keyboard then if e.type == event.ev_keyboard then

View File

@@ -123,12 +123,12 @@ function demo:dialog_tips()
return dialog_tips return dialog_tips
end end
-- resize dialog -- on resize
function demo:resize() function demo:on_resize()
self:dialog_main():bounds_set(rect {1, 1, self:width() - 1, self:height() - 1}) 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_input(), {centerx = true, centery = true})
self:center(self:dialog_tips(), {centerx = true, centery = true}) self:center(self:dialog_tips(), {centerx = true, centery = true})
application.resize(self) application.on_resize(self)
end end
-- run demo -- run demo