Common widget methods
As explained in the Intro to Widgets tutorial, all widgets are derived from a base constructor. You will not have to access it or mess with it directly, however it's important to know there are setters and getters (and properties) available that are common to all widgets.
You can browse the full API reference, however the idea of this tutorial is to discuss how to perform the most commonly used widget operations.
In gooey, setters are prefixed with set and getters with get. Anytime you see a setter, there's probably a getter too and viceversa - only specific things have one of the two. Additionally, there are some special methods that are not setters or getters, but rather perform specific operations.
Creating a widget
I wanted to explicitly write a section about creating a widget, to clear any doubts - even though you do not use a method to do this. In gooey you create widgets by using their specific constructors - this is, using the new operator to create one occurrence of the constructor function that is defined.
The list of available constructors as of version 2025.11 is:
| Widget | Constructor name |
|---|---|
| Panel | UIPanel |
| Grid | UIGrid |
| Group | UIGroup |
| Button | UIButton |
| Text | UIText |
| Sprite | UISprite |
| Checkbox | UICheckbox |
| Progress bar | UIProgressBar |
| Drop down / combo box | UIDropDown |
| Option group | UIOptionGroup |
| Slider | UISlider |
| Spinner | UISpinner |
| Text box (text input) | UITextBox |
| Canvas (surface) | UICanvas |
You can check out the individual tutorials for each widget type. Do note that the constructor names are case sensitive, and that the parameters each constructor function takes will vary per widget.
Add the widget to a parent
Method signature
When you create a specific widget using its constructor (e.g. new UIButton(...), like we did in the Positioning and anchor points tutorial), it will be added to the gooey system. However, it will not be rendered unless it is a panel (given that panels are a descendant of the GUI layer itself, not another widget) or it is another type of widget and you add it to a panel (or to another widget already inside a panel).
To add a widget to a parent, you can use the .add() method, calling it from the parent. We already saw an example of this before:
In this example, we are adding the button to the panel, or equivalently, we are setting the panel as the parent widget of the button widget.
Once a widget has a parent, its "coordinates" (the offsets specified) will be calculated relative to its parent and considering the anchor point specified (as discussed in the relevant tutorial). The .add() method is the way to set the structure of your UI and position elements1.
Destroy a widget
Method signature
When you want to get rid of a widget, you can do so by using the .destroy() method. This one is straightforward and forces gooey to remove the widget as well as all of its descendants. So, for example, if you destroy a panel, it will get rid of the panel widget itself and also all of its containing buttons, texts, sprites, etc.
It is important to know that the UI manager object that handles the gooey interactions automatically destroys all panels on its Cleanup event. This is normally what you want, as said manager object is persistent and, thus, normally only gets destroyed when the game ends. This lets GameMaker free up memory used to store gooey components.
Get a widget's ID
Method signature
On the first tutorial we discussed how all widgets have a unique string ID. We can get the ID of a widget by using .getID().
Get or set the widget dimensions
Getting the dimensions
Method signature
This method is super useful and very commonly used. The getter is self-explanatory, but it actually contains a lot more info than is apparent to the naked eye. Apart from the obvious (the offset, width and height, anchor point and parent) it sports additional variables. I want to bring the following to your attention:
| Variable | Description |
|---|---|
offset_x / offset_y |
Returns the widget's specified offset, relative to its parent's anchor point (as explained before) |
x / y |
Returns the widget's top left coordinates, relative to the GUI layer's origin |
x_parent / y_parent |
Returns the widget's top left coordinates, relative to its parent's origin |
The last two pairs of variables are automatically calculated and updated by gooey when you create the widget or change the dimensions of a widget.
Setting the dimensions
Method signature
This allows you to change as many values as you wish from the dimensions of the widget. This proves very useful for a number of use cases - for example, making sure a child element remains the same width as some other widget, or modifying the anchor point dynamically as we did in the Positioning and anchor points tutorial).
Inheriting width or height from the parent
Method signature
Finally, you can set a widget to inherit width and/or height from its parent by calling the setter (or get the corresponding boolean value using the getter). For example, setting inheritance to true in combination with grids, makes it very easy to create buttons on a rectangular arrangement.
Enabling/disabling widgets
Method signature
You can disable widgets to prevent them from registering mouse interactions. When a widget is disabled, you can still see it, but it will not process any events.
Setting visibility of widgets
Method signature
With this setter you can hide or show widgets, without destroying them. For example, you might have a pause menu that only shows up when the player hits the Esc key. Instead of destroying and recreating the menu, yuo can simply hide it and show it.
Setting sprites and images
Method signature
Since gooey is completely sprite based, you will be using these setters frequently. They are self-explanatory. However, it's important to note that some widgets use more than one sprite/image to render. For example, a button will have separate sprites and images for the normal state, the hover state, the click state and the disabled state; or a slider will have one sprite for the "rail" and another sprite for the handle. In this case, there will be specific setters/getters for those. Always use the setters/getters specific to the widget you are using.
Wrapping up
This page briefly explored some of the most frequently used setters, getters and regular methods that are common to all widgets. I deliberately left out a functionality so important that deserves its own page: setting up interactions via callbacks. Let's take a look at how to do this in the next page.
-
If you are adding widgets to grids, there is another (better!) way, using
.addToCell(). Take a look at the Introduction to grids tutorial for more info. ↩