Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Insality committed Sep 3, 2024
1 parent 0aeb0b3 commit 4a095a2
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Build && Run
run: |
deployer_url="https://raw.githubusercontent.com/Insality/defold-deployer/1/deployer.sh"
curl -s ${deployer_url} | bash -s lbd --headless --settings ./unit_test.txt
curl -s ${deployer_url} | bash -s lbd --headless --settings ./test/test.ini
- name: Upload test report
run: bash <(curl -s https://codecov.io/bash)
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Thumbs.db
builtins
dist
deployer_version_settings.txt

.deployer_cache
bob*.jar
manifest.private.der
manifest.public.der
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

[![](media/druid_logo.png)](https://insality.github.io/druid/)

[![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/insality) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/insality) [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/insality)
[![GitHub release (latest by date)](https://img.shields.io/github/v/tag/insality/druid?style=for-the-badge&label=Release)](https://github.com/Insality/druid/tags)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/insality/druid/ci-workflow.yml?branch=master&style=for-the-badge)](https://github.com/Insality/druid/actions)
[![codecov](https://img.shields.io/codecov/c/github/Insality/druid?style=for-the-badge)](https://codecov.io/gh/Insality/druid)

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/insality/druid)](https://github.com/Insality/druid/releases)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/insality/druid/ci-workflow.yml?branch=master)](https://github.com/Insality/druid/actions)
[![codecov](https://codecov.io/gh/Insality/druid/branch/master/graph/badge.svg)](https://codecov.io/gh/Insality/druid)
[![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/insality) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/insality) [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/insality)

**Druid** - powerful **Defold** component UI framework that empowers developers to create stunning and customizable GUIs by leveraging a wide range of embedded components or effortlessly designing their own game-specific components.

Expand All @@ -23,11 +23,19 @@ To integrate the **Druid** extension into your own project, add this project as
Here is a list of [all releases](https://github.com/Insality/druid/releases).

Size: **67.16 KB**

> The size metrics exlcude the extended components, which are including only on demand.
### Library Size

> **Note:** The library size is calculated based on the build report per platform. The extended components are exlcuded, which are including only on demand.
| Platform | Library Size |
| ---------------- | ------------- |
| HTML5 | **38.96 KB** |
| Desktop / Mobile | **65.97 KB** |


### Input Bindings

**Druid** utilizes the `/builtins/input/all.input_binding` input bindings. For custom input bindings, refer to the Input Binding section in the **_[Advanced Setup](docs_md/advanced-setup.md#input-bindings)_**.


Expand Down Expand Up @@ -173,8 +181,6 @@ Each example page provides a direct link to the corresponding example code, maki

Or refer directly to the [**example folder**](https://github.com/Insality/druid/tree/develop/example) for code examples demonstrating how to use **Druid**.

If you want to see examples of GUIs created with Druid, please refer to the [game_examples.md](docs_md/game_examples.md) file.

## Documentation

To better understand **Druid**, read the following documentation:
Expand Down Expand Up @@ -214,4 +220,4 @@ For a complete history of the development of **Druid**, please check the [change

Your donation helps me stay engaged in creating valuable projects for **Defold**. If you appreciate what I'm doing, please consider supporting me!

[![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/insality) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/insality) [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/insality)
[![Github-sponsors](https://img.shields.io/badge/sponsor-30363D?style=for-the-badge&logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/insality) [![Ko-Fi](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/insality) [![BuyMeACoffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/insality)
8 changes: 0 additions & 8 deletions docs_md/game_examples.md

This file was deleted.

4 changes: 3 additions & 1 deletion druid/annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ local druid__hotkey__style = {}


---@class druid.hover : druid.base_component
---@field node node Hover node
---@field on_hover druid.event On hover callback(self, state, hover_instance)
---@field on_mouse_hover druid.event On mouse hover callback(self, state, hover_instance)
local druid__hover = {}
Expand Down Expand Up @@ -998,9 +999,10 @@ function druid__rich_text.init(self, template, nodes) end
function druid__rich_text.set_text(self, text) end

--- Get all words, which has a passed tag.
---@param self druid.rich_text @{RichText}
---@param tag string
---@return druid.rich_text.word[] words
function druid__rich_text.tagged(tag) end
function druid__rich_text.tagged(self, tag) end


---@class druid.rich_text.style
Expand Down
14 changes: 8 additions & 6 deletions druid/base/button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -380,36 +382,36 @@ 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
local press_time = socket.gettime() - self.last_pressed_time

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


Expand Down
3 changes: 3 additions & 0 deletions druid/base/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
55 changes: 41 additions & 14 deletions druid/base/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions druid/base/static_grid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions druid/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function BaseComponent.setup_component(self, druid_instance, context, style, ins
self:set_template("")

if self._meta.parent then
self._meta.parent:__add_children(self)
self._meta.parent:__add_child(self)
end

return self
Expand Down Expand Up @@ -445,19 +445,20 @@ end
-- @tparam BaseComponent self @{BaseComponent}
-- @tparam component children The druid component instance
-- @local
function BaseComponent.__add_children(self, children)
table.insert(self._meta.children, children)
function BaseComponent.__add_child(self, child)
table.insert(self._meta.children, child)
end


--- Remove child from component children list
-- @tparam BaseComponent self @{BaseComponent}
-- @tparam component children The druid component instance
-- @local
function BaseComponent.__remove_children(self, children)
function BaseComponent.__remove_child(self, child)
for i = #self._meta.children, 1, -1 do
if self._meta.children[i] == children then
if self._meta.children[i] == child then
table.remove(self._meta.children, i)
return true
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion druid/custom/rich_input/rich_input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
---

local component = require("druid.component")
local input = require("druid.extended.input")

local RichInput = component.create("druid.rich_input")

Expand Down Expand Up @@ -74,7 +75,7 @@ function RichInput.init(self, template, nodes)
self.druid = self:get_druid()
self.root = self:get_node(SCHEME.ROOT)

self.input = self.druid:new_input(self:get_node(SCHEME.BUTTON), self:get_node(SCHEME.INPUT))
self.input = self.druid:new(input, self:get_node(SCHEME.BUTTON), self:get_node(SCHEME.INPUT))
self.cursor = self:get_node(SCHEME.CURSOR)

self.input:set_text("")
Expand Down
3 changes: 2 additions & 1 deletion druid/custom/rich_text/rich_text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ end


--- Get all words, which has a passed tag.
-- @tparam RichText self @{RichText}
-- @tparam string tag
-- @treturn druid.rich_text.word[] words
function RichText:tagged(tag)
function RichText.tagged(self, tag)
if not self._words then
return
end
Expand Down
2 changes: 1 addition & 1 deletion druid/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function M.unsubscribe(self, callback, callback_context)
return false
end

tremove(self, event_index --[[@as number]])
tremove(self, event_index)
return true
end

Expand Down
Loading

0 comments on commit 4a095a2

Please sign in to comment.