mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Update layout component
This commit is contained in:
parent
e029d1eac3
commit
0107c015a1
@ -33,9 +33,12 @@
|
|||||||
--- The last index of node in grid
|
--- The last index of node in grid
|
||||||
-- @tfield number last_index
|
-- @tfield number last_index
|
||||||
|
|
||||||
--- Item anchor
|
--- Item anchor [0..1]
|
||||||
-- @tfield vector3 anchor
|
-- @tfield vector3 anchor
|
||||||
|
|
||||||
|
--- Item pivot [-0.5..0.5]
|
||||||
|
-- @tfield vector3 pivot
|
||||||
|
|
||||||
--- Item size
|
--- Item size
|
||||||
-- @tfield vector3 node_size
|
-- @tfield vector3 node_size
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ function BaseComponent.get_node(self, node_or_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not node then
|
if not node then
|
||||||
assert(node, "No component with name: " .. template_name .. node_or_name)
|
assert(node, "No component with name: " .. (template_name or "") .. (node_or_name or ""))
|
||||||
end
|
end
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
@ -87,6 +87,8 @@ M.REVERSE_PIVOTS = {
|
|||||||
M.LAYOUT_MODE = {
|
M.LAYOUT_MODE = {
|
||||||
STRETCH_X = "stretch_x",
|
STRETCH_X = "stretch_x",
|
||||||
STRETCH_Y = "stretch_y",
|
STRETCH_Y = "stretch_y",
|
||||||
|
ZOOM_MIN = "zoom_min",
|
||||||
|
ZOOM_MAX = "zoom_max",
|
||||||
FIT = gui.ADJUST_FIT,
|
FIT = gui.ADJUST_FIT,
|
||||||
STRETCH = gui.ADJUST_STRETCH,
|
STRETCH = gui.ADJUST_STRETCH,
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ 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._inited = false
|
self._inited = false
|
||||||
|
self._is_stretch_position = nil
|
||||||
|
|
||||||
self.gui_size = vmath.vector3(gui.get_width(), gui.get_height(), 0)
|
self.gui_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
|
||||||
@ -81,11 +82,14 @@ function Layout:on_window_resized()
|
|||||||
new_size.x = math.min(new_size.x, self._max_size.x)
|
new_size.x = math.min(new_size.x, self._max_size.x)
|
||||||
new_size.y = math.min(new_size.y, self._max_size.y)
|
new_size.y = math.min(new_size.y, self._max_size.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
gui.set_size(self.node, new_size)
|
gui.set_size(self.node, new_size)
|
||||||
|
|
||||||
self.position.x = self.origin_position.x + self.origin_position.x * (1 - x_koef) * self.pivot.x * 2
|
self.position.x = self.origin_position.x
|
||||||
self.position.y = self.origin_position.y + self.origin_position.y * (1 - y_koef) * self.pivot.y * 2
|
self.position.y = self.origin_position.y
|
||||||
|
if self._is_stretch_position then
|
||||||
|
self.position.x = self.position.x + self.origin_position.x * (1 - x_koef) * (self.pivot.x * 2)
|
||||||
|
self.position.y = self.position.y + self.origin_position.y * (1 - y_koef) * (self.pivot.y * 2)
|
||||||
|
end
|
||||||
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)
|
||||||
@ -110,6 +114,14 @@ function Layout:set_origin_position(new_origin_position)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--@tparam boolean state
|
||||||
|
function Layout:set_stretch_position(state)
|
||||||
|
self._is_stretch_position = state
|
||||||
|
self:on_window_resized()
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Layout:set_origin_size(new_origin_size)
|
function Layout:set_origin_size(new_origin_size)
|
||||||
self.origin_size = new_origin_size or self.origin_size
|
self.origin_size = new_origin_size or self.origin_size
|
||||||
self:on_window_resized()
|
self:on_window_resized()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user