mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Move component from system to root folder
This commit is contained in:
parent
544fd8d736
commit
e1edc8ae9b
@ -100,7 +100,7 @@ end
|
|||||||
Basic custom component template looks like this:
|
Basic custom component template looks like this:
|
||||||
```lua
|
```lua
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("amazing_component", { const.ON_INPUT })
|
local M = component.create("amazing_component", { const.ON_INPUT })
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ On each component recomended describe component schema in next way:
|
|||||||
```lua
|
```lua
|
||||||
-- Component module
|
-- Component module
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("new_component")
|
local M = component.create("new_component")
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
-- @module druid.back_handler
|
-- @module druid.back_handler
|
||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("back_handler", { const.ON_INPUT })
|
local M = component.create("back_handler", { const.ON_INPUT })
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("blocker", { const.ON_SWIPE })
|
local M = component.create("blocker", { const.ON_SWIPE })
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("button", { const.ON_INPUT })
|
local M = component.create("button", { const.ON_INPUT })
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
-- @module druid.checkbox
|
-- @module druid.checkbox
|
||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("checkbox")
|
local M = component.create("checkbox")
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
--- Checkboux group module
|
--- Checkboux group module
|
||||||
-- @module druid.checkbox_group
|
-- @module druid.checkbox_group
|
||||||
|
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("checkbox_group")
|
local M = component.create("checkbox_group")
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
-- @module druid.grid
|
-- @module druid.grid
|
||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("grid")
|
local M = component.create("grid")
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local settings = require("druid.system.settings")
|
local settings = require("druid.system.settings")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("locale", { const.ON_CHANGE_LANGUAGE })
|
local M = component.create("locale", { const.ON_CHANGE_LANGUAGE })
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("progress", { const.ON_UPDATE })
|
local M = component.create("progress", { const.ON_UPDATE })
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
--- Radio group module
|
--- Radio group module
|
||||||
-- @module druid.radio_group
|
-- @module druid.radio_group
|
||||||
|
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("radio_group")
|
local M = component.create("radio_group")
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("scroll", { const.ON_UPDATE, const.ON_SWIPE })
|
local M = component.create("scroll", { const.ON_UPDATE, const.ON_SWIPE })
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("slider", { const.ON_SWIPE })
|
local M = component.create("slider", { const.ON_SWIPE })
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("text")
|
local M = component.create("text")
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
local const = require("druid.const")
|
local const = require("druid.const")
|
||||||
local formats = require("druid.helper.formats")
|
local formats = require("druid.helper.formats")
|
||||||
local helper = require("druid.helper")
|
local helper = require("druid.helper")
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("timer", { const.ON_UPDATE })
|
local M = component.create("timer", { const.ON_UPDATE })
|
||||||
|
|
||||||
|
169
druid/component.lua
Normal file
169
druid/component.lua
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
--- Basic class for all Druid components.
|
||||||
|
-- To create you component, use `component.create`
|
||||||
|
-- @module component
|
||||||
|
|
||||||
|
local const = require("druid.const")
|
||||||
|
local class = require("druid.system.middleclass")
|
||||||
|
|
||||||
|
-- @classmod Component
|
||||||
|
local Component = class("druid.component")
|
||||||
|
|
||||||
|
|
||||||
|
--- Setup component context and his style table
|
||||||
|
-- @function component:setup_component
|
||||||
|
-- @tparam context table Druid context. Usually it is self of script
|
||||||
|
-- @tparam style table Druid style module
|
||||||
|
-- @treturn Component Component itself
|
||||||
|
function Component.setup_component(self, context, style)
|
||||||
|
self._meta = {
|
||||||
|
template = nil,
|
||||||
|
context = nil,
|
||||||
|
nodes = nil,
|
||||||
|
style = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
self:set_context(context)
|
||||||
|
self:set_style(style)
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get current component style table
|
||||||
|
-- @function component:get_style
|
||||||
|
-- @treturn table Component style table
|
||||||
|
function Component.get_style(self)
|
||||||
|
if not self._meta.style then
|
||||||
|
return const.EMPTY_TABLE
|
||||||
|
end
|
||||||
|
|
||||||
|
return self._meta.style[self._component.name] or const.EMPTY_TABLE
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Set current component style table
|
||||||
|
-- @function component:set_style
|
||||||
|
-- @tparam table style Druid style module
|
||||||
|
function Component.set_style(self, druid_style)
|
||||||
|
self._meta.style = druid_style
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get current component template name
|
||||||
|
-- @function component:get_template
|
||||||
|
-- @treturn string Component template name
|
||||||
|
function Component.get_template(self)
|
||||||
|
return self._meta.template
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Set current component template name
|
||||||
|
-- @function component:set_template
|
||||||
|
-- @tparam string template Component template name
|
||||||
|
function Component.set_template(self, template)
|
||||||
|
self._meta.template = template
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get current component nodes
|
||||||
|
-- @function component:get_nodes
|
||||||
|
-- @treturn table Component nodes table
|
||||||
|
function Component.get_nodes(self)
|
||||||
|
return self._meta.nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Set current component nodes
|
||||||
|
-- @function component:set_nodes
|
||||||
|
-- @tparam table nodes Component nodes table
|
||||||
|
function Component.set_nodes(self, nodes)
|
||||||
|
self._meta.nodes = nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get current component context
|
||||||
|
-- @function component:get_context
|
||||||
|
-- @treturn table Component context
|
||||||
|
function Component.get_context(self, context)
|
||||||
|
return self._meta.context
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Set current component context
|
||||||
|
-- @function component:set_context
|
||||||
|
-- @tparam table context Druid context. Usually it is self of script
|
||||||
|
function Component.set_context(self, context)
|
||||||
|
self._meta.context = context
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get current component interests
|
||||||
|
-- @function component:get_interests
|
||||||
|
-- @treturn table List of component interests
|
||||||
|
function Component.get_interests(self)
|
||||||
|
return self._component.interest
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- TODO: Определиться с get_node и node
|
||||||
|
-- get_node - берет ноду по ноде или строке
|
||||||
|
-- node - может брать ноду у компонента по схеме (если есть
|
||||||
|
-- template или таблица нод после gui.clone_tree)
|
||||||
|
function Component.get_node(self, node_or_name)
|
||||||
|
local template_name = self:get_template() or const.EMPTY_STRING
|
||||||
|
local nodes = self:get_nodes()
|
||||||
|
|
||||||
|
if nodes then
|
||||||
|
return nodes[template_name .. node_or_name]
|
||||||
|
else
|
||||||
|
if type(node_or_name) == const.STRING then
|
||||||
|
return gui.get_node(template_name .. node_or_name)
|
||||||
|
else
|
||||||
|
return node_or_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Return druid with context of calling component.
|
||||||
|
-- Use it to create component inside of other components.
|
||||||
|
-- @function component:get_druid
|
||||||
|
-- @treturn Druid Druid instance with component context
|
||||||
|
function Component.get_druid(self)
|
||||||
|
local context = { _context = self }
|
||||||
|
return setmetatable(context, { __index = self:get_context().druid })
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Basic constructor of component. It will call automaticaly
|
||||||
|
-- by `Component.static.create`
|
||||||
|
-- @function component:initialize
|
||||||
|
-- @tparam string name Component name
|
||||||
|
-- @tparam table interest List of component's interest
|
||||||
|
-- @local
|
||||||
|
function Component.initialize(self, name, interest)
|
||||||
|
self._component = {
|
||||||
|
name = name,
|
||||||
|
interest = interest
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Create new component. It will inheritance from basic
|
||||||
|
-- druid component.
|
||||||
|
-- @function Component.create
|
||||||
|
-- @tparam string name Component name
|
||||||
|
-- @tparam table interest List of component's interest
|
||||||
|
function Component.static.create(name, interest)
|
||||||
|
-- Yea, inheritance here
|
||||||
|
local new_class = class(name, Component)
|
||||||
|
|
||||||
|
new_class.initialize = function(self)
|
||||||
|
Component.initialize(self, name, interest)
|
||||||
|
end
|
||||||
|
|
||||||
|
return new_class
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return Component
|
@ -1,7 +1,7 @@
|
|||||||
--- Component for rich progress component
|
--- Component for rich progress component
|
||||||
-- @module druid.progress_rich
|
-- @module druid.progress_rich
|
||||||
|
|
||||||
local component = require("druid.system.component")
|
local component = require("druid.component")
|
||||||
|
|
||||||
local M = component.create("progress_rich")
|
local M = component.create("progress_rich")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user