Page 1 of 1
Custom sprite-button not firing on_gui_click
Posted: Thu Jul 27, 2023 5:44 am
by NindyBun
I made a "sprite-button" that displays the item icon with related tooltips but the button doesn't fire the on_gui_click event when pressed.

- Everything but the button registers the click event
- button.PNG (675.07 KiB) Viewed 976 times
https://github.com/NindyBun/RefinedNetw ... e.lua#L277
Re: Custom sprite-button not firing on_gui_click
Posted: Thu Jul 27, 2023 10:18 am
by Klonan
Re: Custom sprite-button not firing on_gui_click
Posted: Thu Jul 27, 2023 11:40 am
by NindyBun
Looking at the function I use to make the button, I don't think I set the mouse filter anywhere. It's also the same function I used to make the 'X' close button on the window and that works fine.
Code: Select all
function GuiApi.add_button(guiTable, name, gui, sprite, hoverSprite, clickedSprite, tooltip, size, save, visible, count, style, tags)
if visible == false then return end
if name ~= nil and name ~= "" and guiTable.vars[name] ~= nil then guiTable.vars[name].destroy() end
local button = gui.add{type="sprite-button", name=name, sprite=sprite, hovered_sprite=hoverSprite, clicked_sprite=clickedSprite, resize_to_sprite=false, tooltip=tooltip, number=count, tags=tags}
if style ~= nil then button.style = style end
button.style.minimal_width = size
button.style.maximal_width = size
button.style.minimal_height = size
button.style.maximal_height = size
button.style.padding = 0
button.style.margin = 0
if guiTable ~= nil and save == true then
guiTable.vars[name] = button
end
return button
end
I went ahead and put the filter to see if that solves the problem but it still doesn't.
Re: Custom sprite-button not firing on_gui_click
Posted: Fri Jul 28, 2023 10:11 am
by NindyBun
Okay, I've narrowed the issue to the guiElement#clear function. I have a scroll pane that clears every second and then redraws the necessary guiElements because I need it to refresh. It turns out that if I don't use the clear function, the buttons fire the on_click_event which is great but I need to clear the elements though...
Re: Custom sprite-button not firing on_gui_click
Posted: Sun Jul 30, 2023 7:19 pm
by Rseding91
NindyBun wrote: Fri Jul 28, 2023 10:11 am
Okay, I've narrowed the issue to the guiElement#clear function. I have a scroll pane that clears every second and then redraws the necessary guiElements because I need it to refresh. It turns out that if I don't use the clear function, the buttons fire the on_click_event which is great but I need to clear the elements though...
Store the elements you created and update them as things change. Deleting and re-creating them is not needed.