Merge branch 'develop' into tests

This commit is contained in:
Insality
2023-02-07 18:45:35 +02:00
27 changed files with 1751 additions and 41 deletions

View File

@@ -61,7 +61,7 @@ local Button = component.create("button")
local function is_input_match(self, action_id)
if action_id == const.ACTION_TOUCH then
if action_id == const.ACTION_TOUCH or action_id == const.ACTION_MULTITOUCH then
return true
end

View File

@@ -5,10 +5,10 @@
-- @within BaseComponent
-- @alias druid.hover
--- On hover callback(self, state)
--- On hover callback(self, state, hover_instance)
-- @tfield DruidEvent on_hover @{DruidEvent}
--- On mouse hover callback(self, state)
--- On mouse hover callback(self, state, hover_instance)
-- @tfield DruidEvent on_mouse_hover @{DruidEvent}
---
@@ -81,6 +81,8 @@ function Hover.on_input(self, action_id, action)
else
hover_function(self, true)
end
return false
end
@@ -95,7 +97,7 @@ end
function Hover.set_hover(self, state)
if self._is_hovered ~= state then
self._is_hovered = state
self.on_hover:trigger(self:get_context(), state)
self.on_hover:trigger(self:get_context(), state, self)
end
end
@@ -114,7 +116,7 @@ end
function Hover.set_mouse_hover(self, state)
if self._is_mouse_hovered ~= state then
self._is_mouse_hovered = state
self.on_mouse_hover:trigger(self:get_context(), state)
self.on_mouse_hover:trigger(self:get_context(), state, self)
end
end

View File

@@ -10,7 +10,7 @@
--- On set text callback(self, text)
-- @tfield DruidEvent on_set_text @{DruidEvent}
--- On adjust text size callback(self, new_scale)
--- On adjust text size callback(self, new_scale, text_metrics)
-- @tfield DruidEvent on_update_text_scale @{DruidEvent}
--- On change pivot callback(self, pivot)
@@ -100,7 +100,7 @@ local function update_text_area_size(self)
update_text_size(self)
self.on_update_text_scale:trigger(self:get_context(), new_scale)
self.on_update_text_scale:trigger(self:get_context(), new_scale, metrics)
end

View File

