mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Merge branch 'develop' into rich_text
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -145,7 +145,7 @@ local function on_button_release(self)
|
||||
self.can_action = false
|
||||
|
||||
local time = socket.gettime()
|
||||
local is_long_click = (time - self.last_pressed_time) > self.style.LONGTAP_TIME
|
||||
local is_long_click = (time - self.last_pressed_time) >= self.style.LONGTAP_TIME
|
||||
is_long_click = is_long_click and self.on_long_click:is_exist()
|
||||
|
||||
local is_double_click = (time - self.last_released_time) < self.style.DOUBLETAP_TIME
|
||||
@@ -248,6 +248,10 @@ function Button.on_input(self, action_id, action)
|
||||
return false
|
||||
end
|
||||
|
||||
if not self:is_enabled() then
|
||||
return false
|
||||
end
|
||||
|
||||
local is_pick = true
|
||||
local is_key_trigger = (action_id == self.key_trigger)
|
||||
if not is_key_trigger then
|
||||
@@ -280,7 +284,7 @@ function Button.on_input(self, action_id, action)
|
||||
|
||||
-- While hold button, repeat rate pick from input.repeat_interval
|
||||
if action.repeated then
|
||||
if not self.disabled and self.on_repeated_click:is_exist() and self.can_action then
|
||||
if self.on_repeated_click:is_exist() and self.can_action then
|
||||
on_button_repeated_click(self)
|
||||
return true
|
||||
end
|
||||
@@ -290,7 +294,7 @@ function Button.on_input(self, action_id, action)
|
||||
return on_button_release(self)
|
||||
end
|
||||
|
||||
if not self.disabled and self.can_action and self.on_long_click:is_exist() then
|
||||
if self.can_action and self.on_long_click:is_exist() then
|
||||
local press_time = socket.gettime() - self.last_pressed_time
|
||||
|
||||
if self.style.AUTOHOLD_TRIGGER <= press_time then
|
||||
|
@@ -63,6 +63,7 @@ local function start_touch(self, touch)
|
||||
|
||||
self.x = touch.x
|
||||
self.y = touch.y
|
||||
self._scene_scale = helper.get_scene_scale(self.node)
|
||||
|
||||
self.on_touch_start:trigger(self:get_context())
|
||||
end
|
||||
@@ -155,9 +156,11 @@ end
|
||||
-- or create your own style
|
||||
-- @table style
|
||||
-- @tfield[opt=10] number DRAG_DEADZONE Distance in pixels to start dragging
|
||||
-- @tfield[opt=false] boolean NO_USE_SCREEN_KOEF If screen aspect ratio affects on drag values
|
||||
function Drag.on_style_change(self, style)
|
||||
self.style = {}
|
||||
self.style.DRAG_DEADZONE = style.DRAG_DEADZONE or 10
|
||||
self.style.NO_USE_SCREEN_KOEF = style.NO_USE_SCREEN_KOEF or false
|
||||
end
|
||||
|
||||
|
||||
@@ -181,6 +184,8 @@ function Drag.init(self, node, on_drag_callback)
|
||||
self.can_x = true
|
||||
self.can_y = true
|
||||
|
||||
self._scene_scale = helper.get_scene_scale(self.node)
|
||||
|
||||
self.click_zone = nil
|
||||
self.on_touch_start = Event()
|
||||
self.on_touch_end = Event()
|
||||
@@ -206,6 +211,7 @@ function Drag.on_window_resized(self)
|
||||
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||
self._x_koef = x_koef
|
||||
self._y_koef = y_koef
|
||||
self._scene_scale = helper.get_scene_scale(self.node)
|
||||
end
|
||||
|
||||
|
||||
@@ -229,7 +235,6 @@ function Drag.on_input(self, action_id, action)
|
||||
if self.click_zone then
|
||||
is_pick = is_pick and gui.pick_node(self.click_zone, action.x, action.y)
|
||||
end
|
||||
|
||||
if not is_pick and not self.is_drag then
|
||||
end_touch(self)
|
||||
return false
|
||||
@@ -278,11 +283,16 @@ function Drag.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
if self.is_drag then
|
||||
local x_koef, y_koef = self._x_koef, self._y_koef
|
||||
if self.style.NO_USE_SCREEN_KOEF then
|
||||
x_koef, y_koef = 1, 1
|
||||
end
|
||||
|
||||
self.on_drag:trigger(self:get_context(),
|
||||
self.dx * self._x_koef,
|
||||
self.dy * self._y_koef,
|
||||
(self.x - self.touch_start_pos.x) * self._x_koef,
|
||||
(self.y - self.touch_start_pos.y) * self._y_koef)
|
||||
self.dx * x_koef / self._scene_scale.x,
|
||||
self.dy * y_koef / self._scene_scale.y,
|
||||
(self.x - self.touch_start_pos.x) * x_koef / self._scene_scale.x,
|
||||
(self.y - self.touch_start_pos.y) * y_koef / self._scene_scale.y)
|
||||
end
|
||||
|
||||
return self.is_drag
|
||||
|
@@ -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,21 +97,38 @@ 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
|
||||
|
||||
|
||||
--- Return current hover state. True if touch action was on the node at current time
|
||||
-- @tparam Hover self @{Hover}
|
||||
-- @treturn bool The current hovered state
|
||||
function Hover.is_hovered(self)
|
||||
return self._is_hovered
|
||||
end
|
||||
|
||||
|
||||
--- Set mouse hover state
|
||||
-- @tparam Hover self @{Hover}
|
||||
-- @tparam bool state The mouse hover state
|
||||
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
|
||||
|
||||
|
||||
--- Return current hover state. True if nil action_id (usually desktop mouse) was on the node at current time
|
||||
-- @tparam Hover self @{Hover}
|
||||
-- @treturn bool The current hovered state
|
||||
function Hover.is_mouse_hovered(self)
|
||||
return self._is_mouse_hovered
|
||||
end
|
||||
|
||||
|
||||
--- Strict hover click area. Useful for
|
||||
-- no click events outside stencil node
|
||||
-- @tparam Hover self @{Hover}
|
||||
|
@@ -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)
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local utf8 = require("druid.system.utf8")
|
||||
local component = require("druid.component")
|
||||
|
||||
@@ -77,7 +78,7 @@ local function update_text_area_size(self)
|
||||
local max_width = self.text_area.x
|
||||
local max_height = self.text_area.y
|
||||
|
||||
local metrics = gui.get_text_metrics_from_node(self.node)
|
||||
local metrics = helper.get_text_metrics_from_node(self.node)
|
||||
|
||||
local scale_modifier = max_width / metrics.width
|
||||
scale_modifier = math.min(scale_modifier, self.start_scale.x)
|
||||
@@ -101,7 +102,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
|
||||
|
||||
|
||||
@@ -135,8 +136,8 @@ end
|
||||
-- calculate space width with font
|
||||
local function get_space_width(self, font)
|
||||
if not self._space_width[font] then
|
||||
local no_space = gui.get_text_metrics(font, "1", 0, false, 0, 0).width
|
||||
local with_space = gui.get_text_metrics(font, " 1", 0, false, 0, 0).width
|
||||
local no_space = resource.get_text_metrics(font, "1").width
|
||||
local with_space = resource.get_text_metrics(font, " 1").width
|
||||
self._space_width[font] = with_space - no_space
|
||||
end
|
||||
|
||||
|
@@ -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")
|
||||
|
@@ -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
|
||||
|
||||
|
||||
|
@@ -36,10 +36,13 @@ function Layout.init(self, node, mode, on_size_changed_callback)
|
||||
|
||||
self._min_size = nil
|
||||
self._max_size = nil
|
||||
self._current_size = vmath.vector3(0)
|
||||
self._inited = false
|
||||
|
||||
self._max_gui_upscale = nil
|
||||
self._fit_node = nil
|
||||
|
||||
self._anchors = {}
|
||||
|
||||
self.mode = mode or const.LAYOUT_MODE.FIT
|
||||
|
||||
self.on_size_changed = Event(on_size_changed_callback)
|
||||
@@ -66,6 +69,13 @@ function Layout.on_window_resized(self)
|
||||
|
||||
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||
|
||||
local revert_scale = 1
|
||||
if self._max_gui_upscale then
|
||||
revert_scale = self._max_gui_upscale / helper.get_gui_scale()
|
||||
revert_scale = math.min(revert_scale, 1)
|
||||
end
|
||||
gui.set_scale(self.node, vmath.vector3(revert_scale))
|
||||
|
||||
if self._fit_node then
|
||||
self.fit_size = gui.get_size(self._fit_node)
|
||||
self.fit_size.x = self.fit_size.x / x_koef
|
||||
@@ -77,11 +87,17 @@ function Layout.on_window_resized(self)
|
||||
|
||||
local new_size = vmath.vector3(self.origin_size)
|
||||
|
||||
if self.mode == const.LAYOUT_MODE.STRETCH_X or self.mode == const.LAYOUT_MODE.STRETCH then
|
||||
new_size.x = new_size.x * x_koef
|
||||
if self.mode == const.LAYOUT_MODE.STRETCH then
|
||||
new_size.x = new_size.x * x_koef / revert_scale
|
||||
new_size.y = new_size.y * y_koef / revert_scale
|
||||
end
|
||||
if self.mode == const.LAYOUT_MODE.STRETCH_Y or self.mode == const.LAYOUT_MODE.STRETCH then
|
||||
new_size.y = new_size.y * y_koef
|
||||
|
||||
if self.mode == const.LAYOUT_MODE.STRETCH_X then
|
||||
new_size.x = new_size.x * x_koef / revert_scale
|
||||
end
|
||||
|
||||
if self.mode == const.LAYOUT_MODE.STRETCH_Y then
|
||||
new_size.y = new_size.y * y_koef / revert_scale
|
||||
end
|
||||
|
||||
-- Fit to the stretched container (node size or other defined)
|
||||
@@ -100,6 +116,7 @@ function Layout.on_window_resized(self)
|
||||
new_size.x = math.min(new_size.x, self._max_size.x)
|
||||
new_size.y = math.min(new_size.y, self._max_size.y)
|
||||
end
|
||||
self._current_size = new_size
|
||||
gui.set_size(self.node, new_size)
|
||||
|
||||
self.position.x = self.origin_position.x + self.origin_position.x * (x_koef - 1)
|
||||
@@ -152,6 +169,16 @@ function Layout.set_origin_size(self, new_origin_size)
|
||||
end
|
||||
|
||||
|
||||
--- Set max gui upscale for FIT adjust mode (or side). It happens on bigger render gui screen
|
||||
-- @tparam Layout self @{Layout}
|
||||
-- @tparam number max_gui_upscale
|
||||
-- @treturn Layout @{Layout}
|
||||
function Layout.set_max_gui_upscale(self, max_gui_upscale)
|
||||
self._max_gui_upscale = max_gui_upscale
|
||||
self:on_window_resized()
|
||||
end
|
||||
|
||||
|
||||
--- Set size for layout node to fit inside it
|
||||
-- @tparam Layout self @{Layout}
|
||||
-- @tparam vector3 target_size
|
||||
|
@@ -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
|
||||
|
||||
|
||||
|
@@ -64,7 +64,7 @@ function Slider.init(self, node, end_pos, callback)
|
||||
|
||||
self.start_pos = gui.get_position(self.node)
|
||||
self.pos = gui.get_position(self.node)
|
||||
self.target_pos = self.pos
|
||||
self.target_pos = vmath.vector3(self.pos)
|
||||
self.end_pos = end_pos
|
||||
|
||||
self.dist = self.end_pos - self.start_pos
|
||||
@@ -72,6 +72,7 @@ function Slider.init(self, node, end_pos, callback)
|
||||
self.value = 0
|
||||
|
||||
self.on_change_value = Event(callback)
|
||||
self:on_window_resized()
|
||||
|
||||
assert(self.dist.x == 0 or self.dist.y == 0, "Slider for now can be only vertical or horizontal")
|
||||
end
|
||||
@@ -82,6 +83,14 @@ function Slider.on_layout_change(self)
|
||||
end
|
||||
|
||||
|
||||
function Slider.on_window_resized(self)
|
||||
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||
self._x_koef = x_koef
|
||||
self._y_koef = y_koef
|
||||
self._scene_scale = helper.get_scene_scale(self.node)
|
||||
end
|
||||
|
||||
|
||||
function Slider.on_input(self, action_id, action)
|
||||
if action_id ~= const.ACTION_TOUCH then
|
||||
return false
|
||||
@@ -90,15 +99,17 @@ function Slider.on_input(self, action_id, action)
|
||||
if gui.pick_node(self.node, action.x, action.y) then
|
||||
if action.pressed then
|
||||
self.pos = gui.get_position(self.node)
|
||||
self._scene_scale = helper.get_scene_scale(self.node)
|
||||
self.is_drag = true
|
||||
end
|
||||
end
|
||||
|
||||
if not self.is_drag and self._input_node and gui.pick_node(self._input_node, action.x, action.y) then
|
||||
if action.pressed and gui.screen_to_local then
|
||||
self._scene_scale = helper.get_scene_scale(self.node)
|
||||
self.pos = gui.screen_to_local(self.node, vmath.vector3(action.screen_x, action.screen_y, 0))
|
||||
self.pos.x = helper.clamp(self.pos.x, self.start_pos.x, self.end_pos.x)
|
||||
self.pos.y = helper.clamp(self.pos.y, self.start_pos.y, self.end_pos.y)
|
||||
self.pos.x = helper.clamp(self.pos.x / self._scene_scale.x, self.start_pos.x, self.end_pos.x)
|
||||
self.pos.y = helper.clamp(self.pos.y / self._scene_scale.y, self.start_pos.y, self.end_pos.y)
|
||||
|
||||
gui.set_position(self.node, self.pos)
|
||||
self.is_drag = true
|
||||
@@ -107,8 +118,8 @@ function Slider.on_input(self, action_id, action)
|
||||
|
||||
if self.is_drag and not action.pressed then
|
||||
-- move
|
||||
self.pos.x = self.pos.x + action.dx
|
||||
self.pos.y = self.pos.y + action.dy
|
||||
self.pos.x = self.pos.x + action.dx * self._x_koef / self._scene_scale.x
|
||||
self.pos.y = self.pos.y + action.dy * self._y_koef / self._scene_scale.y
|
||||
|
||||
local prev_x = self.target_pos.x
|
||||
local prev_y = self.target_pos.y
|
||||
|
@@ -12,7 +12,7 @@ local M = {}
|
||||
--- Text node or icon node can be nil
|
||||
local function get_text_width(text_node)
|
||||
if text_node then
|
||||
local text_metrics = gui.get_text_metrics_from_node(text_node)
|
||||
local text_metrics = M.get_text_metrics_from_node(text_node)
|
||||
local text_scale = gui.get_scale(text_node).x
|
||||
return text_metrics.width * text_scale
|
||||
end
|
||||
@@ -107,6 +107,13 @@ function M.get_screen_aspect_koef()
|
||||
end
|
||||
|
||||
|
||||
function M.get_gui_scale()
|
||||
local window_x, window_y = window.get_size()
|
||||
return math.min(window_x / gui.get_width(),
|
||||
window_y / gui.get_height())
|
||||
end
|
||||
|
||||
|
||||
function M.step(current, target, step)
|
||||
if current < target then
|
||||
return math.min(current + step, target)
|
||||
@@ -166,6 +173,21 @@ function M.contains(t, value)
|
||||
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_name = gui.get_font(text_node)
|
||||
local font = gui.get_font_resource(font_name)
|
||||
return resource.get_text_metrics(font, gui.get_text(text_node), {
|
||||
width = gui.get_size(text_node).x,
|
||||
leading = gui.get_leading(text_node),
|
||||
tracking = gui.get_tracking(text_node),
|
||||
line_break = gui.get_line_break(text_node),
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
--- Check if node is enabled in gui hierarchy.
|
||||
-- Return false, if node or any his parent is disabled
|
||||
-- @function helper.is_enabled
|
||||
@@ -183,6 +205,23 @@ function M.is_enabled(node)
|
||||
end
|
||||
|
||||
|
||||
--- Get cumulative parent's node scale
|
||||
-- @function helper.get_scene_scale
|
||||
-- @tparam node node Gui node
|
||||
-- @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))
|
||||
parent = gui.get_parent(parent)
|
||||
end
|
||||
|
||||
return scale
|
||||
end
|
||||
|
||||
|
||||
--- Return closest non inverted clipping parent node for node
|
||||
-- @function helper.get_closest_stencil_node
|
||||
-- @tparam node node Gui node
|
||||
@@ -280,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
|
||||
|
@@ -56,6 +56,7 @@ M["button"] = {
|
||||
|
||||
M["drag"] = {
|
||||
DRAG_DEADZONE = 10, -- Size in pixels of drag deadzone
|
||||
NO_USE_SCREEN_KOEF = false,
|
||||
}
|
||||
|
||||
|
||||
@@ -113,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
|
||||
|
@@ -49,16 +49,17 @@ local static_grid = require("druid.base.static_grid")
|
||||
local swipe = require("druid.base.swipe")
|
||||
local text = require("druid.base.text")
|
||||
|
||||
local checkbox = require("druid.extended.checkbox")
|
||||
local checkbox_group = require("druid.extended.checkbox_group")
|
||||
local dynamic_grid = require("druid.extended.dynamic_grid")
|
||||
local input = require("druid.extended.input")
|
||||
local lang_text = require("druid.extended.lang_text")
|
||||
local progress = require("druid.extended.progress")
|
||||
local radio_group = require("druid.extended.radio_group")
|
||||
local slider = require("druid.extended.slider")
|
||||
local timer_component = require("druid.extended.timer")
|
||||
local data_list = require("druid.extended.data_list")
|
||||
-- To use this components, you should register them first
|
||||
-- local checkbox = require("druid.extended.checkbox")
|
||||
-- local checkbox_group = require("druid.extended.checkbox_group")
|
||||
-- local dynamic_grid = require("druid.extended.dynamic_grid")
|
||||
-- local input = require("druid.extended.input")
|
||||
-- local lang_text = require("druid.extended.lang_text")
|
||||
-- local progress = require("druid.extended.progress")
|
||||
-- local radio_group = require("druid.extended.radio_group")
|
||||
-- local slider = require("druid.extended.slider")
|
||||
-- local timer_component = require("druid.extended.timer")
|
||||
-- local data_list = require("druid.extended.data_list")
|
||||
|
||||
|
||||
local DruidInstance = class("druid.druid_instance")
|
||||
@@ -193,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
|
||||
@@ -215,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
|
||||
|
||||
|
||||
@@ -244,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
|
||||
@@ -315,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]
|
||||
@@ -569,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
|
||||
@@ -634,8 +646,7 @@ end
|
||||
-- @tparam node parent The gui node parent, where items will be placed
|
||||
-- @treturn DynamicGrid grid component
|
||||
function DruidInstance.new_dynamic_grid(self, parent)
|
||||
-- return helper.extended_component("dynamic_grid")
|
||||
return DruidInstance.new(self, dynamic_grid, parent)
|
||||
return helper.extended_component("dynamic_grid")
|
||||
end
|
||||
|
||||
|
||||
@@ -646,8 +657,7 @@ end
|
||||
-- @tparam bool no_adjust If true, will not correct text size
|
||||
-- @treturn LangText lang_text component
|
||||
function DruidInstance.new_lang_text(self, node, locale_id, no_adjust)
|
||||
-- return helper.extended_component("lang_text")
|
||||
return DruidInstance.new(self, lang_text, node, locale_id, no_adjust)
|
||||
return helper.extended_component("lang_text")
|
||||
end
|
||||
|
||||
|
||||
@@ -658,8 +668,7 @@ end
|
||||
-- @tparam[opt] function callback On slider change callback
|
||||
-- @treturn Slider slider component
|
||||
function DruidInstance.new_slider(self, node, end_pos, callback)
|
||||
-- return helper.extended_component("slider")
|
||||
return DruidInstance.new(self, slider, node, end_pos, callback)
|
||||
return helper.extended_component("slider")
|
||||
end
|
||||
|
||||
|
||||
@@ -671,8 +680,7 @@ end
|
||||
-- @tparam[opt=false] boolean initial_state The initial state of checkbox, default - false
|
||||
-- @treturn Checkbox checkbox component
|
||||
function DruidInstance.new_checkbox(self, node, callback, click_node, initial_state)
|
||||
-- return helper.extended_component("checkbox")
|
||||
return DruidInstance.new(self, checkbox, node, callback, click_node, initial_state)
|
||||
return helper.extended_component("checkbox")
|
||||
end
|
||||
|
||||
|
||||
@@ -683,8 +691,7 @@ end
|
||||
-- @tparam[opt] number keyboard_type Gui keyboard type for input field
|
||||
-- @treturn Input input component
|
||||
function DruidInstance.new_input(self, click_node, text_node, keyboard_type)
|
||||
-- return helper.extended_component("input")
|
||||
return DruidInstance.new(self, input, click_node, text_node, keyboard_type)
|
||||
return helper.extended_component("input")
|
||||
end
|
||||
|
||||
|
||||
@@ -695,8 +702,7 @@ end
|
||||
-- @tparam[opt=node] node[] click_nodes Array of trigger nodes, by default equals to nodes
|
||||
-- @treturn CheckboxGroup checkbox_group component
|
||||
function DruidInstance.new_checkbox_group(self, nodes, callback, click_nodes)
|
||||
-- return helper.extended_component("checkbox_group")
|
||||
return DruidInstance.new(self, checkbox_group, nodes, callback, click_nodes)
|
||||
return helper.extended_component("checkbox_group")
|
||||
end
|
||||
|
||||
|
||||
@@ -707,8 +713,7 @@ end
|
||||
-- @tparam function create_function The create function callback(self, data, index, data_list). Function should return (node, [component])
|
||||
-- @treturn DataList data_list component
|
||||
function DruidInstance.new_data_list(self, druid_scroll, druid_grid, create_function)
|
||||
-- return helper.extended_component("data_list")
|
||||
return DruidInstance.new(self, data_list, druid_scroll, druid_grid, create_function)
|
||||
return helper.extended_component("data_list")
|
||||
end
|
||||
|
||||
|
||||
@@ -719,8 +724,7 @@ end
|
||||
-- @tparam[opt=node] node[] click_nodes Array of trigger nodes, by default equals to nodes
|
||||
-- @treturn RadioGroup radio_group component
|
||||
function DruidInstance.new_radio_group(self, nodes, callback, click_nodes)
|
||||
-- return helper.extended_component("radio_group")
|
||||
return DruidInstance.new(self, radio_group, nodes, callback, click_nodes)
|
||||
return helper.extended_component("radio_group")
|
||||
end
|
||||
|
||||
|
||||
@@ -732,8 +736,7 @@ end
|
||||
-- @tparam[opt] function callback Function on timer end
|
||||
-- @treturn Timer timer component
|
||||
function DruidInstance.new_timer(self, node, seconds_from, seconds_to, callback)
|
||||
-- return helper.extended_component("timer")
|
||||
return DruidInstance.new(self, timer_component, node, seconds_from, seconds_to, callback)
|
||||
return helper.extended_component("timer")
|
||||
end
|
||||
|
||||
|
||||
@@ -744,8 +747,7 @@ end
|
||||
-- @tparam[opt=1] number init_value Initial value of progress bar
|
||||
-- @treturn Progress progress component
|
||||
function DruidInstance.new_progress(self, node, key, init_value)
|
||||
-- return helper.extended_component("progress")
|
||||
return DruidInstance.new(self, progress, node, key, init_value)
|
||||
return helper.extended_component("progress")
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user