mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Merge branch 'layout' into develop
This commit is contained in:
@@ -17,10 +17,10 @@
|
||||
--- Event on drag start callback(self)
|
||||
-- @tfield DruidEvent on_drag_start @{DruidEvent}
|
||||
|
||||
--- on drag progress callback(self, dx, dy)
|
||||
--- on drag progress callback(self, dx, dy, total_x, total_y)
|
||||
-- @tfield DruidEvent on_drag Event @{DruidEvent}
|
||||
|
||||
--- Event on drag end callback(self)
|
||||
--- Event on drag end callback(self, total_x, total_y)
|
||||
-- @tfield DruidEvent on_drag_end @{DruidEvent}
|
||||
|
||||
--- Is component now touching
|
||||
@@ -70,7 +70,7 @@ end
|
||||
|
||||
local function end_touch(self)
|
||||
if self.is_drag then
|
||||
self.on_drag_end:trigger(self:get_context())
|
||||
self.on_drag_end:trigger(self:get_context(), self.x - self.touch_start_pos.x, self.y - self.touch_start_pos.y)
|
||||
end
|
||||
|
||||
self.is_drag = false
|
||||
@@ -96,7 +96,7 @@ local function process_touch(self, touch)
|
||||
if not self.is_drag and distance >= self.style.DRAG_DEADZONE then
|
||||
self.is_drag = true
|
||||
self.on_drag_start:trigger(self:get_context())
|
||||
self:set_input_priority(const.PRIORITY_INPUT_MAX)
|
||||
self:set_input_priority(const.PRIORITY_INPUT_MAX, true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -176,6 +176,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.can_x = true
|
||||
self.can_y = true
|
||||
@@ -186,6 +187,8 @@ function Drag.init(self, node, on_drag_callback)
|
||||
self.on_drag_start = Event()
|
||||
self.on_drag = Event(on_drag_callback)
|
||||
self.on_drag_end = Event()
|
||||
|
||||
self:on_window_resized()
|
||||
end
|
||||
|
||||
|
||||
@@ -199,6 +202,13 @@ function Drag.on_late_init(self)
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
function Drag.on_input_interrupt(self)
|
||||
if self.is_drag or self.is_touch then
|
||||
end_touch(self)
|
||||
@@ -211,7 +221,7 @@ function Drag.on_input(self, action_id, action)
|
||||
return false
|
||||
end
|
||||
|
||||
if not helper.is_enabled(self.node) then
|
||||
if not helper.is_enabled(self.node) or self._is_disabled then
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -268,7 +278,7 @@ function Drag.on_input(self, action_id, action)
|
||||
end
|
||||
|
||||
if self.is_drag then
|
||||
self.on_drag:trigger(self:get_context(), self.dx, self.dy)
|
||||
self.on_drag:trigger(self:get_context(), self.dx, self.dy, self.x - self.touch_start_pos.x, self.y - self.touch_start_pos.y)
|
||||
end
|
||||
|
||||
return self.is_drag
|
||||
@@ -284,4 +294,21 @@ function Drag.set_click_zone(self, node)
|
||||
end
|
||||
|
||||
|
||||
--- Set Drag input enabled or disabled
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @tparam bool is enabled
|
||||
function Drag.set_enabled(self, is_enabled)
|
||||
self._is_disabled = not is_enabled
|
||||
end
|
||||
|
||||
|
||||
--- Check if Drag component is enabled
|
||||
-- @tparam Drag self @{Drag}
|
||||
-- @treturn bool
|
||||
function Drag.is_enabled(self)
|
||||
return self._is_disabled
|
||||
end
|
||||
|
||||
|
||||
|
||||
return Drag
|
||||
|
@@ -33,9 +33,12 @@
|
||||
--- The last index of node in grid
|
||||
-- @tfield number last_index
|
||||
|
||||
--- Item anchor
|
||||
--- Item anchor [0..1]
|
||||
-- @tfield vector3 anchor
|
||||
|
||||
--- Item pivot [-0.5..0.5]
|
||||
-- @tfield vector3 pivot
|
||||
|
||||
--- Item size
|
||||
-- @tfield vector3 node_size
|
||||
|
||||
|
@@ -240,10 +240,16 @@ end
|
||||
-- @treturn number Height
|
||||
function Text.get_text_size(self, text)
|
||||
text = text or self.last_value
|
||||
local font = gui.get_font(self.node)
|
||||
local font_name = gui.get_font(self.node)
|
||||
local font = gui.get_font_resource(font_name)
|
||||
local scale = gui.get_scale(self.node)
|
||||
local linebreak = gui.get_line_break(self.node)
|
||||
local metrics = gui.get_text_metrics(font, text, 0, linebreak, 0, 0)
|
||||
local metrics = resource.get_text_metrics(font, text, {
|
||||
line_break = linebreak,
|
||||
leading = 1,
|
||||
tracking = 0,
|
||||
width = self.start_size.x
|
||||
})
|
||||
local width = metrics.width
|
||||
for i = #text, 1, -1 do
|
||||
local c = string.sub(text, i, i)
|
||||
|
Reference in New Issue
Block a user