All basic components declared with explicit way

This commit is contained in:
Insality
2020-02-05 02:43:37 +03:00
parent ec2acceebe
commit 92098052e3
3 changed files with 223 additions and 66 deletions

View File

@@ -1,7 +1,12 @@
--- Druid UI Library.
-- Component based UI library to make your life easier.
-- Contains a lot of base components and give API
-- to create your own rich components.
-- Powerful Defold component based UI library. Use standart
-- components or make your own game-specific to make amazing
-- GUI in your games.
--
-- Contains the several basic components and examples
-- to how to do your custom complex components to
-- separate UI game logic to small files
--
-- @module druid
local const = require("druid.const")
@@ -13,47 +18,12 @@ local M = {}
local log = settings.log
--- Basic components
M.components = {
button = require("druid.base.button"),
blocker = require("druid.base.blocker"),
back_handler = require("druid.base.back_handler"),
text = require("druid.base.text"),
locale = require("druid.base.locale"),
timer = require("druid.base.timer"),
progress = require("druid.base.progress"),
grid = require("druid.base.grid"),
scroll = require("druid.base.scroll"),
slider = require("druid.base.slider"),
checkbox = require("druid.base.checkbox"),
checkbox_group = require("druid.base.checkbox_group"),
radio_group = require("druid.base.radio_group"),
-- TODO:
-- input - text input
-- infinity_scroll -- to handle big data scroll
progress_rich = require("druid.rich.progress_rich"),
-- TODO: Examples:
-- Slider menu like clash royale
}
local function register_basic_components()
for k, v in pairs(M.components) do
if not druid_instance["new_" .. k] then
M.register(k, v)
else
log("Basic component", k, "already registered")
end
end
end
--- Register external module
--- Register external druid component.
-- After register you can create the component with
-- druid_instance:new_{name}. For example `druid:new_button(...)`
-- @function druid:register
-- @tparam string name module name
-- @tparam table module lua table with module
-- @tparam table module lua table with component
function M.register(name, module)
-- TODO: Find better solution to creating elements?
-- Possibly: druid.new(druid.BUTTON, etc?)
@@ -66,23 +36,30 @@ function M.register(name, module)
end
--- Create Druid instance for creating components
-- @return instance with all ui components
--- Create Druid instance.
-- @function druid.new
-- @tparam table context Druid context. Usually it is self of script
-- @tparam[opt] table style Druid style module
-- @treturn druid_instance Druid instance
function M.new(context, style)
if register_basic_components then
register_basic_components()
register_basic_components = false
end
return druid_instance(context, style)
end
-- Set new default style.
-- @function druid.set_default_style
-- @tparam table style Druid style module
function M.set_default_style(style)
settings.default_style = style
end
-- Set text function.
-- Druid locale component will call this function
-- to get translated text. After set_text_funtion
-- all existing locale component will be updated
-- @function druid.set_text_function(callback)
-- @tparam function callback Get localized text function
function M.set_text_function(callback)
settings.get_text = callback or const.EMPTY_FUNCTION
-- TODO: Update all localized text
@@ -90,6 +67,11 @@ function M.set_text_function(callback)
end
-- Set sound function.
-- Component will call this function to
-- play sound by sound_id
-- @function druid.set_sound_function
-- @tparam function callback Sound play callback
function M.set_sound_function(callback)
settings.play_sound = callback or const.EMPTY_FUNCTION
end