Druid - Component GUI Framework

Druid 0.4.0: https://github.com/Insality/druid/releases/tag/0.4.0

  • Add Drag basic component

    • Drag component allow you detect dragging on GUI node
    • Drag will be processed even the cursor is outside of node, if drag is already started
    • Drag provides correct handle of several touches. Drag can switch between them (no more scroll gliches with position)
    • Drag have next events:
      • on_touch_start (self)
      • on_touch_end (self)
      • on_drag_start (self)
      • on_drag (self, dx, dy)
      • on_drag_end (self)
    • You can restriction side of dragging by changing drag.can_x and drag.can_y fields
    • You can setup drag deadzone to detect, when dragging is started (by default 10 pixels)
  • Druid Scroll component fully reworked. Input logic moved to Drag component

    • Update scroll documentation
    • [Breaking changes] Change constructor order params
    • [Breaking changes] Change scroll:set_border to scroll:set_size
    • Scroll now contains from view and content node
      • View node - static node, which size determine the “camera” zone
      • Content node - dynamic node, moving by Scroll component
    • Scroll will be disabled only if content size equals to view size (by width or height separatly)
    • You can adjust start scroll size via .gui scene. Just setup correct node size
    • Different anchoring is supported (for easier layouting)
    • Function scroll_to now accept position relative to content node. It’s more easier for handling. Example: if you have children node of content_node, you can pass this node position to scroll to this.
    • Resolve #52: Content node size now can be less than view node size. In this case, content will be scrolled only inside view size (can be disabled via style field: SMALL_CONTENT_SCROLL)
    • Fix #50: If style.SOFT_ZONE_SIZE equals to [0…1], scroll had glitches
  • Druid Grid Update

    • Anchor by default equals to node pivot (so, more component settings in .gui settings) (#51)
    • Function grid:clear now don’t delete any GUI nodes. Druid will not care about gui.delete_node logic anymore (#56)
  • Druid Hover component now have two hover events (#49):

    • on_hover is usual hover event. Trigger only if touch or mouse action_id pressed on node
    • on_mouse_hover action on node without action_id (desktop mouse over). Works only on desktop platform
  • Styles update:

    • Styles table now can be empty, every component have their default style values
    • Remove component:get_style function. Now you can only set styles
    • To get style values in component, add component:on_style_change function. It’s invoked on component:set_style function
    • You can look up default values inside component:on_style_change function or style component API on Druid API
  • Druid update:

    • Now function druid:remove remove instance and all instance children components. No more manual deleting child components (#41)
  • Fix: Blocker component bug (blocker had very high priority, so it’s block even button components, created after blocker)

  • Fix #58: Bug, when druid instance should be always named druid (ex: self.druid = druid.new(self))

  • Fix #53: Bug with final Druid instance without any components

P.S.: Thanks for any feedback you give to me. It’s very helpful :slight_smile:


This is great API, for quick and easy GUI functionality.

I have query and not sure if this right platform to ask.
I am trying to implement scroller with dynamic content, but facing issue with Not enough resources, as we have resource limit,
for example message app having scroller for message, as each message is resource, and have no limit for message.

where as I tried to release resources and re-adding resources. for example while scroll up, release bottom out of grid resources and add then again on top of grid and vise versa.
but not working exactly as expected, is there any provision for this type of requirement ? or what else I can try ?
Thank you in advance,

1 Like

Thanks for the feedback! Glad to hear you like Druid

The way you described to create infinity scroll is correct. I’ll add infinity scroll soon (week or two I guess), it will be available as additional GUI component.

But for now my advice is implement it by you own, as you can.

1 Like

Thank you for your quick reply,

I am working on my own implementation, wanted to know what is a better approach.
is it a good approach to reposition out of the grid node again. I mean, while scroll down repositions top nodes again to the bottom, will it be quick enough and smooth in functionality.
or any other approach you want to suggest?

I think reposition is the best way, but my solution is delete nodes outside and re-create it again. Since Defold is static engine this is good enough too (but much easier for use)

You can create your component in any of ways, it should be ok :slight_smile:


Druid 0.5.0: https://github.com/Insality/druid/releases/tag/0.5.0

Besides a lot of fixes (thanks for feedback!) two components was add: StaticGrid and DynamicGrid instead of usual Grid component (it is deprecated now).
Add component:set_input_enabled for basic component class. So you can enable/disable user input for any component.
Finally implemented on_layout_changed support. Druid components now will try keep their data between layout changing! You also can use this callback in your custom components.
Also check component.template.lua what you can use for your own custom components!

  • #77 Grid update:
    • The grid component now is deprecated. Use static_grid instead. Druid will show you deprecated message, if you still using grid component
    • [BREAKING] Remove the grid:set_offset grid functions. To adjust the distance between nodes inside grid - setup correct node sizes
    • Add static_grid component
      • The behaviour like previous grid component
      • Have constant element size, so have ability to precalculate positions, indexes and size of content
      • By default, not shifting elements on removing element. Add is_shift flag to static_grid:remove function
      • This grid can spawn elements with several rows and columns
    • Add dynamic_grid component
      • Can have different element size. So have no ability to precalculate stuff like static_grid
      • This grid can’t have gaps between elements. You will get the error, if spawn element far away from other elements
      • The grid can spawn elements only in row or in column
      • The grid node should have West, East, South or North pivot (vertical or horizontal element placement)
      • Able to shift nodes left or right on grid:add / grid:remove functions
  • Scroll update:
    • Add scroll:set_vertical_scroll and scroll:set_horizontal_scroll for disable scroll sides
    • Add scroll:bind_grid function. Now is possible to bind Druid Grid component (Static or Dynamic) to the scroll for auto refresh the scroll size on grid nodes changing
  • #37 Add on_layout_change support. Druid will keep and restore GUI component data between changing game layout. Override function on_layout_change in your custom components to do stuff you need.
  • #85 Move several components from base folder to extended. In future to use them, you have to register them manually. This is done for decrease build size by excluding unused components
  • Fix #61: Button component: fix button animation node creation
  • Fix #64: Hover component: wrong mouse_hover default state
  • Fix #71: Blocker: blocker now correct block mouse hover event
  • Fix #72: Fix return nil in some on_input functions
  • Fix #74: [BREAKING] Fix typo: strech -> stretch. Scroll function set_extra_stretch_size renamed
  • Fix #76: Add params for lang text localization component
  • Fix #79: Fix druid:remove inside on_input callback
  • Fix #80: Fix hover:set_enable typo function call
  • Fix #88: Add component:set_input_enabled function to enable/disable input for druid component. Now you can disable input of any druid component, even complex (with other components inside)
  • Add component.template.lua as template for Druid custom component
  • Update the example app

Awesome work, really impressive.
I have a question about the list/grid components.
Does it reuse the nodes (similar to a recyclerview in native Android)? I mean does it support a 100K item list or do we have to keep the number of items under the max sprites/nodes allowed?


Currently no, there is no druid solution for infinity scroll
Above we talked about this. In next Druid release will be added extended component to handle scroll with huge amount of data. Current release with grids is preparing for this.

Thanks for the quick changes and dynamic grid,
it seems there is an issue with dynamic_grid added into the scroller, if the prefab_dynamic box component has some nested box component or text component, the nested component is not visible in the scroller,

I the example project, I also tried adding grid_nodes_prefab to grid_dynamic_view however its only showing the parent box of grid_nodes_prefab and not showing inner component that is grid_nodes_dot.
is anything else I need to try?

It’s seems not the Druid issue, but gui node management.

In Druid Example, create function just make gui.clone of the prefab node. For your case, you should do gui.clone_tree and do your stuff with gui nodes tree


56 data_list_gif

Druid 0.6.0: https://github.com/Insality/druid/releases/tag/0.6.0

Hey! Are you tired from Druid updates? (It’s a joke)

Finally, got a time to release component to process huge amount of data. So introducing: DataList component. It can help solve your problem with GUI nodes limit reached and helps with scroll optimization. Give feedback about it!

The next important stuff is EmmyLua docs. I’m implemented EmmyLua doc generator from LuaDoc and Protofiles, so now you can use EmmyLua annotations inside your IDE instead of website API looking or source code scanning.

Also the Druid examples is reworked, so each example will be in separate collection. Now it’s become a much easier to learn Druid via examples. A lot of stuff in progress now, but you already can see on it!

Input priority got reworked too. Now instead of two input stacks: usual and high, Druid use simple input priority value.

And I should note here are several breaking changes, take a look in changelogs.

Wanna something more? Add an issues!
Have a good day.

Changelog 0.6.0

  • #43 Add DataList Druid extended component. Component used to manage huge amount of data to make stuff like infinity scroll.
    • This versions is first basic implementation. But it should be enough for almost all basic stuff.
    • Create Data List with druid:new_data_list(scroll, grid, create_function).
      • scroll - already created Scroll component
      • grid - already created StaticGrid or DynamicGrid component
      • create_function - your function to create node instances. This callback have next parameters: fun(self, data, index, data_list)
        • self - Script/Druid context
        • data- your element data
        • index - element index
        • data_list - current DataList component
    • Create function should return root node and optionaly, Druid component. It’s required to manage create/remove lifecycle
    • Set data with data_list:set_data({...})
    • In current version there is no add/remove functions
  • Add EmmyLua annotations (ta-daaa). See how to use it FAQ!
  • Add context argument to Druid Event. You can pass this argument to forward it first in your callbacks (for example - object context)
  • Add SHIFT_POLICY for Static and Dynamic Grids. It mean how nodes will be shifted if you append data between nodes. There are const.SHIFT.RIGHT, const.SHIFT.LEFT and const.SHIFT.NO_SHIFT.
    • [BREAKING] Please check your StaticGrid:remove and DynamicGrid:remove functions
  • #102 [BREAKING] Removed component:increase_input_priority component function. Use component:set_input_priority function instead. The bigger priority value processed first. The value 10 is default for Druid components, the 100 value is maximum priority for acquire input in drag and input components
    • Add constants for priorities: const.PRIORITY_INPUT, const.PRIORITY_INPUT_HIGH, const.PRIORITY_INPUT_MAX.
    • [BREAKING] If you use in you custom components interest: component.ON_INPUT_HIGH you should replace it with component.ON_INPUT and add const.PRIORITY_INPUT_HIGH as third param. For example:
      local Drag = component.create("drag", { component.ON_INPUT_HIGH })
      local Drag = component.create("drag", { component.ON_INPUT }, const.PRIORITY_INPUT_HIGH)
  • Lang text now can be initialized without default locale id
  • Input component: rename field selected to is_selected (according to the docs)
  • #92 Setup repo for CI and unit tests. (Yea, successful build and tests badges!)
  • #86 Fix a lot of event triggers on scroll inertia moving
  • #101 Fix scroll to other node instead of swipe direction with scroll’s points of interest (without inert settings)
  • #103 Add helper.centate_nodes function. It can horizontal align several Box and Text nodes
  • #105 Add Input:select and Input:unselect function.
  • #106 Add Input.style.IS_UNSELECT_ON_RESELECT style param. If true, it will be unselect input on click on input box, not only on outside click.
  • #108 Add component interests const to component.lua
  • #116 You can pass Text component in Input component instead of text node
  • #117 Move each Druid example in separate collection. It’s a lot of easier now to learn via examples, check it!
    • Examples in progress, so a lot of stuff are locked now, stay tuned!
  • #118 Druid.scroll freezes if held in one place for a long time
  • #123 Add scroll for Scroll component via mouse wheel or touchpad:
    • Added Scroll style params: WHEEL_SCROLL_SPEED, WHEEL_SCROLL_INVERTED
    • Mouse scroll working when cursor is hover on scroll view node
    • Vertical scroll have more priority than horizontal
    • Fix: When Hover component node became disabled, reset hover state (throw on_hover and on_mouse_hover events)
    • By default mouse scroll is disabled
    • This is basic implementation, it is work not perfect
  • #124 Add Scroll:set_click_zone function. This is just link to Drag:set_click_zone function inside scroll component.
  • #127 The druid:create is deprecated. Use druid:new for creating custom components

What would be the best way to hook in animations – specifically, I’m looking to add some animation when items are added to a grid, e.g. like they’re cards being dealt out.

If it requires modifying the druid code, that’s fine, but I’m not exactly sure where to look, as I wasn’t able to find anything in the examples or documentation


It’s nice example request, thanks!

Usually, for some animations like you say, I just run animations after adding elements to the grid (card appear, leaderboards, etc)
If you need animation before element deletion, I just call grid.remove in the end of this animation.

If this case is not suit for you, I need more information what you want :wink:

1 Like

so, like I said above, right now I’m trying to basically do a card-dealing animation when the elements are added to the grid. I did eventually find the on_add_item event, which seems like exactly what I want, but only the last one is being animated. Here’s my preliminary attempt:

self.matching_grid.on_add_item:subscribe(function(self, node, index)
	local end_pos = gui.get_position(node)
	print("added "..index.." @ "..end_pos.x..","..end_pos.y)

	gui.set_position(node, vmath.vector3(480, -100, 0))
	gui.animate(node, gui.PROP_POSITION, end_pos, gui.EASING_OUTBACK, 1.0)

@greay sorry for late reply!

Yea, I got the your problem. The reason is what Grid component is manage their nodes position. So after add/update/remove any element, Grid will update all their element positions. Your callback is right, but after add element all previous position is updated.

The correct way is manage position inside the root node of added elements. You can add root node (which added to Grid component) and inside root node the position_anchor node to make animations.

I’ve add the example you can check (yea, now with deep linking!)

Try live example with grid animations here

The example code here


Hi @Insality,
I use Druid library in my project and I have some issues regarding Scroll with POIs.

  1. The powerful scroll of grid to the edge position causes a delay by stretching.
    Delay depends from scroll “power”.
    It seems an inertion and stretching working parallel and stretching waits until inertion routine returns the see point back into stretching area and then grid will be moved to the end position through stretching program.

GIF1 on Google Drive

  1. At some positions the scroll “jump” to the wrong position and then does inertion-scroll.

GIF2 on Google Drive

Both issues can be re-produced with your default example.
Perhaps I do something wrong , but I would like to use both stretching and inertion by this scroll.

1 Like

Thanks for the feedback!

I’ll take a look later, it’s possible that there is some problems with POIs in the scroll. So there is a reason to look on it better :wink:

1 Like


Druid 0.7.0 : https://github.com/Insality/druid/releases/tag/0.7.0

Hello! Here I’m again with new Druid stuff for you!

The feature I want a long time to deliver for you: the different Text size adjust modes. Druid use the text node sizes to fit the text into this box.
There are new adjust modes such as Trim, Scroll, Downscale with restrictions and Downscale + Scroll. You can change default adjust mode via text style table, but by default there is no changes - it’s downscale adjust mode as before.
I’ll hope it can be useful for you for in different cases and now it will be much easy to fit all your texts for different languages!

The next features is made for add more control for availability of user input. So meet the whitelists, blacklists and custom check functions for Buttons. Now you can easily choose the more suitable way to enable/disable/restrict input for you users. I’m sure it can be useful for you tutorials.

Another small, but cool feature on my mind is druid.stencil_check. If you did interactive elements inside the Scroll, probably you used component:set_click_zone to restrict input zone by stencil scroll view node. With this feature, Druid will do it automaticaly for you! You can enable this feature in your game.project. It will not override you existing set_click_zone calls.

Now you even able to remap default input keys! Also there are several bugfixes with Scroll, Text, Grids.

Wanna something more? Add an issues!
You can say thanks to me via stars on GitHub! :wink:

Good luck!

Changelog 0.7.0

  • #78 [Text] Update Text component:
    • Add text adjust type instead of no_adjust param.
      • const.TEXT_ADJUST.DOWNSCALE - Change text’s scale to fit in the text node size
      • const.TEXT_ADJUST.TRIM - Trim the text with postfix (default - “…”, override in styles) to fit in the text node size
      • const.TEXT_ADJUST.NO_ADJUST - No any adjust, like default Defold text node
      • const.TEXT_ADJUST.DOWNSCALE_LIMITED - Change text’s scale list downscale, but there is limit for text’s scale
      • const.TEXT_ADJUST.SCROLL - Change text’s pivot to imitate scrolling in the text box. Use with stencil node for better effect.
      • const.TEXT_ADJUST.SCALE_THEN_SCROLL - Combine two modes: first limited downscale, then scroll
  • #110 [Button] Add Button:set_check_function(check_function, failure_callback) function to add your custom click condition to button.
    • Button:set_enabled has more priority than this to check button availability
    • The check_function should return true of false. If true - button can be clicked by user
    • The failure_callback will be called if check_function will return false
    • Example with set_check_function in general:buttons example collection
  • #66 Add druid:set_whitelist() and druid.set_blacklist() functions. It’s affects only on input process step, you can allow/forbid interact with list of specific components
    • You can pass array of components, single component or nil in these functions
  • #111 Add autocheck for input and stencil nodes. To enable this feature, add druid.stencil_check = 1 to your game.project file.
    • This feature is using for auto setup component:set_click_zone to restrict clicks outside scrolls zone for example. Now you can don’t think about click zone and let Druid do it instead of you!
    • Add helper.get_closest_stencil_node function to get closest parent of non inverted stencil node
    • Add component.ON_LATE_INIT interest. Component with this will call component.on_late_init function once after component init on update step. This can be used to do something after all gui components are inited
  • #81 Add ability to interact with Druid input via messages:
    • Currently add for Button and Text component only:
      • Send to gui.script message: druid_const.ON_MESSAGE_INPUT. The message table params:
        • node_id - the name of the node with component on it
        • action - value from druid_const.MESSAGE_INPUT. Available values:
          • BUTTON_CLICK - usual button click callback
          • BUTTON_LONG_CLICK - button long click callback
          • BUTTON_DOUBLE_CLICK - button double click callback
          • BUTTON_REPEATED_CLICK - button repeated click callback
          • TEXT_SET - set text for Text component
        • value - optional field for several actions. For example value is text for TEXT_SET
    • Add Druid component interest: component.ON_MESSAGE_INPUT
    • Implement new interest via function component:on_message_input(node_id, message)
    • See System: Message input example
  • #131 [Static Grid] Add style param: IS_DYNAMIC_NODE_POSES (default: false). Always align by content size with node anchor.
    • If true - Static Grid will by always align to content anchor.
    • If false (currently behaviour) - all poses for static grid is predefined and not depends on element’s count (see example: static grid and static grid with dynamic poses)
  • #125 Now component:set_input_priority() affects on all component’s children too
  • #143 Update all lang components on druid.set_text_function call
  • #112 Allow remap default Druid input bindings via game.project
  • #107 [Text] Better scale text adjust by height for multiline text nodes (but still not perfect)
  • #144 [Scroll] Fix some glitches with scroll Points of Interest. Remove false detection of scroll stopped.
  • #142 [Scroll] Add Scroll style param WHEEL_SCROLL_BY_INERTION (default - false). If true - mouse wheel will add inertion to scroll, if false - set position directly per mouse wheel event.
    • This fix caused because Mac trackpad seems have additional mouse wheel events for simulate inertion. If you uncomfortable with this, you can disable WHEEL_SCROLL_BY_INERTION for more controllable scroll by mouse wheel.
  • #132 Add example with grid add/remove with animations

Hi @Insality ,
great thanks for #144 :+1:
Star is given !
Regards @UzelDev



I am having an issue testing the timer function.

I can get the timer to appear on the gui, but it remains static at the initial value - it doesn’t tick down.

I have a main.collection and a main_menu.gui.

I have two scripts - main_controller.script which performs the functions of the app, and main_menu.gui.script that handles the user input. The gui script passes messages to the main_controller.script when there is user input (there are 12 gui nodes in total). It’s a very simple project as I am pretty new to Defold.

When the app loads the timer value loads successfully in the gui node as pass as a parameter, but then it fails to change.

Is there anything I am missing?