mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Solve #73 fix scroll drag on stretch/zoom nodes
This commit is contained in:
parent
f7e6888c5a
commit
decb9fd9fd
@ -186,6 +186,8 @@ function Drag.init(self, node, on_drag_callback)
|
|||||||
self.on_drag_start = Event()
|
self.on_drag_start = Event()
|
||||||
self.on_drag = Event(on_drag_callback)
|
self.on_drag = Event(on_drag_callback)
|
||||||
self.on_drag_end = Event()
|
self.on_drag_end = Event()
|
||||||
|
|
||||||
|
self:on_window_resized()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -199,6 +201,13 @@ function Drag.on_late_init(self)
|
|||||||
end
|
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)
|
function Drag.on_input_interrupt(self)
|
||||||
if self.is_drag or self.is_touch then
|
if self.is_drag or self.is_touch then
|
||||||
end_touch(self)
|
end_touch(self)
|
||||||
@ -258,8 +267,8 @@ function Drag.on_input(self, action_id, action)
|
|||||||
|
|
||||||
local touch_modified = find_touch(action_id, action, self.touch_id)
|
local touch_modified = find_touch(action_id, action, self.touch_id)
|
||||||
if touch_modified and self.is_drag then
|
if touch_modified and self.is_drag then
|
||||||
self.dx = touch_modified.x - self.x
|
self.dx = (touch_modified.x - self.x) * self._x_koef
|
||||||
self.dy = touch_modified.y - self.y
|
self.dy = (touch_modified.y - self.y) * self._y_koef
|
||||||
end
|
end
|
||||||
|
|
||||||
if touch_modified then
|
if touch_modified then
|
||||||
|
@ -30,7 +30,6 @@ function Layout:init(node, mode, on_size_changed_callback)
|
|||||||
self._min_size = nil
|
self._min_size = nil
|
||||||
self._max_size = nil
|
self._max_size = nil
|
||||||
|
|
||||||
self.window_size = vmath.vector3(gui.get_width(), gui.get_height(), 0)
|
|
||||||
self.mode = mode or const.LAYOUT_MODE.FIT
|
self.mode = mode or const.LAYOUT_MODE.FIT
|
||||||
|
|
||||||
self.on_size_changed = Event(on_size_changed_callback)
|
self.on_size_changed = Event(on_size_changed_callback)
|
||||||
@ -40,12 +39,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function Layout:on_window_resized()
|
function Layout:on_window_resized()
|
||||||
local window_x, window_y = window.get_size()
|
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||||
local stretch_x = window_x / self.window_size.x
|
|
||||||
local stretch_y = window_y / self.window_size.y
|
|
||||||
|
|
||||||
local x_koef = stretch_x / math.min(stretch_x, stretch_y)
|
|
||||||
local y_koef = stretch_y / math.min(stretch_x, stretch_y)
|
|
||||||
|
|
||||||
local new_size = vmath.vector3(self.origin_size)
|
local new_size = vmath.vector3(self.origin_size)
|
||||||
if self.mode == const.LAYOUT_MODE.STRETCH_X or self.mode == const.LAYOUT_MODE.STRETCH then
|
if self.mode == const.LAYOUT_MODE.STRETCH_X or self.mode == const.LAYOUT_MODE.STRETCH then
|
||||||
@ -65,8 +59,8 @@ function Layout:on_window_resized()
|
|||||||
|
|
||||||
gui.set_size(self.node, new_size)
|
gui.set_size(self.node, new_size)
|
||||||
|
|
||||||
self.position.x = self.origin_position.x * x_koef + self.origin_position.x * (1 - x_koef) * self.pivot.x * 2
|
self.position.x = self.origin_position.x + self.origin_position.x * (1 - x_koef) * self.pivot.x * 2
|
||||||
self.position.y = self.origin_position.y * y_koef + self.origin_position.y * (1 - y_koef) * self.pivot.y * 2
|
self.position.y = self.origin_position.y + self.origin_position.y * (1 - y_koef) * self.pivot.y * 2
|
||||||
gui.set_position(self.node, self.position)
|
gui.set_position(self.node, self.position)
|
||||||
|
|
||||||
self.on_size_changed:trigger(self:get_context(), new_size)
|
self.on_size_changed:trigger(self:get_context(), new_size)
|
||||||
|
@ -97,6 +97,15 @@ function M.centrate_nodes(margin, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.get_screen_aspect_koef()
|
||||||
|
local window_x, window_y = window.get_size()
|
||||||
|
local stretch_x = window_x / gui.get_width()
|
||||||
|
local stretch_y = window_y / gui.get_height()
|
||||||
|
return stretch_x / math.min(stretch_x, stretch_y),
|
||||||
|
stretch_y / math.min(stretch_x, stretch_y)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function M.step(current, target, step)
|
function M.step(current, target, step)
|
||||||
if current < target then
|
if current < target then
|
||||||
return math.min(current + step, target)
|
return math.min(current + step, target)
|
||||||
|
@ -71,7 +71,7 @@ nodes {
|
|||||||
nodes {
|
nodes {
|
||||||
position {
|
position {
|
||||||
x: 0.0
|
x: 0.0
|
||||||
y: 200.0
|
y: 250.0
|
||||||
z: 0.0
|
z: 0.0
|
||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ nodes {
|
|||||||
nodes {
|
nodes {
|
||||||
position {
|
position {
|
||||||
x: 0.0
|
x: 0.0
|
||||||
y: 0.0
|
y: 50.0
|
||||||
z: 0.0
|
z: 0.0
|
||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ nodes {
|
|||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_CENTER
|
||||||
adjust_mode: ADJUST_MODE_STRETCH
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
parent: "root"
|
parent: "root"
|
||||||
layer: ""
|
layer: ""
|
||||||
inherit_alpha: true
|
inherit_alpha: true
|
||||||
@ -604,6 +604,126 @@ nodes {
|
|||||||
text_tracking: 0.0
|
text_tracking: 0.0
|
||||||
custom_type: 0
|
custom_type: 0
|
||||||
}
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: -150.0
|
||||||
|
y: -400.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
rotation {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
scale {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
size {
|
||||||
|
x: 300.0
|
||||||
|
y: 100.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
color {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
type: TYPE_BOX
|
||||||
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
|
texture: "kenney/slider_move"
|
||||||
|
id: "node_layout_stretch_y_anchor_w"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_W
|
||||||
|
adjust_mode: ADJUST_MODE_STRETCH
|
||||||
|
parent: "even_in_fit_node"
|
||||||
|
layer: ""
|
||||||
|
inherit_alpha: true
|
||||||
|
slice9 {
|
||||||
|
x: 17.0
|
||||||
|
y: 17.0
|
||||||
|
z: 17.0
|
||||||
|
w: 17.0
|
||||||
|
}
|
||||||
|
clipping_mode: CLIPPING_MODE_NONE
|
||||||
|
clipping_visible: true
|
||||||
|
clipping_inverted: false
|
||||||
|
alpha: 1.0
|
||||||
|
template_node_child: false
|
||||||
|
size_mode: SIZE_MODE_MANUAL
|
||||||
|
custom_type: 0
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
position {
|
||||||
|
x: 150.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
rotation {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
scale {
|
||||||
|
x: 0.65
|
||||||
|
y: 0.65
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
size {
|
||||||
|
x: 450.0
|
||||||
|
y: 100.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
color {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
type: TYPE_TEXT
|
||||||
|
blend_mode: BLEND_MODE_ALPHA
|
||||||
|
text: "Layout Stretch by Y Anchor W"
|
||||||
|
font: "game"
|
||||||
|
id: "text_layout_stretch3"
|
||||||
|
xanchor: XANCHOR_NONE
|
||||||
|
yanchor: YANCHOR_NONE
|
||||||
|
pivot: PIVOT_CENTER
|
||||||
|
outline {
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
shadow {
|
||||||
|
x: 1.0
|
||||||
|
y: 1.0
|
||||||
|
z: 1.0
|
||||||
|
w: 1.0
|
||||||
|
}
|
||||||
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
|
line_break: true
|
||||||
|
parent: "node_layout_stretch_y_anchor_w"
|
||||||
|
layer: ""
|
||||||
|
inherit_alpha: true
|
||||||
|
alpha: 1.0
|
||||||
|
outline_alpha: 1.0
|
||||||
|
shadow_alpha: 0.0
|
||||||
|
template_node_child: false
|
||||||
|
text_leading: 1.0
|
||||||
|
text_tracking: 0.0
|
||||||
|
custom_type: 0
|
||||||
|
}
|
||||||
layers {
|
layers {
|
||||||
name: "image"
|
name: "image"
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ function init(self)
|
|||||||
self.druid:new_layout("node_layout_stretch", const_druid.LAYOUT_MODE.STRETCH)
|
self.druid:new_layout("node_layout_stretch", const_druid.LAYOUT_MODE.STRETCH)
|
||||||
self.druid:new_layout("node_layout_stretch_x", const_druid.LAYOUT_MODE.STRETCH_X)
|
self.druid:new_layout("node_layout_stretch_x", const_druid.LAYOUT_MODE.STRETCH_X)
|
||||||
self.druid:new_layout("node_layout_stretch_y", const_druid.LAYOUT_MODE.STRETCH_Y)
|
self.druid:new_layout("node_layout_stretch_y", const_druid.LAYOUT_MODE.STRETCH_Y)
|
||||||
|
self.druid:new_layout("node_layout_stretch_y_anchor_w", const_druid.LAYOUT_MODE.STRETCH_Y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user