mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Add more annotations, update grid_page example
This commit is contained in:
parent
14a4e4365e
commit
897d401142
@ -267,6 +267,7 @@ end
|
|||||||
-- It will change content gui node size
|
-- It will change content gui node size
|
||||||
-- @tparam Scroll self
|
-- @tparam Scroll self
|
||||||
-- @tparam vector3 size The new size for content node
|
-- @tparam vector3 size The new size for content node
|
||||||
|
-- @tparam vector3 offset Offset value to set, where content is starts
|
||||||
-- @treturn druid.scroll Current scroll instance
|
-- @treturn druid.scroll Current scroll instance
|
||||||
function Scroll.set_size(self, size, offset)
|
function Scroll.set_size(self, size, offset)
|
||||||
if offset then
|
if offset then
|
||||||
@ -361,6 +362,10 @@ function Scroll.set_vertical_scroll(self, state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check node if it visible now on scroll
|
||||||
|
-- @tparam Scroll self
|
||||||
|
-- @tparma node node The node to check
|
||||||
|
-- @treturn boolean True, if node in visible scroll area
|
||||||
function Scroll.is_node_in_view(self, node)
|
function Scroll.is_node_in_view(self, node)
|
||||||
local node_border = helper.get_border(node, gui.get_position(node))
|
local node_border = helper.get_border(node, gui.get_position(node))
|
||||||
local view_border = helper.get_border(self.view_node, -self.position)
|
local view_border = helper.get_border(self.view_node, -self.position)
|
||||||
|
@ -318,7 +318,9 @@ function StaticGrid.clear(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- return vector where content borders starts
|
--- Return StaticGrid offset, where StaticGrid content starts.
|
||||||
|
-- @tparam StaticGrid self The StaticGrid instance
|
||||||
|
-- @treturn vector3 The StaticGrid offset
|
||||||
function StaticGrid:get_offset()
|
function StaticGrid:get_offset()
|
||||||
local borders = self:get_borders()
|
local borders = self:get_borders()
|
||||||
local size = self:get_size()
|
local size = self:get_size()
|
||||||
|
@ -224,6 +224,21 @@ function DynamicGrid.get_size(self, border)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return DynamicGrid offset, where DynamicGrid content starts.
|
||||||
|
-- @tparam DynamicGrid self The DynamicGrid instance
|
||||||
|
-- @treturn vector3 The DynamicGrid offset
|
||||||
|
function DynamicGrid.get_offset(self)
|
||||||
|
local size = self:get_size()
|
||||||
|
local borders = self:get_borders()
|
||||||
|
local offset = vmath.vector3(
|
||||||
|
(borders.z + borders.x)/2 + size.x * self.pivot.x,
|
||||||
|
(borders.y + borders.w)/2 + size.y * self.pivot.y,
|
||||||
|
0)
|
||||||
|
|
||||||
|
return offset
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return grid content borders
|
--- Return grid content borders
|
||||||
-- @tparam DynamicGrid self
|
-- @tparam DynamicGrid self
|
||||||
-- @treturn vector3 The grid content borders
|
-- @treturn vector3 The grid content borders
|
||||||
@ -391,24 +406,12 @@ function DynamicGrid._get_next_node_pos(self, origin_node_index, new_node, place
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function DynamicGrid._get_node_size(self, node)
|
function DynamicGrid._get_node_size(self, node)
|
||||||
return vmath.mul_per_elem(gui.get_size(node), gui.get_scale(node))
|
return vmath.mul_per_elem(gui.get_size(node), gui.get_scale(node))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function DynamicGrid:get_offset()
|
|
||||||
-- return vector where content borders starts
|
|
||||||
local size = self:get_size()
|
|
||||||
local borders = self:get_borders()
|
|
||||||
local offset = vmath.vector3(
|
|
||||||
(borders.z + borders.x)/2 + size.x * self.pivot.x,
|
|
||||||
(borders.y + borders.w)/2 + size.y * self.pivot.y,
|
|
||||||
0)
|
|
||||||
|
|
||||||
return offset
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Return side vector to correct node shifting
|
--- Return side vector to correct node shifting
|
||||||
function DynamicGrid._get_side_vector(self, side, is_forward)
|
function DynamicGrid._get_side_vector(self, side, is_forward)
|
||||||
if side == const.SIDE.X then
|
if side == const.SIDE.X then
|
||||||
|
@ -183,9 +183,11 @@ function M.is_web()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Distance from node to size border
|
--- Distance from node position to his borders
|
||||||
-- @function helper.get_border
|
-- @function helper.get_border
|
||||||
-- @return vector4 (left, top, right, down)
|
-- @tparam node node The gui node to check
|
||||||
|
-- @tparam vector3 offset The offset to add to result
|
||||||
|
-- @return vector4 Vector with distance to node border: (left, top, right, down)
|
||||||
function M.get_border(node, offset)
|
function M.get_border(node, offset)
|
||||||
local pivot = gui.get_pivot(node)
|
local pivot = gui.get_pivot(node)
|
||||||
local pivot_offset = M.get_pivot_offset(pivot)
|
local pivot_offset = M.get_pivot_offset(pivot)
|
||||||
|
@ -10614,9 +10614,9 @@ nodes {
|
|||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
color {
|
color {
|
||||||
x: 0.6
|
x: 1.0
|
||||||
y: 0.3019608
|
y: 1.0
|
||||||
z: 0.4
|
z: 1.0
|
||||||
w: 1.0
|
w: 1.0
|
||||||
}
|
}
|
||||||
type: TYPE_BOX
|
type: TYPE_BOX
|
||||||
|
@ -91,6 +91,7 @@ end
|
|||||||
|
|
||||||
local function add_node_dynamic(self, index, is_shift_left)
|
local function add_node_dynamic(self, index, is_shift_left)
|
||||||
local node = gui.clone(self.prefab_dynamic)
|
local node = gui.clone(self.prefab_dynamic)
|
||||||
|
gui.set_color(node, vmath.vector4(math.random() * 0.2 + 0.8))
|
||||||
gui.set_enabled(node, true)
|
gui.set_enabled(node, true)
|
||||||
gui.set_size(node, vmath.vector3(250, math.random(60, 150), 0))
|
gui.set_size(node, vmath.vector3(250, math.random(60, 150), 0))
|
||||||
self.grid_dynamic_grid:add(node, index, is_shift_left)
|
self.grid_dynamic_grid:add(node, index, is_shift_left)
|
||||||
@ -99,24 +100,51 @@ local function add_node_dynamic(self, index, is_shift_left)
|
|||||||
remove_dynamic_node(self, button)
|
remove_dynamic_node(self, button)
|
||||||
end)
|
end)
|
||||||
button.on_long_click:subscribe(function()
|
button.on_long_click:subscribe(function()
|
||||||
remove_dynamic_node(self, button, const.SHIFT.lEFT)
|
remove_dynamic_node(self, button, const.SHIFT.LEFT)
|
||||||
end)
|
end)
|
||||||
button:set_click_zone(self.grid_dynamic_scroll.view_node)
|
button:set_click_zone(self.grid_dynamic_scroll.view_node)
|
||||||
table.insert(self.dynamic_node_buttons, button)
|
table.insert(self.dynamic_node_buttons, button)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function remove_dynamic_hor_node(self, button, shift_policy)
|
||||||
|
gui.delete_node(button.node)
|
||||||
|
|
||||||
|
self.druid:remove(button)
|
||||||
|
local index = self.grid_dynamic_hor_grid:get_index_by_node(button.node)
|
||||||
|
self.grid_dynamic_hor_grid:remove(index, shift_policy)
|
||||||
|
for i = 1, #self.dynamic_node_hor_buttons do
|
||||||
|
if self.dynamic_node_hor_buttons[i] == button then
|
||||||
|
table.remove(self.dynamic_node_hor_buttons, i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function add_node_dynamic_hor(self, index)
|
local function add_node_dynamic_hor(self, index)
|
||||||
local node = gui.clone(self.prefab_hor_dynamic)
|
local node = gui.clone(self.prefab_hor_dynamic)
|
||||||
|
gui.set_color(node, vmath.vector4(math.random() * 0.2 + 0.8))
|
||||||
gui.set_enabled(node, true)
|
gui.set_enabled(node, true)
|
||||||
gui.set_size(node, vmath.vector3(80 + math.random(0, 80), 80, 0))
|
gui.set_size(node, vmath.vector3(80 + math.random(0, 80), 80, 0))
|
||||||
|
|
||||||
|
local button = self.druid:new_button(node, function(_, params, button)
|
||||||
|
remove_dynamic_hor_node(self, button)
|
||||||
|
end)
|
||||||
|
button.on_long_click:subscribe(function()
|
||||||
|
remove_dynamic_hor_node(self, button, const.SHIFT.LEFT)
|
||||||
|
end)
|
||||||
|
button:set_click_zone(self.grid_dynamic_hor_scroll.view_node)
|
||||||
|
|
||||||
self.grid_dynamic_hor_grid:add(node, index)
|
self.grid_dynamic_hor_grid:add(node, index)
|
||||||
|
table.insert(self.dynamic_node_hor_buttons, button)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function init_dynamic_grid(self)
|
local function init_dynamic_grid(self)
|
||||||
-- Vertical horizontal grid
|
-- Vertical horizontal grid
|
||||||
self.dynamic_node_buttons = {}
|
self.dynamic_node_buttons = {}
|
||||||
|
self.dynamic_node_hor_buttons = {}
|
||||||
|
|
||||||
self.prefab_dynamic = gui.get_node("grid_dynamic_prefab")
|
self.prefab_dynamic = gui.get_node("grid_dynamic_prefab")
|
||||||
gui.set_enabled(self.prefab_dynamic, false)
|
gui.set_enabled(self.prefab_dynamic, false)
|
||||||
@ -125,7 +153,7 @@ local function init_dynamic_grid(self)
|
|||||||
add_node_dynamic(self, i)
|
add_node_dynamic(self, i)
|
||||||
end
|
end
|
||||||
self.druid:new_button("button_add_start_dynamic/button", function()
|
self.druid:new_button("button_add_start_dynamic/button", function()
|
||||||
local start_index = (self.grid_dynamic_grid.first_index or 2) - 1
|
local start_index = self.grid_dynamic_grid.first_index or 1
|
||||||
add_node_dynamic(self, start_index)
|
add_node_dynamic(self, start_index)
|
||||||
end)
|
end)
|
||||||
self.druid:new_button("button_add_end_dynamic/button", function()
|
self.druid:new_button("button_add_end_dynamic/button", function()
|
||||||
@ -141,7 +169,8 @@ local function init_dynamic_grid(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.druid:new_button("button_add_start_dynamic_hor/button", function()
|
self.druid:new_button("button_add_start_dynamic_hor/button", function()
|
||||||
add_node_dynamic_hor(self, 1)
|
local start_index = self.grid_dynamic_hor_grid.first_index or 1
|
||||||
|
add_node_dynamic_hor(self, start_index)
|
||||||
end)
|
end)
|
||||||
self.druid:new_button("button_add_end_dynamic_hor/button", function()
|
self.druid:new_button("button_add_end_dynamic_hor/button", function()
|
||||||
add_node_dynamic_hor(self)
|
add_node_dynamic_hor(self)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user