Update README

Button key trigger will not consume input
Update scroll position while animate
Add scroll:set_view_size
Better static grid get_index function
Rework Data List (only static grid)
Update Default style
Remove a component from parent if exists on druid:remove
This commit is contained in:
Insality
2024-09-03 21:48:43 +03:00
parent 0aeb0b3fea
commit 4a095a2a24
18 changed files with 161 additions and 233 deletions

View File

@@ -343,6 +343,7 @@ function Button.on_input(self, action_id, action)
return false
end
local is_consume = true
local is_pick = true
local is_key_trigger = (action_id == self.key_trigger)
if not is_key_trigger then
@@ -365,6 +366,7 @@ function Button.on_input(self, action_id, action)
if is_key_trigger then
self.hover:set_hover(not action.released)
is_consume = false
end
if action.pressed then
@@ -380,19 +382,19 @@ function Button.on_input(self, action_id, action)
on_button_click(self)
end)
end
return true
return is_consume
end
-- While hold button, repeat rate pick from input.repeat_interval
if action.repeated then
if self.on_repeated_click:is_exist() and self.can_action then
on_button_repeated_click(self)
return true
return is_consume
end
end
if action.released then
return on_button_release(self)
return on_button_release(self) and is_consume
end
if self.can_action and self.on_long_click:is_exist() then
@@ -400,16 +402,16 @@ function Button.on_input(self, action_id, action)
if self.style.AUTOHOLD_TRIGGER <= press_time then
on_button_release(self)
return true
return is_consume
end
if press_time >= self.style.LONGTAP_TIME then
on_button_hold(self, press_time)
return true
return is_consume
end
end
return not self.disabled
return not self.disabled and is_consume
end

View File

@@ -5,6 +5,9 @@
-- @within BaseComponent
-- @alias druid.hover
--- Hover node
-- @tfield node node
--- On hover callback(self, state, hover_instance)
-- @tfield DruidEvent on_hover @{DruidEvent}

View File

@@ -216,6 +216,12 @@ end
function Scroll.update(self, dt)
if self.is_animate then
self.position.x = gui.get(self.content_node, "position.x")
self.position.y = gui.get(self.content_node, "position.y")
self.on_scroll:trigger(self:get_context(), self.position)
end
if self.drag.is_drag then
self:_update_hand_scroll(dt)
else
@@ -255,12 +261,12 @@ function Scroll.scroll_to(self, point, is_instant)
if is_instant then
self.target_position = target
self:_set_scroll_position(target)
self:_set_scroll_position(target.x, target.y)
else
gui.animate(self.content_node, gui.PROP_POSITION, target, gui.EASING_OUTSINE, self.style.ANIM_SPEED, 0, function()
self.is_animate = false
self.target_position = target
self:_set_scroll_position(target)
self:_set_scroll_position(target.x, target.y)
end)
end
@@ -305,6 +311,13 @@ function Scroll.scroll_to_percent(self, percent, is_instant)
0
)
if not self.drag.can_x then
pos.x = self.position.x
end
if not self.drag.can_y then
pos.y = self.position.y
end
self:scroll_to(pos, is_instant)
end
@@ -338,6 +351,20 @@ function Scroll.set_size(self, size, offset)
end
--- Set scroll view size.
-- @tparam Scroll self @{Scroll}
-- @tparam vector3 size The new size for view node
-- @treturn druid.scroll Current scroll instance
function Scroll.set_view_size(self, size)
gui.set_size(self.view_node, size)
self.view_size = size
self.view_border = helper.get_border(self.view_node)
self:_update_size()
return self
end
--- Enable or disable scroll inert.
-- If disabled, scroll through points (if exist)
-- If no points, just simple drag without inertion
@@ -583,14 +610,14 @@ function Scroll._cancel_animate(self)
end
function Scroll._set_scroll_position(self, position)
function Scroll._set_scroll_position(self, position_x, position_y)
local available_extra = self.available_pos_extra
position.x = helper.clamp(position.x, available_extra.x, available_extra.z)
position.y = helper.clamp(position.y, available_extra.w, available_extra.y)
position_x = helper.clamp(position_x, available_extra.x, available_extra.z)
position_y = helper.clamp(position_y, available_extra.w, available_extra.y)
if self.position.x ~= position.x or self.position.y ~= position.y then
self.position.x = position.x
self.position.y = position.y
if self.position.x ~= position_x or self.position.y ~= position_y then
self.position.x = position_x
self.position.y = position_y
gui.set_position(self.content_node, self.position)
self.on_scroll:trigger(self:get_context(), self.position)
@@ -692,7 +719,7 @@ function Scroll._update_free_scroll(self, dt)
self:_check_soft_zone()
if self.position.x ~= target.x or self.position.y ~= target.y then
self:_set_scroll_position(target)
self:_set_scroll_position(target.x, target.y)
end
end
@@ -704,7 +731,7 @@ function Scroll._update_hand_scroll(self, dt)
self.inertion.x = (self.inertion.x + dx) * self.style.FRICT_HOLD
self.inertion.y = (self.inertion.y + dy) * self.style.FRICT_HOLD
self:_set_scroll_position(self.target_position)
self:_set_scroll_position(self.target_position.x, self.target_position.y)
end
@@ -746,14 +773,14 @@ function Scroll._update_size(self)
content_border_extra.w = content_border_extra.w - stretch_size * sign_y
if not self.style.SMALL_CONTENT_SCROLL then
self.drag.can_x = content_size.x > self.view_size.x
self.drag.can_y = content_size.y > self.view_size.y
self.drag.can_x = content_size.x > self.view_size.x and self._is_horizontal_scroll
self.drag.can_y = content_size.y > self.view_size.y and self._is_vertical_scroll
end
self.available_pos_extra = get_border_vector(self.view_border - content_border_extra, self._offset)
self.available_size_extra = get_size_vector(self.available_pos_extra)
self:_set_scroll_position(self.position)
self:_set_scroll_position(self.position.x, self.position.y)
self.target_position.x = self.position.x
self.target_position.y = self.position.y
end
@@ -788,7 +815,7 @@ function Scroll._process_scroll_wheel(self, action_id, action)
self.inertion.x = 0
end
self:_set_scroll_position(self.target_position)
self:_set_scroll_position(self.target_position.x, self.target_position.y)
end
return true

View File

@@ -171,8 +171,12 @@ end
-- @tparam vector3 pos The node position in the grid
-- @treturn number The node index
function StaticGrid.get_index(self, pos)
local col = pos.x / self.node_size.x + 1
local row = -pos.y / self.node_size.y
-- Offset to left-top corner from node pivot
local node_offset_x = self.node_size.x * (-0.5 + self.node_pivot.x)
local node_offset_y = self.node_size.y * (0.5 - self.node_pivot.y)
local col = (pos.x + node_offset_x) / self.node_size.x + 1
local row = -(pos.y + node_offset_y) / self.node_size.y
col = helper.round(col)
row = helper.round(row)
@@ -337,6 +341,7 @@ function StaticGrid.clear(self)
self:_update()
self.on_clear:trigger(self:get_context())
self.on_change_items:trigger(self:get_context())
return self
end