mirror of
https://github.com/Insality/druid.git
synced 2025-06-28 19:07:44 +02:00
Merge pull request #59 from Insality/feature/41-remove-instances
Feature/41 remove instances
This commit is contained in:
commit
b1b06f9a17
@ -157,12 +157,10 @@ function M.get_all_pos(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Clear all items from the grid
|
--- Clear grid nodes array. GUI nodes will be not deleted!
|
||||||
|
-- If you want to delete GUI nodes, use grid.nodes array before grid:clear
|
||||||
-- @function grid:clear
|
-- @function grid:clear
|
||||||
function M.clear(self)
|
function M.clear(self)
|
||||||
for i = 1, #self.nodes do
|
|
||||||
gui.delete_node(self.nodes[i])
|
|
||||||
end
|
|
||||||
self.nodes = {}
|
self.nodes = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ function Component.increase_input_priority(self)
|
|||||||
self._meta.increased_input_priority = true
|
self._meta.increased_input_priority = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Reset input priority in current input stack
|
--- Reset input priority in current input stack
|
||||||
-- @function component:reset_input_priority
|
-- @function component:reset_input_priority
|
||||||
function Component.reset_input_priority(self)
|
function Component.reset_input_priority(self)
|
||||||
@ -133,21 +134,39 @@ end
|
|||||||
-- @treturn Druid Druid instance with component context
|
-- @treturn Druid Druid instance with component context
|
||||||
function Component.get_druid(self)
|
function Component.get_druid(self)
|
||||||
local context = { _context = self }
|
local context = { _context = self }
|
||||||
return setmetatable(context, { __index = self:get_context().druid })
|
return setmetatable(context, { __index = self._meta.druid })
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return true, if current component is child of another component
|
||||||
|
-- @function component:is_child_of
|
||||||
|
-- @treturn bool True, if current component is child of another
|
||||||
|
function Component.is_child_of(self, component)
|
||||||
|
return self:get_context() == component
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return component name
|
||||||
|
-- @function component:get_name
|
||||||
|
-- @treturn string The component name
|
||||||
|
function Component.get_name(self)
|
||||||
|
return self._component.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Setup component context and his style table
|
--- Setup component context and his style table
|
||||||
-- @function component:setup_component
|
-- @function component:setup_component
|
||||||
|
-- @tparam druid_instance table The parent druid instance
|
||||||
-- @tparam context table Druid context. Usually it is self of script
|
-- @tparam context table Druid context. Usually it is self of script
|
||||||
-- @tparam style table Druid style module
|
-- @tparam style table Druid style module
|
||||||
-- @treturn Component Component itself
|
-- @treturn Component Component itself
|
||||||
function Component.setup_component(self, context, style)
|
function Component.setup_component(self, druid_instance, context, style)
|
||||||
self._meta = {
|
self._meta = {
|
||||||
template = nil,
|
template = nil,
|
||||||
context = nil,
|
context = nil,
|
||||||
nodes = nil,
|
nodes = nil,
|
||||||
style = nil,
|
style = nil,
|
||||||
|
druid = druid_instance,
|
||||||
increased_input_priority = false
|
increased_input_priority = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ end
|
|||||||
-- Create the component itself
|
-- Create the component itself
|
||||||
local function create(self, instance_class)
|
local function create(self, instance_class)
|
||||||
local instance = instance_class()
|
local instance = instance_class()
|
||||||
instance:setup_component(self._context, self._style)
|
instance:setup_component(self, self._context, self._style)
|
||||||
|
|
||||||
table.insert(self.components[const.ALL], instance)
|
table.insert(self.components[const.ALL], instance)
|
||||||
|
|
||||||
@ -170,6 +170,14 @@ end
|
|||||||
function Druid.remove(self, component)
|
function Druid.remove(self, component)
|
||||||
local all_components = self.components[const.ALL]
|
local all_components = self.components[const.ALL]
|
||||||
|
|
||||||
|
-- Recursive remove all children of component
|
||||||
|
for i = 1, #all_components do
|
||||||
|
local inst = all_components[i]
|
||||||
|
if inst:is_child_of(component) then
|
||||||
|
self:remove(inst)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for i = #all_components, 1, -1 do
|
for i = #all_components, 1, -1 do
|
||||||
if all_components[i] == component then
|
if all_components[i] == component then
|
||||||
if component.on_remove then
|
if component.on_remove then
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
local sprite_style = require("druid.styles.sprites.style")
|
|
||||||
|
|
||||||
local M = {}
|
|
||||||
|
|
||||||
|
|
||||||
local function usual_callback()
|
|
||||||
print("Usual callback")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function long_tap_callback(self, params, button, hold_time)
|
|
||||||
print("Long tap callback", hold_time)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function hold_callback(self, params, button, hold_time)
|
|
||||||
print("On hold callback", hold_time)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function repeated_callback(self, params, button, click_in_row)
|
|
||||||
print("Repeated callback", click_in_row)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function double_tap_callback(self, params, button, click_in_row)
|
|
||||||
print("Double tap callback", click_in_row)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function setup_buttons(self)
|
|
||||||
self.druid:new_button("button_usual/button", usual_callback)
|
|
||||||
|
|
||||||
local custom_style = self.druid:new_button("button_custom_style/button", usual_callback)
|
|
||||||
custom_style:set_style(sprite_style)
|
|
||||||
|
|
||||||
local long_button = self.druid:new_button("button_long_tap/button", usual_callback)
|
|
||||||
long_button.on_hold_callback:subscribe(hold_callback)
|
|
||||||
long_button.on_long_click:subscribe(long_tap_callback)
|
|
||||||
self.druid:new_button("button_repeated_tap/button", usual_callback)
|
|
||||||
.on_repeated_click:subscribe(repeated_callback)
|
|
||||||
self.druid:new_button("button_double_tap/button", usual_callback)
|
|
||||||
.on_double_click:subscribe(double_tap_callback)
|
|
||||||
|
|
||||||
local button_space = self.druid:new_button("button_key_trigger/button", usual_callback)
|
|
||||||
button_space:set_key_trigger("key_space")
|
|
||||||
button_space.on_long_click:subscribe(long_tap_callback)
|
|
||||||
button_space.on_double_click:subscribe(double_tap_callback)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function M.setup_page(self)
|
|
||||||
setup_buttons(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
return M
|
|
Loading…
x
Reference in New Issue
Block a user