mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Small optimization && refactoring
This commit is contained in:
parent
337090e74c
commit
556e1a9bae
@ -60,7 +60,7 @@ end
|
||||
-- @tparam table action on_input action
|
||||
-- @local
|
||||
function BackHandler.on_input(self, action_id, action)
|
||||
if not action[const.RELEASED] then
|
||||
if not action.released then
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -340,10 +340,7 @@ function Button.on_input(self, action_id, action)
|
||||
local is_pick = true
|
||||
local is_key_trigger = (action_id == self.key_trigger)
|
||||
if not is_key_trigger then
|
||||
is_pick = gui.pick_node(self.node, action.x, action.y)
|
||||
if self.click_zone then
|
||||
is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y)
|
||||
end
|
||||
is_pick = helper.pick_node(self.node, action.x, action.y, self.click_zone)
|
||||
end
|
||||
|
||||
if not is_pick then
|
||||
|
@ -185,7 +185,7 @@ function Drag.init(self, node, on_drag_callback)
|
||||
self.is_touch = false
|
||||
self.is_drag = false
|
||||
self.touch_start_pos = vmath.vector3(0)
|
||||
self._is_disabled = false
|
||||
self._is_enabled = true
|
||||
|
||||
self.can_x = true
|
||||
self.can_y = true
|
||||
@ -233,14 +233,11 @@ function Drag.on_input(self, action_id, action)
|
||||
return false
|
||||
end
|
||||
|
||||
if not gui.is_enabled(self.node, true) or self._is_disabled then
|
||||
if not self._is_enabled or not gui.is_enabled(self.node, true) then
|
||||
return false
|
||||
end
|
||||
|
||||
local is_pick = gui.pick_node(self.node, action.x, action.y)
|
||||
if self.click_zone then
|
||||
is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y)
|
||||
end
|
||||
local is_pick = helper.pick_node(self.node, action.x, action.y, self.click_zone)
|
||||
if not is_pick and not self.is_drag then
|
||||
end_touch(self)
|
||||
return false
|
||||
@ -318,7 +315,7 @@ end
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @tparam bool is_enabled
|
||||
function Drag.set_enabled(self, is_enabled)
|
||||
self._is_disabled = not is_enabled
|
||||
self._is_enabled = is_enabled
|
||||
end
|
||||
|
||||
|
||||
@ -326,7 +323,7 @@ end
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @treturn bool
|
||||
function Drag.is_enabled(self)
|
||||
return not self._is_disabled
|
||||
return self._is_enabled
|
||||
end
|
||||
|
||||
|
||||
|
@ -64,11 +64,7 @@ function Hover.on_input(self, action_id, action)
|
||||
return false
|
||||
end
|
||||
|
||||
local is_pick = gui.pick_node(self.node, action.x, action.y)
|
||||
if self.click_zone then
|
||||
is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y)
|
||||
end
|
||||
|
||||
local is_pick = helper.pick_node(self.node, action.x, action.y, self.click_zone)
|
||||
local hover_function = action_id and self.set_hover or self.set_mouse_hover
|
||||
|
||||
if not is_pick then
|
||||
|
@ -99,7 +99,7 @@ end
|
||||
-- @tparam string template BaseComponent template name
|
||||
-- @treturn BaseComponent @{BaseComponent}
|
||||
function BaseComponent.set_template(self, template)
|
||||
template = template or const.EMPTY_STRING
|
||||
template = template or ""
|
||||
|
||||
local parent = self:get_parent_component()
|
||||
if parent and IS_AUTO_TEMPLATE then
|
||||
@ -183,7 +183,7 @@ end
|
||||
-- @tparam string|node node_or_name Node name or node itself
|
||||
-- @treturn node Gui node
|
||||
function BaseComponent.get_node(self, node_or_name)
|
||||
if type(node_or_name) ~= const.STRING then
|
||||
if type(node_or_name) ~= "string" then
|
||||
-- Assume it's already node from gui.get_node
|
||||
return node_or_name
|
||||
end
|
||||
|
@ -10,25 +10,16 @@ local M = {}
|
||||
M.ACTION_TEXT = hash(sys.get_config("druid.input_text", "text"))
|
||||
M.ACTION_TOUCH = hash(sys.get_config("druid.input_touch", "touch"))
|
||||
M.ACTION_MARKED_TEXT = hash(sys.get_config("druid.input_marked_text", "marked_text"))
|
||||
|
||||
M.ACTION_ESC = hash(sys.get_config("druid.input_key_esc", "key_esc"))
|
||||
M.ACTION_BACK = hash(sys.get_config("druid.input_key_back", "key_back"))
|
||||
M.ACTION_ENTER = hash(sys.get_config("druid.input_key_enter", "key_enter"))
|
||||
M.ACTION_MULTITOUCH = hash(sys.get_config("druid.input_multitouch", "touch_multi"))
|
||||
M.ACTION_BACKSPACE = hash(sys.get_config("druid.input_key_backspace", "key_backspace"))
|
||||
|
||||
M.ACTION_SCROLL_UP = hash(sys.get_config("druid.input_scroll_up", "mouse_wheel_up"))
|
||||
M.ACTION_SCROLL_DOWN = hash(sys.get_config("druid.input_scroll_down", "mouse_wheel_down"))
|
||||
|
||||
M.IS_STENCIL_CHECK = not (sys.get_config("druid.no_stencil_check") == "1")
|
||||
|
||||
M.RELEASED = "released"
|
||||
M.PRESSED = "pressed"
|
||||
M.STRING = "string"
|
||||
M.TABLE = "table"
|
||||
M.ZERO = "0"
|
||||
|
||||
|
||||
--- Component Interests
|
||||
M.ON_INPUT = "on_input"
|
||||
M.ON_UPDATE = "update"
|
||||
@ -41,12 +32,11 @@ M.ON_MESSAGE_INPUT = "on_message_input"
|
||||
M.ON_WINDOW_RESIZED = "on_window_resized"
|
||||
M.ON_LANGUAGE_CHANGE = "on_language_change"
|
||||
|
||||
|
||||
-- Components with higher priority value processed first
|
||||
M.PRIORITY_INPUT = 10
|
||||
M.PRIORITY_INPUT_HIGH = 20
|
||||
M.PRIORITY_INPUT_MAX = 100
|
||||
|
||||
|
||||
M.MESSAGE_INPUT = {
|
||||
BUTTON_CLICK = "button_click",
|
||||
BUTTON_LONG_CLICK = "button_long_click",
|
||||
@ -55,7 +45,6 @@ M.MESSAGE_INPUT = {
|
||||
TEXT_SET = "text_set",
|
||||
}
|
||||
|
||||
|
||||
M.PIVOTS = {
|
||||
[gui.PIVOT_CENTER] = vmath.vector3(0),
|
||||
[gui.PIVOT_N] = vmath.vector3(0, 0.5, 0),
|
||||
@ -90,7 +79,6 @@ M.LAYOUT_MODE = {
|
||||
}
|
||||
|
||||
M.VECTOR_ZERO = vmath.vector3(0)
|
||||
M.VECTOR_ONE = vmath.vector3(1)
|
||||
M.SYS_INFO = sys.get_sys_info()
|
||||
M.CURRENT_SYSTEM_NAME = M.SYS_INFO.system_name
|
||||
|
||||
@ -135,6 +123,5 @@ M.ERRORS = {
|
||||
}
|
||||
|
||||
M.EMPTY_FUNCTION = function() end
|
||||
M.EMPTY_STRING = ""
|
||||
|
||||
return M
|
||||
|
@ -123,7 +123,7 @@ end
|
||||
function Input.init(self, click_node, text_node, keyboard_type)
|
||||
self.druid = self:get_druid(self)
|
||||
|
||||
if type(text_node) == const.TABLE then
|
||||
if type(text_node) == "table" then
|
||||
self.text = text_node
|
||||
else
|
||||
self.text = self.druid:new_text(text_node)
|
||||
|
@ -120,11 +120,7 @@ function Swipe.on_input(self, action_id, action)
|
||||
return false
|
||||
end
|
||||
|
||||
local is_pick = gui.pick_node(self.node, action.x, action.y)
|
||||
if self.click_zone then
|
||||
is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y)
|
||||
end
|
||||
|
||||
local is_pick = helper.pick_node(self.node, action.x, action.y, self.click_zone)
|
||||
if not is_pick then
|
||||
reset_swipe(self, action)
|
||||
return false
|
||||
|
@ -271,6 +271,23 @@ function M.add_array(target, source)
|
||||
end
|
||||
|
||||
|
||||
--- Make a check with gui.pick_node, but with additional node_click_area check.
|
||||
-- @function helper.pick_node
|
||||
-- @tparam Node node
|
||||
-- @tparam number x
|
||||
-- @tparam number y
|
||||
-- @tparam[opt] Node node_click_area
|
||||
-- @local
|
||||
function M.pick_node(node, x, y, node_click_area)
|
||||
local is_pick = gui.pick_node(node, x, y)
|
||||
|
||||
if node_click_area then
|
||||
is_pick = is_pick and gui.pick_node(node_click_area, x, y)
|
||||
end
|
||||
|
||||
return is_pick
|
||||
end
|
||||
|
||||
--- Get node size adjusted by scale
|
||||
-- @function helper.get_scaled_size
|
||||
-- @tparam node node GUI node
|
||||
@ -356,7 +373,7 @@ end
|
||||
-- @treturn string
|
||||
function M.table_to_string(t)
|
||||
if not t then
|
||||
return const.EMPTY_STRING
|
||||
return ""
|
||||
end
|
||||
|
||||
local result = "{"
|
||||
|
@ -1,3 +0,0 @@
|
||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||
|
||||
return {}
|
@ -234,8 +234,8 @@ end
|
||||
|
||||
--- Druid class constructor
|
||||
-- @tparam DruidInstance self
|
||||
-- @tparam table context Druid context. Usually it is self of script
|
||||
-- @tparam table style Druid style module
|
||||
-- @tparam table context Druid context. Usually it is self of gui script
|
||||
-- @tparam table style Druid style table
|
||||
-- @local
|
||||
function DruidInstance.initialize(self, context, style)
|
||||
self._context = context
|
||||
|
Loading…
x
Reference in New Issue
Block a user