mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +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
|
||||
|
||||
|
Reference in New Issue
Block a user