mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Update docs
This commit is contained in:
parent
6ed48772a3
commit
23ac068f51
@ -22,6 +22,7 @@
|
||||
"input": true,
|
||||
"media": true,
|
||||
"build": true,
|
||||
"docs": true,
|
||||
".github": true,
|
||||
".deployer_cache": true,
|
||||
"dist": true
|
||||
|
@ -161,7 +161,7 @@ function druid__blocker.init(self, node) end
|
||||
function druid__blocker.is_enabled(self) end
|
||||
|
||||
--- Set enabled blocker component state.
|
||||
--- Don't change node enabled state.
|
||||
--- Don't change node enabled state itself.
|
||||
---@param self druid.blocker @{Blocker}
|
||||
---@param state bool Enabled state
|
||||
function druid__blocker.set_enabled(self, state) end
|
||||
|
@ -10,6 +10,8 @@
|
||||
-- • Blocker inheritance @{BaseComponent}, you can use all of its methods in addition to those described here.
|
||||
--
|
||||
-- • Blocker initial enabled state is `gui.is_enabled(node, true)`
|
||||
--
|
||||
-- • The Blocker node should be enabled to capture the input
|
||||
-- @usage
|
||||
-- local node = gui.get_node("blocker_node")
|
||||
-- local blocker = self.druid:new_blocker(node)
|
||||
@ -33,7 +35,7 @@ local Blocker = component.create("blocker")
|
||||
-- @tparam node node Gui node
|
||||
function Blocker.init(self, node)
|
||||
self.node = self:get_node(node)
|
||||
self._is_enabled = gui.is_enabled(node, true)
|
||||
self._is_enabled = gui.is_enabled(self.node, true)
|
||||
end
|
||||
|
||||
|
||||
@ -53,6 +55,10 @@ function Blocker.on_input(self, action_id, action)
|
||||
return false
|
||||
end
|
||||
|
||||
if not gui.is_enabled(self.node, true) then
|
||||
return false
|
||||
end
|
||||
|
||||
if gui.pick_node(self.node, action.x, action.y) then
|
||||
return true
|
||||
end
|
||||
@ -63,7 +69,7 @@ end
|
||||
|
||||
--- Set enabled blocker component state.
|
||||
--
|
||||
-- Don't change node enabled state.
|
||||
-- Don't change node enabled state itself.
|
||||
-- @tparam Blocker self @{Blocker}
|
||||
-- @tparam bool state Enabled state
|
||||
function Blocker.set_enabled(self, state)
|
||||
|
@ -534,52 +534,6 @@ function M.tagged(words, tag)
|
||||
end
|
||||
|
||||
|
||||
--- Split a word into it's characters
|
||||
-- @param word The word to split
|
||||
-- @return The individual characters
|
||||
function M.characters(word)
|
||||
assert(word)
|
||||
|
||||
local parent = gui.get_parent(word.node)
|
||||
local font = gui.get_font(word.node)
|
||||
local layer = gui.get_layer(word.node)
|
||||
local pivot = gui.get_pivot(word.node)
|
||||
|
||||
local word_length = utf8.len(word.text)
|
||||
|
||||
-- exit early if word is a single character or empty
|
||||
if word_length <= 1 then
|
||||
local char = helper.deepcopy(word)
|
||||
char.node, char.metrics = create_node(char, parent, font)
|
||||
gui.set_pivot(char.node, pivot)
|
||||
gui.set_position(char.node, gui.get_position(word.node))
|
||||
gui.set_layer(char.node, layer)
|
||||
return { char }
|
||||
end
|
||||
|
||||
-- split word into characters
|
||||
local chars = {}
|
||||
local position = gui.get_position(word.node)
|
||||
local position_x = position.x
|
||||
|
||||
for i = 1, word_length do
|
||||
local char = helper.deepcopy(word)
|
||||
chars[#chars + 1] = char
|
||||
char.text = utf8.sub(word.text, i, i)
|
||||
char.node, char.metrics = create_node(char, parent, font)
|
||||
gui.set_layer(char.node, layer)
|
||||
gui.set_pivot(char.node, pivot)
|
||||
|
||||
local sub_metrics = get_text_metrics(word, font, utf8.sub(word.text, 1, i))
|
||||
position.x = position_x + sub_metrics.width - char.metrics.width
|
||||
char.position = vmath.vector3(position)
|
||||
gui.set_position(char.node, char.position)
|
||||
end
|
||||
|
||||
return chars
|
||||
end
|
||||
|
||||
|
||||
---Removes the gui nodes created by rich text
|
||||
function M.remove(words)
|
||||
assert(words)
|
||||
|
@ -3,10 +3,28 @@
|
||||
--- Druid Rich Text custom component.
|
||||
-- <b># Overview #</b>
|
||||
--
|
||||
-- Heavily inspired by https://github.com/britzl/defold-richtext.
|
||||
-- Heavily inspired by <a href="https://github.com/britzl/defold-richtext" target="_blank">https://github.com/britzl/defold-richtext</a>.
|
||||
--
|
||||
-- Uses the same syntax for tags, but currently have less tags support.
|
||||
--
|
||||
-- All Rich Text params are adjusted in GUI scene
|
||||
--
|
||||
-- The Rich Text template should have next scheme:
|
||||
--
|
||||
-- root
|
||||
--
|
||||
-- - text_prefab
|
||||
--
|
||||
-- - icon_prefab
|
||||
--
|
||||
-- <b># Rich Text Setup #</b>
|
||||
-- • Root node size - maximum width and height of the text
|
||||
-- • Root anchor - Aligment of the Rich Text inside root node size area
|
||||
-- • Text prefab - all text params for the text node
|
||||
-- • Text prefab anchor - Anchor for each text node (you should adjust this only if animate text)
|
||||
-- • Icon prefab - all node params for the icon node
|
||||
-- • Icon prefab anchor - Anchor for each icon node (you should adjust this only if animate icon)
|
||||
--
|
||||
-- <b># Notes #</b>
|
||||
--
|
||||
-- • Nested tags are supported
|
||||
|
@ -7,7 +7,7 @@
|
||||
-- Druid components or make your own game-specific components to make
|
||||
-- amazing GUI in your games.
|
||||
--
|
||||
-- To start using Druid, please refer to the Basic Usage section below.
|
||||
-- To start using Druid, please refer to the Usage section below.
|
||||
--
|
||||
-- <b># Notes #</b>
|
||||
--
|
||||
|
@ -1,9 +1,10 @@
|
||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||
|
||||
--- Druid Event module.
|
||||
--- Druid Event Module
|
||||
--
|
||||
-- Event is a simple class to handle callbacks. It's used in many Druid components.
|
||||
-- You can subscribe to event with `:subscribe` method and unsubscribe with `:unsubscribe`.
|
||||
-- The Event module provides a simple class for handling callbacks. It is used in many Druid components.
|
||||
--
|
||||
-- You can subscribe to an event using the `:subscribe` method and unsubscribe using the `:unsubscribe` method.
|
||||
-- @module DruidEvent
|
||||
-- @alias druid.event
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
-- Copyright (c) 2021 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||
|
||||
--- Helper module with various usefull GUI functions.
|
||||
-- @usage
|
||||
-- local helper = require("druid.helper")
|
||||
-- helper.centrate_nodes(0, node_1, node_2)
|
||||
-- @module Helper
|
||||
-- @alias druid.helper
|
||||
|
||||
|
@ -150,7 +150,41 @@ M["text"] = {
|
||||
|
||||
|
||||
M["hotkey"] = {
|
||||
MODIFICATORS = { "key_lshift", "key_rshift", "key_lctrl", "key_rctrl", "key_lalt", "key_ralt", "key_lsuper", "key_rsuper" }, -- Add key ids to mark it as modificator keys
|
||||
-- Add key ids to mark it as modificator keys
|
||||
MODIFICATORS = {
|
||||
"key_lshift",
|
||||
"key_rshift",
|
||||
"key_lctrl",
|
||||
"key_rctrl",
|
||||
"key_lalt",
|
||||
"key_ralt",
|
||||
"key_lsuper",
|
||||
"key_rsuper"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
M["rich_text"] = {
|
||||
COLORS = {
|
||||
white = "#FFFFFF",
|
||||
black = "#000000",
|
||||
red = "#FF0000",
|
||||
green = "#00FF00",
|
||||
blue = "#0000FF",
|
||||
yellow = "#FFFF00",
|
||||
magenta = "#FF00FF",
|
||||
cyan = "#00FFFF",
|
||||
gray = "#808080",
|
||||
dark_gray = "#404040",
|
||||
light_gray = "#C0C0C0",
|
||||
orange = "#FFA500",
|
||||
pink = "#FFC0CB",
|
||||
purple = "#800080",
|
||||
brown = "#A52A2A",
|
||||
olive = "#808000",
|
||||
teal = "#008080",
|
||||
navy = "#000080",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user