diff --git a/src/ltui/boxdialog.lua b/src/ltui/boxdialog.lua index d9ab03f..184b9e8 100644 --- a/src/ltui/boxdialog.lua +++ b/src/ltui/boxdialog.lua @@ -68,7 +68,7 @@ function boxdialog:init(name, bounds, title) if curses.KEY_MOUSE then -- set click action - self:frame():action_set(ltui.action.ac_on_clicked, function (v, x, y) + self:frame():action_set(action.ac_on_clicked, function (v, x, y) -- return if not mouseable if not v:option("mouseable") then @@ -87,7 +87,7 @@ function boxdialog:init(name, bounds, title) box:bounds():contains(px, py) then -- bypass panel - return box:action_on(ltui.action.ac_on_clicked, px, py) + return box:action_on(action.ac_on_clicked, px, py) end -- return true if it doesn't match any selectable view diff --git a/src/ltui/button.lua b/src/ltui/button.lua index ca688d9..d6858ac 100644 --- a/src/ltui/button.lua +++ b/src/ltui/button.lua @@ -38,28 +38,31 @@ function button:init(name, bounds, text, on_action) -- mark as selectable self:option_set("selectable", true) - -- mark as mouseable - self:option_set("mouseable", true) - - -- set click action - self:action_set(ltui.action.ac_on_clicked, function (v) - - -- return if not mouseable - if not v:option("mouseable") then - return - end - - if v:parent()._do_select then - return v:parent():_do_select() - end - return v:action_on(ltui.action.ac_on_enter) - end) - -- show cursor self:cursor_show(true) -- init action self:action_set(action.ac_on_enter, on_action) + + if curses.KEY_MOUSE then + + -- mark as mouseable + self:option_set("mouseable", true) + + -- set click action + self:action_set(action.ac_on_clicked, function (v) + + -- return if not mouseable + if not v:option("mouseable") then + return + end + + if v:parent()._do_select then + return v:parent():_do_select() + end + return v:action_on(action.ac_on_enter) + end) + end end -- draw button diff --git a/src/ltui/panel.lua b/src/ltui/panel.lua index d105287..89da183 100644 --- a/src/ltui/panel.lua +++ b/src/ltui/panel.lua @@ -67,7 +67,7 @@ function panel:init(name, bounds) -- try focused first if v:current() and v:current():bounds():contains(x, y) then - return v:current():action_on(ltui.action.ac_on_clicked, x, y) + return v:current():action_on(action.ac_on_clicked, x, y) end local p = v:last()