@@ -14,11 +14,11 @@ M.ACTION_MARKED_TEXT = hash(sys.get_config("druid.input_marked_text", "marked_te
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", "multitouch"))
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", "scroll_up"))
M.ACTION_SCROLL_DOWN = hash(sys.get_config("druid.input_scroll_down", "scroll_down"))
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")

View File

@@ -87,6 +87,7 @@ end
-- @tfield[opt=false] bool IS_LONGTAP_ERASE Is long tap will erase current input data
-- @tfield[opt=*] string MASK_DEFAULT_CHAR Default character mask for password input
-- @tfield[opt=false] bool IS_UNSELECT_ON_RESELECT If true, call unselect on select selected input
-- @tfield[opt=false] bool NO_CONSUME_INPUT_WHILE_SELECTED If true, will not consume input while input is selected. It's allow to interact with other components while input is selected (text input still captured)
-- @tfield function on_select (self, button_node) Callback on input field selecting
-- @tfield function on_unselect (self, button_node) Callback on input field unselecting
-- @tfield function on_input_wrong (self, button_node) Callback on wrong user input
@@ -97,6 +98,7 @@ function Input.on_style_change(self, style)
self.style.IS_LONGTAP_ERASE = style.IS_LONGTAP_ERASE or false
self.style.MASK_DEFAULT_CHAR = style.MASK_DEFAULT_CHAR or "*"
self.style.IS_UNSELECT_ON_RESELECT = style.IS_UNSELECT_ON_RESELECT or false
self.style.NO_CONSUME_INPUT_WHILE_SELECTED = style.NO_CONSUME_INPUT_WHILE_SELECTED or false
self.style.on_select = style.on_select or function(_, button_node) end
self.style.on_unselect = style.on_unselect or function(_, button_node) end
@@ -214,7 +216,8 @@ function Input.on_input(self, action_id, action)
end
end
return self.is_selected
local is_consume_input = not self.style.NO_CONSUME_INPUT_WHILE_SELECTED and self.is_selected
return is_consume_input
end

View File

@@ -121,12 +121,8 @@ function Progress.init(self, node, key, init_value)
end
self.on_change = Event()
end
-- @tparam Progress self @{Progress}
function Progress.on_late_init(self)
self:set_to(self._init_value)
self:set_to(self.last_value)
end

View File

@@ -208,10 +208,10 @@ end
--- Get cumulative parent's node scale
-- @function helper.get_scene_scale
-- @tparam node node Gui node
-- @tparam bool include_node_scale
-- @treturn bool Is enabled in hierarchy
function M.get_scene_scale(node, include_node_scale)
local scale = include_node_scale and gui.get_scale(node) or vmath.vector3(1)
-- @tparam bool include_passed_node_scale True if add current node scale to result
-- @treturn vector3 The scene node scale
function M.get_scene_scale(node, include_passed_node_scale)
local scale = include_passed_node_scale and gui.get_scale(node) or vmath.vector3(1)
local parent = gui.get_parent(node)
while parent do
scale = vmath.mul_per_elem(scale, gui.get_scale(parent))
@@ -319,6 +319,26 @@ function M.get_border(node, offset)
end
--- Get text metric from gui node. Replacement of previous gui.get_text_metrics_from_node function
-- @tparam Node text_node
-- @treturn table {width, height, max_ascent, max_descent}
function M.get_text_metrics_from_node(text_node)
local font_resource = gui.get_font_resource(gui.get_font(text_node))
local options = {
tracking = gui.get_tracking(text_node),
line_break = gui.get_line_break(text_node),
}
-- Gather other options only if it used in node
if options.line_break then
options.width = gui.get_size(text_node).x
options.leading = gui.get_leading(text_node)
end
return resource.get_text_metrics(font_resource, gui.get_text(text_node), options)
end
--- Show deprecated message. Once time per message
-- @function helper.deprecated
-- @tparam string message The deprecated message

View File

@@ -114,6 +114,7 @@ M["input"] = {
BUTTON_SELECT_INCREASE = 1.06,
MASK_DEFAULT_CHAR = "*",
IS_UNSELECT_ON_RESELECT = false,
NO_CONSUME_INPUT_WHILE_SELECTED = false,
on_select = function(self, button_node)
local target_scale = self.button.start_scale

View File

@@ -194,6 +194,18 @@ local function process_input(self, action_id, action, components)
end
local function schedule_late_init(self)
if self._late_init_timer_id then
return
end
self._late_init_timer_id = timer.delay(0, false, function()
self._late_init_timer_id = nil
self:late_init()
end)
end
--- Druid class constructor
-- @tparam DruidInstance self
-- @tparam table context Druid context. Usually it is self of script
@@ -216,10 +228,6 @@ function DruidInstance.initialize(self, context, style)
for i = 1, #base_component.ALL_INTERESTS do
self.components_interest[base_component.ALL_INTERESTS[i]] = {}
end
timer.delay(0, false, function()
self:late_init()
end)
end
@@ -245,6 +253,9 @@ function DruidInstance.new(self, component, ...)
if instance.init then
instance:init(...)
end
if instance.on_late_init or (not self.input_inited and instance.on_input) then
schedule_late_init(self)
end
return instance
end
@@ -316,7 +327,7 @@ function DruidInstance.remove(self, component)
end
--- Druid late update function call after init and before udpate step
--- Druid late update function call after init and before update step
-- @tparam DruidInstance self
function DruidInstance.late_init(self)
local late_init_components = self.components_interest[base_component.ON_LATE_INIT]
@@ -570,7 +581,7 @@ end
-- @tparam node node Gui text node
-- @tparam[opt] string value Initial text. Default value is node text from GUI scene.
-- @tparam[opt] bool no_adjust If true, text will be not auto-adjust size
-- @treturn Tet text component
-- @treturn Text text component
function DruidInstance.new_text(self, node, value, no_adjust)
return DruidInstance.new(self, text, node, value, no_adjust)
end