mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
Merge branch 'develop' into feature/77-grid-update
# Conflicts: # druid/helper.lua # druid/system/druid_instance.lua
This commit is contained in:
commit
63186823e9
@ -19,7 +19,6 @@
|
|||||||
-- @tfield vector3 anchor Item anchor
|
-- @tfield vector3 anchor Item anchor
|
||||||
-- @tfield vector3 node_size Item size
|
-- @tfield vector3 node_size Item size
|
||||||
-- @tfield vector4 border The size of item content
|
-- @tfield vector4 border The size of item content
|
||||||
-- @tfield vector3 border_offer The border offset for correct anchor calculations
|
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local Event = require("druid.event")
|
local Event = require("druid.event")
|
||||||
@ -39,11 +38,10 @@ function DynamicGrid:init(parent, side)
|
|||||||
|
|
||||||
self.offset = vmath.vector3(0)
|
self.offset = vmath.vector3(0)
|
||||||
|
|
||||||
local pivot = helper.get_pivot_offset(gui.get_pivot(self.parent))
|
self.pivot = helper.get_pivot_offset(gui.get_pivot(self.parent))
|
||||||
self.anchor = vmath.vector3(0.5 + pivot.x, 0.5 - pivot.y, 0)
|
self.anchor = vmath.vector3(0.5 + self.pivot.x, 0.5 - self.pivot.y, 0)
|
||||||
|
|
||||||
self.border = vmath.vector4(0) -- Current grid content size
|
self.border = vmath.vector4(0) -- Current grid content size
|
||||||
self.border_offset = vmath.vector3(0) -- Content offset for match the grid anchoring
|
|
||||||
|
|
||||||
self.on_add_item = Event()
|
self.on_add_item = Event()
|
||||||
self.on_remove_item = Event()
|
self.on_remove_item = Event()
|
||||||
@ -68,8 +66,12 @@ function DynamicGrid:get_pos(index, node)
|
|||||||
|
|
||||||
if not prev_node and not next_node then
|
if not prev_node and not next_node then
|
||||||
-- TODO: assert no elements in grid now
|
-- TODO: assert no elements in grid now
|
||||||
-- should be center of current scroll
|
local size = self:_get_node_size(node)
|
||||||
return self.center_pos -- first element in grid
|
local pivot = const.PIVOTS[gui.get_pivot(node)]
|
||||||
|
return vmath.vector3(
|
||||||
|
size.x * pivot.x + size.x * self.pivot.x,
|
||||||
|
size.y * pivot.y - size.y * self.pivot.y,
|
||||||
|
0)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- For now it works only by vertical
|
-- For now it works only by vertical
|
||||||
@ -83,23 +85,6 @@ function DynamicGrid:get_pos(index, node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Return index for grid pos
|
|
||||||
-- @function dynamic_grid:get_index
|
|
||||||
-- @tparam vector3 pos The node position in the grid
|
|
||||||
-- @treturn number The node index
|
|
||||||
function DynamicGrid:get_index(pos)
|
|
||||||
local col = (pos.x + self.border_offset.x) / (self.node_size.x + self.offset.x) + 1
|
|
||||||
local row = -(pos.y + self.border_offset.y) / (self.node_size.y + self.offset.y)
|
|
||||||
|
|
||||||
col = helper.round(col)
|
|
||||||
row = helper.round(row)
|
|
||||||
|
|
||||||
local index = col + row
|
|
||||||
return math.ceil(index)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function DynamicGrid:on_layout_change()
|
function DynamicGrid:on_layout_change()
|
||||||
self:_update_pos(true)
|
self:_update_pos(true)
|
||||||
end
|
end
|
||||||
@ -140,10 +125,6 @@ function DynamicGrid:add(item, index)
|
|||||||
self:_add_node(item, index)
|
self:_add_node(item, index)
|
||||||
|
|
||||||
self:_update_borders()
|
self:_update_borders()
|
||||||
-- for i, _ in pairs(self.nodes) do
|
|
||||||
-- self:_update_border_offset(self:get_pos(i))
|
|
||||||
-- end
|
|
||||||
|
|
||||||
self:_update_pos()
|
self:_update_pos()
|
||||||
self:_update_indexes()
|
self:_update_indexes()
|
||||||
|
|
||||||
@ -168,11 +149,6 @@ function DynamicGrid:remove(index, is_shift_nodes)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self:_update_borders()
|
self:_update_borders()
|
||||||
-- self:_update_border_offset(self:get_pos(1))
|
|
||||||
-- for i, _ in pairs(self.nodes) do
|
|
||||||
-- self:_update_border_offset(self:get_pos(i))
|
|
||||||
-- end
|
|
||||||
|
|
||||||
self:_update_pos()
|
self:_update_pos()
|
||||||
self:_update_indexes()
|
self:_update_indexes()
|
||||||
|
|
||||||
@ -227,10 +203,8 @@ end
|
|||||||
-- If you want to delete GUI nodes, use dynamic_grid.nodes array before grid:clear
|
-- If you want to delete GUI nodes, use dynamic_grid.nodes array before grid:clear
|
||||||
-- @function dynamic_grid:clear
|
-- @function dynamic_grid:clear
|
||||||
function DynamicGrid:clear()
|
function DynamicGrid:clear()
|
||||||
self:_update_borders()
|
|
||||||
-- self:_update_border_offset(self:get_pos(1))
|
|
||||||
|
|
||||||
self.nodes = {}
|
self.nodes = {}
|
||||||
|
self:_update_borders()
|
||||||
self:_update_indexes()
|
self:_update_indexes()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -265,10 +239,10 @@ function DynamicGrid:_update_borders()
|
|||||||
local size = node.size
|
local size = node.size
|
||||||
local pivot = node.pivot
|
local pivot = node.pivot
|
||||||
|
|
||||||
local left = pos.x - size.x/2 - (size.x * pivot.x) + self.border_offset.x
|
local left = pos.x - size.x/2 - (size.x * pivot.x)
|
||||||
local right = pos.x + size.x/2 - (size.x * pivot.x) + self.border_offset.x
|
local right = pos.x + size.x/2 - (size.x * pivot.x)
|
||||||
local top = pos.y + size.y/2 - (size.y * pivot.y) + self.border_offset.y
|
local top = pos.y + size.y/2 - (size.y * pivot.y)
|
||||||
local bottom = pos.y - size.y/2 - (size.y * pivot.y) + self.border_offset.y
|
local bottom = pos.y - size.y/2 - (size.y * pivot.y)
|
||||||
|
|
||||||
border.x = math.min(border.x, left)
|
border.x = math.min(border.x, left)
|
||||||
border.y = math.max(border.y, top)
|
border.y = math.max(border.y, top)
|
||||||
@ -277,23 +251,6 @@ function DynamicGrid:_update_borders()
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.border = border
|
self.border = border
|
||||||
self.border_offset = vmath.vector3(
|
|
||||||
(border.x + (border.z - border.x) * self.anchor.x),
|
|
||||||
(border.y + (border.w - border.y) * self.anchor.y),
|
|
||||||
0
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function DynamicGrid:_update_border_offset(pos)
|
|
||||||
local border = self.border
|
|
||||||
self:_update_border(pos, border)
|
|
||||||
|
|
||||||
self.border_offset = vmath.vector3(
|
|
||||||
(border.x + (border.z - border.x) * self.anchor.x),
|
|
||||||
(border.y + (border.w - border.y) * self.anchor.y),
|
|
||||||
0
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -326,7 +283,7 @@ function DynamicGrid:_get_next_node_pos(origin_node_index, new_node, place_side)
|
|||||||
)
|
)
|
||||||
|
|
||||||
local node_center = vmath.vector3(
|
local node_center = vmath.vector3(
|
||||||
pos.x + size.x * anchor.x,
|
pos.x - size.x * anchor.x,
|
||||||
pos.y - size.y * anchor.y,
|
pos.y - size.y * anchor.y,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
|
@ -203,4 +203,13 @@ function M.deprecated(message)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Show message to require extended component
|
||||||
|
function M.extended_component(component_name)
|
||||||
|
print(string.format("[Druid]: The component %s is extended component. You have to register it via druid.register to use it", component_name))
|
||||||
|
print("[Druid]: Use next code:")
|
||||||
|
print(string.format('local %s = require("druid.extended.%s")', component_name, component_name))
|
||||||
|
print(string.format('druid.register("%s", %s)', component_name, component_name))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -20,30 +20,30 @@
|
|||||||
-- @see druid.drag
|
-- @see druid.drag
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
|
local helper = require("druid.helper")
|
||||||
local druid_input = require("druid.helper.druid_input")
|
local druid_input = require("druid.helper.druid_input")
|
||||||
local settings = require("druid.system.settings")
|
local settings = require("druid.system.settings")
|
||||||
local class = require("druid.system.middleclass")
|
local class = require("druid.system.middleclass")
|
||||||
local helper = require("druid.helper")
|
|
||||||
|
|
||||||
local button = require("druid.base.button")
|
|
||||||
local blocker = require("druid.base.blocker")
|
|
||||||
local back_handler = require("druid.base.back_handler")
|
local back_handler = require("druid.base.back_handler")
|
||||||
|
local blocker = require("druid.base.blocker")
|
||||||
|
local button = require("druid.base.button")
|
||||||
|
local drag = require("druid.base.drag")
|
||||||
local hover = require("druid.base.hover")
|
local hover = require("druid.base.hover")
|
||||||
local text = require("druid.base.text")
|
|
||||||
local lang_text = require("druid.base.lang_text")
|
local lang_text = require("druid.base.lang_text")
|
||||||
local timer = require("druid.base.timer")
|
|
||||||
local progress = require("druid.base.progress")
|
|
||||||
local static_grid = require("druid.base.static_grid")
|
local static_grid = require("druid.base.static_grid")
|
||||||
local dynamic_grid = require("druid.base.dynamic_grid")
|
local dynamic_grid = require("druid.base.dynamic_grid")
|
||||||
local scroll = require("druid.base.scroll")
|
local scroll = require("druid.base.scroll")
|
||||||
local slider = require("druid.base.slider")
|
|
||||||
local checkbox = require("druid.base.checkbox")
|
|
||||||
local checkbox_group = require("druid.base.checkbox_group")
|
|
||||||
local radio_group = require("druid.base.radio_group")
|
|
||||||
local input = require("druid.base.input")
|
|
||||||
local swipe = require("druid.base.swipe")
|
local swipe = require("druid.base.swipe")
|
||||||
local drag = require("druid.base.drag")
|
local text = require("druid.base.text")
|
||||||
-- local infinity_scroll = require("druid.base.infinity_scroll")
|
|
||||||
|
local checkbox = require("druid.extended.checkbox")
|
||||||
|
local checkbox_group = require("druid.extended.checkbox_group")
|
||||||
|
local input = require("druid.extended.input")
|
||||||
|
local progress = require("druid.extended.progress")
|
||||||
|
local radio_group = require("druid.extended.radio_group")
|
||||||
|
local slider = require("druid.extended.slider")
|
||||||
|
local timer = require("druid.extended.timer")
|
||||||
|
|
||||||
-- @classmod Druid
|
-- @classmod Druid
|
||||||
local Druid = class("druid.druid_instance")
|
local Druid = class("druid.druid_instance")
|
||||||
@ -387,24 +387,6 @@ function Druid.new_lang_text(self, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Create timer basic component
|
|
||||||
-- @function druid:new_timer
|
|
||||||
-- @tparam args ... timer init args
|
|
||||||
-- @treturn Component timer component
|
|
||||||
function Druid.new_timer(self, ...)
|
|
||||||
return Druid.create(self, timer, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Create progress basic component
|
|
||||||
-- @function druid:new_progress
|
|
||||||
-- @tparam args ... progress init args
|
|
||||||
-- @treturn Component progress component
|
|
||||||
function Druid.new_progress(self, ...)
|
|
||||||
return Druid.create(self, progress, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Create grid basic component
|
--- Create grid basic component
|
||||||
-- @function druid:new_grid
|
-- @function druid:new_grid
|
||||||
-- @tparam args ... grid init args
|
-- @tparam args ... grid init args
|
||||||
@ -443,51 +425,6 @@ function Druid.new_scroll(self, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Create slider basic component
|
|
||||||
-- @function druid:new_slider
|
|
||||||
-- @tparam args ... slider init args
|
|
||||||
-- @treturn Component slider component
|
|
||||||
function Druid.new_slider(self, ...)
|
|
||||||
return Druid.create(self, slider, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Create checkbox basic component
|
|
||||||
-- @function druid:new_checkbox
|
|
||||||
-- @tparam args ... checkbox init args
|
|
||||||
-- @treturn Component checkbox component
|
|
||||||
function Druid.new_checkbox(self, ...)
|
|
||||||
return Druid.create(self, checkbox, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Create input basic component
|
|
||||||
-- @function druid:new_input
|
|
||||||
-- @tparam args ... input init args
|
|
||||||
-- @treturn Component input component
|
|
||||||
function Druid.new_input(self, ...)
|
|
||||||
return Druid.create(self, input, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Create checkbox_group basic component
|
|
||||||
-- @function druid:new_checkbox_group
|
|
||||||
-- @tparam args ... checkbox_group init args
|
|
||||||
-- @treturn Component checkbox_group component
|
|
||||||
function Druid.new_checkbox_group(self, ...)
|
|
||||||
return Druid.create(self, checkbox_group, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Create radio_group basic component
|
|
||||||
-- @function druid:new_radio_group
|
|
||||||
-- @tparam args ... radio_group init args
|
|
||||||
-- @treturn Component radio_group component
|
|
||||||
function Druid.new_radio_group(self, ...)
|
|
||||||
return Druid.create(self, radio_group, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- Create swipe basic component
|
--- Create swipe basic component
|
||||||
-- @function druid:new_swipe
|
-- @function druid:new_swipe
|
||||||
-- @tparam args ... swipe init args
|
-- @tparam args ... swipe init args
|
||||||
@ -506,4 +443,74 @@ function Druid.new_drag(self, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create slider basic component
|
||||||
|
-- @function druid:new_slider
|
||||||
|
-- @tparam args ... slider init args
|
||||||
|
-- @treturn Component slider component
|
||||||
|
function Druid.new_slider(self, ...)
|
||||||
|
-- return helper.extended_component("slider")
|
||||||
|
return Druid.create(self, slider, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create checkbox basic component
|
||||||
|
-- @function druid:new_checkbox
|
||||||
|
-- @tparam args ... checkbox init args
|
||||||
|
-- @treturn Component checkbox component
|
||||||
|
function Druid.new_checkbox(self, ...)
|
||||||
|
-- return helper.extended_component("checkbox")
|
||||||
|
return Druid.create(self, checkbox, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create input basic component
|
||||||
|
-- @function druid:new_input
|
||||||
|
-- @tparam args ... input init args
|
||||||
|
-- @treturn Component input component
|
||||||
|
function Druid.new_input(self, ...)
|
||||||
|
-- return helper.extended_component("input")
|
||||||
|
return Druid.create(self, input, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create checkbox_group basic component
|
||||||
|
-- @function druid:new_checkbox_group
|
||||||
|
-- @tparam args ... checkbox_group init args
|
||||||
|
-- @treturn Component checkbox_group component
|
||||||
|
function Druid.new_checkbox_group(self, ...)
|
||||||
|
-- return helper.extended_component("checkbox_group")
|
||||||
|
return Druid.create(self, checkbox_group, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create radio_group basic component
|
||||||
|
-- @function druid:new_radio_group
|
||||||
|
-- @tparam args ... radio_group init args
|
||||||
|
-- @treturn Component radio_group component
|
||||||
|
function Druid.new_radio_group(self, ...)
|
||||||
|
-- return helper.extended_component("radio_group")
|
||||||
|
return Druid.create(self, radio_group, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create timer basic component
|
||||||
|
-- @function druid:new_timer
|
||||||
|
-- @tparam args ... timer init args
|
||||||
|
-- @treturn Component timer component
|
||||||
|
function Druid.new_timer(self, ...)
|
||||||
|
-- return helper.extended_component("timer")
|
||||||
|
return Druid.create(self, timer, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create progress basic component
|
||||||
|
-- @function druid:new_progress
|
||||||
|
-- @tparam args ... progress init args
|
||||||
|
-- @treturn Component progress component
|
||||||
|
function Druid.new_progress(self, ...)
|
||||||
|
-- return helper.extended_component("progress")
|
||||||
|
return Druid.create(self, progress, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return Druid
|
return Druid
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
use_latest_bob=true
|
use_latest_bob=false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user