More widgets, additional adjusts for text

This commit is contained in:
Insality
2024-11-20 01:42:12 +02:00
parent c35dfc7066
commit 37d7168bd6
15 changed files with 698 additions and 72 deletions

View File

@@ -74,7 +74,7 @@ end
--- Add hotkey for component callback
---@param keys string[]|hash[]|string|hash that have to be pressed before key pressed to activate
---@param callback_argument any|nil The argument to pass into the callback function
---@return Hotkey Current instance
---@return druid.hotkey Current instance
function M:add_hotkey(keys, callback_argument)
keys = keys or {}
if type(keys) == "string" then
@@ -86,7 +86,7 @@ function M:add_hotkey(keys, callback_argument)
for index = 1, #keys do
local key_hash = hash(keys[index])
if helper.contains(self.style.MODIFICATORS, key_hash) then
if #keys > 1 and helper.contains(self.style.MODIFICATORS, key_hash) then
table.insert(modificators, key_hash)
else
if not key then
@@ -114,6 +114,17 @@ function M:add_hotkey(keys, callback_argument)
end
function M:is_processing()
for index = 1, #self._hotkeys do
if self._hotkeys[index].is_processing then
return true
end
end
return false
end
function M:on_focus_gained()
for k, v in pairs(self._modificators) do
self._modificators[k] = false
@@ -122,32 +133,32 @@ end
function M:on_input(action_id, action)
if not action_id or #self._hotkeys == 0 then
if not action_id then
return false
end
if self._modificators[action_id] ~= nil then
if action.pressed then
self._modificators[action_id] = true
end
if action.released then
self._modificators[action_id] = false
end
if self._modificators[action_id] ~= nil and action.pressed then
self._modificators[action_id] = true
end
for index = 1, #self._hotkeys do
local hotkey = self._hotkeys[index]
if action_id == hotkey.key then
local is_relative_key = helper.contains(self.style.MODIFICATORS, action_id) or action_id == hotkey.key
if is_relative_key and (action_id == hotkey.key or not hotkey.key) then
local is_modificator_ok = true
local is_consume = not not (hotkey.key)
-- Check only required modificators pressed
for i = 1, #self.style.MODIFICATORS do
local mod = self.style.MODIFICATORS[i]
if helper.contains(hotkey.modificators, mod) and self._modificators[mod] == false then
is_modificator_ok = false
end
if not helper.contains(hotkey.modificators, mod) and self._modificators[mod] == true then
is_modificator_ok = false
if hotkey.key and #hotkey.modificators > 0 then
for i = 1, #self.style.MODIFICATORS do
local mod = self.style.MODIFICATORS[i]
if helper.contains(hotkey.modificators, mod) and self._modificators[mod] == false then
is_modificator_ok = false
end
if not helper.contains(hotkey.modificators, mod) and self._modificators[mod] == true then
is_modificator_ok = false
end
end
end
@@ -157,23 +168,27 @@ function M:on_input(action_id, action)
end
if not action.pressed and self._is_process_repeated and action.repeated and is_modificator_ok and hotkey.is_processing then
self.on_hotkey_released:trigger(self:get_context(), hotkey.callback_argument)
return true
return is_consume
end
if action.released and is_modificator_ok and hotkey.is_processing then
hotkey.is_processing = false
self.on_hotkey_released:trigger(self:get_context(), hotkey.callback_argument)
return true
hotkey.is_processing = false
return is_consume
end
end
end
if self._modificators[action_id] ~= nil and action.released then
self._modificators[action_id] = false
end
return false
end
--- If true, the callback will be triggered on action.repeated
---@param is_enabled_repeated bool The flag value
---@return Hotkey
---@return druid.hotkey
function M:set_repeat(is_enabled_repeated)
self._is_process_repeated = is_enabled_repeated
return self

View File

@@ -68,6 +68,22 @@ function M:update()
end
function M:get_entities()
return self.entities
end
function M:set_node_index(node, index)
for i = 1, #self.entities do
if self.entities[i] == node then
table.remove(self.entities, i)
table.insert(self.entities, index, node)
break
end
end
end
---@param margin_x number|nil
---@param margin_y number|nil
---@return druid.layout
@@ -444,15 +460,16 @@ function M:calculate_rows_data()
end
---Will reset z value to 0!
local TEMP_VECTOR = vmath.vector3(0, 0, 0)
---@param node node
---@param x number
---@param y number
---@return node
function M:set_node_position(node, x, y)
local position = gui.get_position(node)
position.x = x
position.y = y
gui.set_position(node, position)
TEMP_VECTOR.x = x
TEMP_VECTOR.y = y
gui.set_position(node, TEMP_VECTOR)
return node
end