Druid - Component GUI Framework

Indeed :grin:

But still, thanks @Insality and @Pawel for your answers.

For some reason, I couldn’t work on my project for 1 month, but when I came back, everything was clearer and I used the" blacklist" method (using a table of buttons that is updated when necessary). Seems to work as intended now.

Not sure I would know how to implement the other approaches, but… one problem at a time :slight_smile:

1 Like

Hey @Insality! (edit : just tagged the wrong insality :see_no_evil: fixed)

I was about to post a wall of text (with lots of screenshots and videos :monkey:), but then I realized that my problem could maybe be summarized as:

How to add/remove elements from a data list? (without deleting/recreating the list)

In the example list, this use case is not available:

However, I did some digging, and there is an example regarding this (even though it’s not enabled by default).

I tried running it, but it doesn’t seem to work correctly.

  • The list positions itself incorrectly when removing an element at the end.
  • The scrolling doesn’t adjust (basically, a “small content” list keeps scrolling as if it had its original size).
  • Some other minor issues here and there.

I suppose that, for now, the example in question is not 100% functional (which is probably why you didn’t enable it).

Just in case: do you have a functional example lying around? :nerd_face:

Not sure about the others, but adding/removing elements to/from a list seems to be an important feature (to me at least). Perhaps someone here has already implemented it?

1 Like

Yea, right now the add/remove the single entry in DataList is not implemented and tested, so it’s disabled.
There are several issues, so currently you have only one option with data_list:set_data until me or someone will implement this.

2 Likes

When the window is resized, dragging becomes offset. I can’t remember if there is a way to address this in Druid?

Minimal project:
Archive.zip (2.6 KB)

Again, thanks for a great extension. :star_struck:

1 Like

Thanks for the report!
I’m already fix this in upcoming release

Should publish soon :upside_down_face:

5 Likes

Druid 0.11.0 : Release Defold Druid v0.11.0 · Insality/druid · GitHub

Hello! What a wonderful day for the new Druid update!

Alright, let’s get straight to the point. Look at what I have for you!

Druid Rich Text has finally been released. The main difference from the existing Bjorn’s Rich Text is that all visual parameters are customizable directly in the GUI. This allows you to integrate Rich Text more accurately and quickly. Additionally, this Rich Text aligns pixel perfect (well, almost) with regular GUI text node.

This version is the most basic one. Honestly, just wanna to publish current version for your and polish it later. Read RichText API here

Another addition is the ability to enable the “HTML mode” for the Button component. In this mode, the button’s action occurs in the context of user action, allowing operations like “copy and paste text” “show the keyboard” and more. However, in this mode, the button only responds to regular clicks due to the technical implementation of it (so no double clicks or long taps for this button).

The huge work was done on documentation. Now it’s more clear and have more examples. All documentation now moved to the API section. The separate componentd.md manual will be deleted soon as all documentation will be moved to the API section.

The API section now filled with overview and usage examples. I’ve started with the basic modules, in future I will add more examples for all modules.

Also, I’ve added the Unit Tests. It’s not cover all Druid code, but it’s a good start! :tada:

Have a good day!

Changelog 0.11.0


  • #126 [Breaking] [Input] Change input bindings to Defold’s defaults
    • This changes was done in prev. tagged release, please sure your input bindings for Druid now are like in the Defold default input bindings. Refer to README for more instructions.
  • #191: [RichText] Finally add Druid Rich Text custom component (live example here). Component is used to make formatted text in your’s GUI. This Rich Text mostly adjusted visually in GUI and have almost pixel-perfect match with similar GUI text node
  • #39: [System] Finally add Unit Tests. Yeah, it cover not all Druid code, but it’s a good start! :tada:
  • #219: [System] UTF-8 performance optimization. Now Druid will try to use utf8 native extension over lua utf8 library if exists. If you wanna use native utf8, just add the extension in your game.project dependency.
  • #156: [Button] Now button can work in HTML5 with html5.set_interaction_listener.
    • The API is button:set_web_user_interaction(true). In HTML5 mode button have several restrictions. Basically, only the single tap event will work.
  • #227: [System] Update current URL in HTML5 example
    • Now if you will open the example from direct URL, it will be updated to the current URL in your browser. So now it’s much easier to share the example link with each other.
  • #183: [Docs] Documentation about GUI in World Space
    • Also not only the GUI in World Space, but overall How to GUI in Defold article.
  • #234: [BREAKING] [Blocker] Now blocker:set_enabled and blocker:is_enabled affects only inner state of component. To consume input, the blocker component should be enabled and the node itself should be enabled.
    • Breaking due the changes can affect your current logic. Please if use this re-check Blocker component usage.
  • #235: [Drag] Fix Drag coordinates on streched screen.
  • #236: [Hover] Fix nil return in hover:on_input.
  • #237: [Layout] Add layout:set_max_gui_upscale function.
    • This functions will scale down element, if current GUI scale is bigger than max_gui_upscale value. It can be useful for adapt mobile device to desktop screen.
  • #238: [System] Add Helper documentation.
  • [System] Now the documentation contains the Druid size. The current size as dependency is around 67KB. It counted without extended components, which is not included by default in the build.

