mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Update Rich Input with selection/arrows control. Add template and nodes to self:get_druid
This commit is contained in:
@@ -80,7 +80,6 @@ end
|
||||
-- @treturn druid.data_list Current DataList instance
|
||||
function DataList.set_data(self, data)
|
||||
self._data = data or {}
|
||||
self.scroll:set_size(self.grid:get_size_for(#self._data))
|
||||
self:_refresh()
|
||||
|
||||
return self
|
||||
@@ -102,7 +101,7 @@ end
|
||||
-- @tparam number shift_policy The constant from const.SHIFT.*
|
||||
-- @local
|
||||
function DataList.add(self, data, index, shift_policy)
|
||||
index = index or self._data_last_index + 1
|
||||
index = index or #self._data + 1
|
||||
shift_policy = shift_policy or const.SHIFT.RIGHT
|
||||
|
||||
helper.insert_with_shift(self._data, data, index, shift_policy)
|
||||
@@ -205,6 +204,7 @@ function DataList._add_at(self, index)
|
||||
|
||||
local node, instance = self._create_function(self:get_context(), self._data[index], index, self)
|
||||
self._data_visual[index] = {
|
||||
data = self._data[index],
|
||||
node = node,
|
||||
component = instance,
|
||||
}
|
||||
@@ -240,6 +240,8 @@ end
|
||||
-- @tparam DataList self @{DataList}
|
||||
-- @local
|
||||
function DataList._refresh(self)
|
||||
self.scroll:set_size(self.grid:get_size_for(#self._data))
|
||||
|
||||
local start_pos = -self.scroll.position
|
||||
local start_index = self.grid:get_index(start_pos)
|
||||
start_index = math.max(1, start_index)
|
||||
@@ -258,6 +260,10 @@ function DataList._refresh(self)
|
||||
for index, data in pairs(self._data_visual) do
|
||||
if index < start_index or index > end_index then
|
||||
self:_remove_at(index)
|
||||
elseif self._data[index] ~= data.data then
|
||||
-- TODO We want to find currently created data instances and move them to new positions
|
||||
-- Now it will re-create them
|
||||
self:_remove_at(index)
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -52,6 +52,7 @@
|
||||
|
||||
local Event = require("druid.event")
|
||||
local const = require("druid.const")
|
||||
local helper = require("druid.helper")
|
||||
local component = require("druid.component")
|
||||
local utf8_lua = require("druid.system.utf8")
|
||||
local utf8 = utf8 or utf8_lua
|
||||
@@ -90,7 +91,6 @@ end
|
||||
-- @tfield boolean IS_LONGTAP_ERASE Is long tap will erase current input data. Default: false
|
||||
-- @tfield string MASK_DEFAULT_CHAR Default character mask for password input. Default: *]
|
||||
-- @tfield boolean IS_UNSELECT_ON_RESELECT If true, call unselect on select selected input. Default: false
|
||||
-- @tfield boolean NO_CONSUME_INPUT_WHILE_SELECTED If true, will not consume input while input is selected. It's allow to interact with other components while input is selected (text input still captured). Default: false
|
||||
-- @tfield function on_select (self, button_node) Callback on input field selecting
|
||||
-- @tfield function on_unselect (self, button_node) Callback on input field unselecting
|
||||
-- @tfield function on_input_wrong (self, button_node) Callback on wrong user input
|
||||
@@ -101,7 +101,6 @@ function Input.on_style_change(self, style)
|
||||
self.style.IS_LONGTAP_ERASE = style.IS_LONGTAP_ERASE or false
|
||||
self.style.MASK_DEFAULT_CHAR = style.MASK_DEFAULT_CHAR or "*"
|
||||
self.style.IS_UNSELECT_ON_RESELECT = style.IS_UNSELECT_ON_RESELECT or false
|
||||
self.style.NO_CONSUME_INPUT_WHILE_SELECTED = style.NO_CONSUME_INPUT_WHILE_SELECTED or false
|
||||
|
||||
self.style.on_select = style.on_select or function(_, button_node) end
|
||||
self.style.on_unselect = style.on_unselect or function(_, button_node) end
|
||||
@@ -121,7 +120,7 @@ end
|
||||
-- @tparam node|Text text_node Text node what will be changed on user input. You can pass text component instead of text node name @{Text}
|
||||
-- @tparam number|nil keyboard_type Gui keyboard type for input field
|
||||
function Input.init(self, click_node, text_node, keyboard_type)
|
||||
self.druid = self:get_druid(self)
|
||||
self.druid = self:get_druid()
|
||||
|
||||
if type(text_node) == "table" then
|
||||
self.text = text_node
|
||||
@@ -139,6 +138,9 @@ function Input.init(self, click_node, text_node, keyboard_type)
|
||||
self.text_width = 0
|
||||
self.market_text_width = 0
|
||||
self.total_width = 0
|
||||
self.cursor_index = utf8.len(self.value)
|
||||
self.start_index = self.cursor_index
|
||||
self.end_index = self.cursor_index
|
||||
|
||||
self.max_length = nil
|
||||
self.allowed_characters = nil
|
||||
@@ -150,6 +152,11 @@ function Input.init(self, click_node, text_node, keyboard_type)
|
||||
self.button.on_click_outside:subscribe(self.unselect)
|
||||
self.button.on_long_click:subscribe(clear_and_select)
|
||||
|
||||
if defos then
|
||||
self.button.hover.style.ON_HOVER_CURSOR = defos.CURSOR_IBEAM
|
||||
self.button.hover.style.ON_MOUSE_HOVER_CURSOR = defos.CURSOR_IBEAM
|
||||
end
|
||||
|
||||
if html5 then
|
||||
self.button:set_web_user_interaction(true)
|
||||
end
|
||||
@@ -160,6 +167,7 @@ function Input.init(self, click_node, text_node, keyboard_type)
|
||||
self.on_input_empty = Event()
|
||||
self.on_input_full = Event()
|
||||
self.on_input_wrong = Event()
|
||||
self.on_select_cursor_change = Event()
|
||||
end
|
||||
|
||||
|
||||
|
@@ -85,6 +85,12 @@ function Slider.on_layout_change(self)
|
||||
end
|
||||
|
||||
|
||||
function Slider.on_remove(self)
|
||||
-- Return pin to start position
|
||||
gui.set_position(self.node, self.start_pos)
|
||||
end
|
||||
|
||||
|
||||
function Slider.on_window_resized(self)
|
||||
local x_koef, y_koef = helper.get_screen_aspect_koef()
|
||||
self._x_koef = x_koef
|
||||
|
Reference in New Issue
Block a user