Custom sprite-button not firing on_gui_click
Custom sprite-button not firing on_gui_click
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. https://github.com/NindyBun/RefinedNetw ... e.lua#L277
Re: Custom sprite-button not firing on_gui_click
Are you setting the mouse filter on the button? https://lua-api.factorio.com/latest/Lua ... ton_filter
Re: Custom sprite-button not firing on_gui_click
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.Klonan wrote: Thu Jul 27, 2023 10:18 am Are you setting the mouse filter on the button? https://lua-api.factorio.com/latest/Lua ... ton_filter
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
Re: Custom sprite-button not firing on_gui_click
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
Store the elements you created and update them as things change. Deleting and re-creating them is not needed.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...
If you want to get ahold of me I'm almost always on Discord.