-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New components #67
Comments
Right now extending components is not designed, but can be done with a little trick. I will think more about this ability, should be it in Druid or not. Druid prefer composition and customizing components via styles should be enough. If you want replace all buttons, current way is copy button component, rework it and register at druid via Trick: for now, you can create subclass from druid component in next-way: local class = require("druid.system.middleclass")
local button = require("druid.base.button")
local M = class("button_custom", button)
--- Class constructor
function M.initialize(self)
--- Call parent constructor
button.initialize(self)
end
function M.is_enabled(self)
print("Overridden function")
return not self.disabled
end
return M Thanks for feedback! Issue will be closed after solution for this. |
I was trying to do it using styles only, but I can't quite figure out how to add some properties to it (for example, save the original node's color so I can manipulate it later). I wanted to avoid copy/paste of the original button codes, because it pretty much contains the basic functionality already, so for easier code maintenance, I just like to extend it. Your solution above actually works perfectly for my use case! I set the properties in this new extended component, then use those properties in my new style, without having to mess around further with the original button codes. Thanks again! |
local M = component.create("my_component")
The code above creates a brand new my_component. What if I just want to extend the existing functionality of an existing druid component e.g. a button. How can I do this?
Currently, I am using something like this:
but then I have to override all functions like:
Is this the proper way to do things? Or is there a simpler way?
Thanks.
The text was updated successfully, but these errors were encountered: