LuaGui.overlay and LuaGuiElement.snap_to()
Posted: Wed Sep 21, 2016 3:37 pm
Ability to create floating panels and align them with other GUI elements. Would be very useful for custom dialogs, drop-downs, etc. For example, we could create re-usable circuit network panels, similar to what the game has, but with our own custom stuff in them.
Would work in much same way as any other panel, only it would appear in a separate 'gui.overlay' layer. The panels default to hidden, but can be shown and aligned with new GUI method such as:
Where `anotherGuiElement` is any visible element for that player and `position` would be things like "bottom-left" (default), "top-right", "center", "bottom-center" etc.
This way, when a button is clicked we could easily show a popup panel aligned to that button, for example:
With styling we could use such a feature to add drop-down menus, color pickers, drop down lists, recipe grids, etc...
Would work in much same way as any other panel, only it would appear in a separate 'gui.overlay' layer. The panels default to hidden, but can be shown and aligned with new GUI method such as:
Code: Select all
local overlay = game.players[somePLayer].gui.overlay
overlay.somePopUp.snap_to( anotherGuiElement, position )
overlay.somePopUp.style.visible = true
This way, when a button is clicked we could easily show a popup panel aligned to that button, for example:
Code: Select all
-- note: could also trigger on custom-input events
script.on_event(defines.events.on_gui_click, function(event)
local popup = game.players[event.player_index].gui.overlay.myPopUp
popup.snap_to( event.element, "bottom-left" )
popup.style.visible = not popup.visible
end )