Overview
LibGUI is SerenityOS’s native GUI toolkit providing widgets, windows, layouts, and event handling for building graphical applications. It offers a rich set of controls from basic buttons to complex table views, all with a clean object-oriented API.LibGUI applications automatically integrate with the SerenityOS WindowServer for window management, theming, and input handling.
Getting Started
Application
Every GUI application starts with aGUI::Application instance.
Application Lifecycle
Application Lifecycle
- Create Application:
GUI::Application::create() - Build UI: Create windows and widgets
- Show Windows: Call
window->show() - Run Event Loop: Call
app->exec() - Cleanup: Automatic when app exits
Windows
Window
Top-level window container.String
Window title displayed in title bar
bool
Whether window can be resized by user
bool
If true, blocks interaction with other windows
bool
Fullscreen mode (hides title bar and decorations)
Core Widgets
Widget
Base class for all GUI widgets.Button
Clickable button widget.Label
Text display widget.TextBox & TextEditor
Single-line and multi-line text input.CheckBox & RadioButton
Toggle controls.ComboBox
Dropdown selection widget.Slider & SpinBox
Numeric input controls.Container Widgets
GroupBox
Visual grouping with optional title.Frame
Decorative frame container.TabWidget
Multi-page tabbed interface.SplitterWidget
Resizable split view.Layouts
VerticalBoxLayout & HorizontalBoxLayout
Stack widgets vertically or horizontally.Advanced Widgets
TableView & ListView
Display tabular and list data.TreeView
Hierarchical tree display.Dialogs
MessageBox
Simple message dialogs.FilePicker
File selection dialogs.Actions & Menus
Action
Reusable command with icon, text, and shortcut.Menu & Menubar
Application menus.Events
Event Handling
Override event handlers in custom widgets.Best Practices
Widget Hierarchy
Widget Hierarchy
- Use layouts instead of manual positioning
- Set size constraints (min/max) instead of fixed sizes when possible
- Use spacers to control widget spacing
- Nest layouts for complex UIs
Memory Management
Memory Management
Theming
Theming
- Use semantic colors via
Gfx::ColorRole - Don’t hardcode colors - respect system theme
- Use standard icons from
/res/icons/ - Follow SerenityOS HIG (Human Interface Guidelines)
Related APIs
- LibGfx - Graphics primitives and rendering
- LibCore - Event loop and I/O
- WindowServer - Window management service
