Adding sounds to a druid button

I feel like this might be a stupid question but… what’s the recommended way to add a click on and click off sound to a druid button? Do I just add the sound to the callback function that gets passed into self.druid:new_buttton ? That way I can get a sound to play when you have released the button but, if that’s the way, how would I do it when you click but have not yet released?

Thanks!

I think Druid button have a event you can subscribe to add an sound at this time:

self.button = self.druid:new_button()
self.button.on_pressed:subscribe(function()
    -- play on_pressed sound
end)

But this add sound only for one button. No any way to do it with style to apply on all buttons.

But you can create your custom button widget, adjust sound inside and use this widget everywhere instead of button, ~like

---@class widget.button: druid.widget
local M = {}


function M:init(...)
	self.button = self.druid:new_button(...)
	self.button.on_pressed:subscribe(self.on_pressed)
end


function M:on_pressed()
	-- Play on_pressed sound
end


return M

And create your button with druid:new_widget(button_widget, _, _, ...)

1 Like

Thank you!