Thanks to the my supporters:

:heart: Support :heart:

Please support me if you like this project! It will help me keep engaged to update Druid and make it even better!

Github-sponsors Ko-Fi BuyMeACoffee

18 Likes

I’m still seeing the same stretched window behaviour in the new build for some reason. Are any changes needed to make it work?

Minimal project:
Archive.zip (2.6 KB)

1 Like

Thanks for the repro!

The issue is the absent druid.on_window_callback function, which catch the window resize to update inner scale koefs.

So if you add the next code, all should be correct

window.set_listener(function(_, event)
	druid.on_window_callback(event)
end)
4 Likes

Now it works! Thanks.

3 Likes

Hello @Insality!

I recently updated Druid from version 0.9.1 to 0.11.0, which was a huge leap, requiring a few adjustments here and there.

However, I just need confirmation about one thing:

1/ When using a data_list in the game, the following message was displayed in the console:

DEBUG:SCRIPT: [Druid]: The component data_list is extended component. You have to register it via druid.register to use it
DEBUG:SCRIPT: [Druid]: Use next code:
DEBUG:SCRIPT: local data_list = require("druid.extended.data_list")
DEBUG:SCRIPT: druid.register("data_list", data_list)

So I added the registration as mentioned:

	self.data_list_items = require("druid.extended.data_list") -- druid 0.11.0
	druid.register("data_list", self.data_list_items) -- druid 0.11.0

	self.data_list_items = self.druid:new_data_list(self.scroll_items, self.grid_items, create_item_list)
	self.data_list_items:set_data(self.data_set_items)

And it seems to be working.

However, I’m still wondering if this was the correct thing to do, as there is no “druid.register” in the provided examples (specifically, data_list > static_grid) for Druid 0.11.0 :man_shrugging: (and it works fine :face_with_monocle:)

Can you confirm that it is necessary to use the druid.register in this way?

Right, all “extended” components should be register first to include them in your build

In Druid examples I register all extended components here

Better to include this code in your bootstrap script to don’t register again them each time

Thanks for the feedback! I will try to figure out how to describe this better

5 Likes

Is their any sample project for understaning how to use custom components. I’m not understanding spawning and registering parts.

Trying something small
I’m trying to create custom button component for navigation into other scenes. This buttons will have different icons in differnet scenes.

Hello!
Probably you can check this example:
Live example, code

or custom component documentation

In this example the custom component for data list are used.

Basically, the custom component is your lua file, that in simplest way will look like this:

local component = require("druid.component")

local ButtonComponent = component.create("button_component")

---@param template string
---@param nodes table<hash, node>
function ButtonComponent:init(template, nodes)
	self:set_template(template)
	self:set_nodes(nodes)
	self.druid = self:get_druid()

	self.root = self:get_node("root")
	self.button = self.druid:new_button(self.root, self._on_click)
end

function ButtonComponent:_on_click()
	self.on_click:trigger(self)
end

return ButtonComponent

And later you will create your component with self.druid:new(ButtonComponent, template, nodes)

Registering components are not required, it’s just to make aliases.
Example:

-- Direct component creation
local ButtonComponent = require("example.examples.data_list.with_component.button_component.button_component")
local button = self.druid:new(ButtonComponent, "button_component", nodes)

----- or ------

-- Register only once:
local druid = require("druid.druid")
local ButtonComponent = require("example.examples.data_list.with_component.button_component.button_component")
druid.register(ButtomComponent, "button_component")

-- And create component in this way
self.druid:new_button_component(template, nodes)

Don’t know about all your requirements, but isn’t it easier to custom icons right inside GUI file and add button over this GUI node?

I’m just playing around this to learn this stuff. Even I don’t have clear idea right now when to use and not. I just gone through reading How to GUI in defold. Trying best practices from start of the project.

1 Like

@Insality , hello!
Is there updated examples on LangText? Link to source here leads to 404.

Hello!
Just checked the link now - it works. There are no any updates in this example

@Insality Hey! Thanks for the amazing work. When I was checking the scroll example, like you see in the ss, when the buttons com top of eachother, even though the expected behavior is go back to menu, it acts like if I clicked on the node button beneath and ignores the menu button click. It happens only when two buttons are aligned like this, just wanted to share.

1 Like

Thanks for sharing this! I’ll fix it :slight_smile:

Just checked the link now - it works. There are no any updates in this example

This is how it looks for me. I click “code” and get 404

1 Like