Application (Mojo)
addEventListener(id: Int, handler: EventHandler)
Registers an event handler for a widget identified by its id
. This function allows you to associate a specific EventHandler
instance with a UI widget, ensuring that when an event (like a click, keypress, or mouse movement) occurs on that widget, the appropriate handler logic is executed. The handler
will only be triggered if the event type defined within the EventHandler
matches the actual event that occurred.
Defined in: mjui/_app.mojo
app.addEventListener(1, handler)
setElementById(id: Int, element: FLTK_WIDGET_POINTER)
Associates a raw FLTK widget pointer (FLTK_WIDGET_POINTER
) with a unique integer id
. This mapping is crucial for managing UI elements dynamically. By assigning a simple integer ID, you can easily retrieve, update, or manipulate specific widgets throughout your application without needing to hold onto the raw FLTK pointer directly.
Defined in: mjui/_app.mojo
app.setElementById(22, label)
getElementById(id: Int) -> FLTK_WIDGET_POINTER
Retrieves the FLTK_WIDGET_POINTER
associated with a given integer id
. This function acts as a lookup mechanism, allowing your Mojo code to get a reference to an underlying FLTK widget based on the ID previously set with setElementById
. This is fundamental for performing operations on specific UI components.
Defined in: mjui/_app.mojo
var label = app.getElementById(22)
markWindowPTRAsMain(ptr: FLTK_WIDGET_POINTER)
Designates a specific FLTK window pointer (ptr
) as the main application window. This is important for the application's lifecycle management. The internal event loop will monitor this designated window for close events, and once it detects that this main window has been closed by the user, the application will gracefully terminate.
Defined in: mjui/_app.mojo
app.markWindowPTRAsMain(window)
attachLoopHook(hook: fn() raises)
Attaches a callable function (hook
) to the application's main event loop. This mechanism allows you to inject custom logic that needs to be executed continuously on every iteration of the event loop. This is useful for tasks such as updating game states, performing animations, background processing, or any other operations that require regular execution while the UI is active.
Defined in: mjui/_app.mojo
app.attachLoopHook(my_hook)
execute()
Starts the main FLTK event loop. Calling this function initiates the continuous polling for and processing of UI events. It enters an infinite loop, constantly checking for user interactions (mouse clicks, keypresses, window events), dispatching them to any registered EventHandler
s, and executing any attached loop hooks. The application will remain responsive and active until the designated main window is closed or an explicit exit signal is received, at which point the loop terminates.
Defined in: mjui/_app.mojo
app.execute()
EventHandler (Mojo)
set(trigger: Int, handler: Handler)
Sets both the trigger event type (trigger
) and the handler function (handler
) for this EventHandler
. This function provides a convenient way to configure an event handler, specifying precisely which type of event it should respond to and what action it should take when that event occurs.
Defined in: mjui/EventHandler.mojo
handler.set(MJUI_KEYDOWN, my_handler)
attachHandler(handler: Handler)
Sets the handler function (handler
) that will be executed when the associated event is triggered. This allows you to define the specific code block or logic that should run in response to an event, separating the event detection from the action to be performed.
Defined in: mjui/EventHandler.mojo
handler.attachHandler(my_handler)
attachTrigger(trigger: Int)
Sets the integer trigger
event type that this EventHandler
will respond to. By setting the trigger, you define which specific UI event (e.g., a button click, a key press) will cause this event handler to become active and execute its attached function.
Defined in: mjui/EventHandler.mojo
handler.attachTrigger(MJUI_KEYDOWN)
trigger()
Executes the currently attached handler function. This function is typically called internally by the event loop when an event matching the `trigger` is detected for the associated widget. You can also call it manually to programmatically invoke the handler's logic.
Defined in: mjui/EventHandler.mojo
handler.trigger()
Utility Functions (Mojo)
rgb(r: UInt32, g: UInt32, b: UInt32) -> UInt32
Converts individual red, green, and blue color components (each ranging from 0-255) into a single 32-bit unsigned integer. This packed integer format is the standard color representation used by FLTK (Fast Light Toolkit) and is essential when setting widget colors or drawing custom graphics.
Defined in: mjui/utils.mojo
var color = rgb(255, 128, 0)
str_to_int8(str: String) -> List[Int8]
Converts a Mojo String
into a List
of Int8
(ASCII character codes). This utility is vital for interoperability with C++ FFI (Foreign Function Interface) functions, which often expect string data to be provided as a null-terminated byte array. This function correctly transforms Mojo strings into this compatible format.
Defined in: mjui/utils.mojo
var ascii_codes = str_to_int8("Hello")
readFromStringBytes(bytes: StringBytes) -> String
Converts a StringBytes
span (a low-level byte array representation, typically received from C++ FFI functions) back into a human-readable Mojo String
. The function intelligently reads the byte array until it encounters a null terminator, ensuring that only the relevant string data is converted.
Defined in: mjui/utils.mojo
var s = readFromStringBytes(bytes)
createIdFrom(id: String) -> Int
Generates a simple integer ID from a given String
. This is achieved by summing the ASCII character codes of the input string. While this method provides a quick and convenient way to get a unique identifier for widgets, it is important to note that it is not collision-proof for all possible string inputs and should be used where strict uniqueness guarantees are not paramount.
Defined in: mjui/utils.mojo
var widget_id = createIdFrom("button1")
convertStringToBytes(strn: String) -> StringBytes
Converts a Mojo String
into a StringBytes
span. This low-level byte representation is specifically designed for efficient and safe passing of string data to C++ FFI functions. It ensures that the string data is correctly formatted for consumption by the underlying C++ libraries.
Defined in: mjui/utils.mojo
var bytes = convertStringToBytes("Label")
Constants (Mojo)
Event Types
Event types used for widget and application event handling.
Name | Value | Description | Defined In |
---|---|---|---|
MJUI_NO_EVENT | 0 | Represents the absence of an event. This value is used when no specific UI interaction or system event has occurred. | mjui/const.mojo |
MJUI_PUSH | 1 | Indicates a mouse button or a similar input device button has been pressed down. This event is commonly used for clickable widgets like buttons. | mjui/const.mojo |
MJUI_RELEASE | 2 | Signifies that a mouse button or a similar input device button has been released after being pressed. It often follows a MJUI_PUSH event. | mjui/const.mojo |
MJUI_ENTER | 3 | Occurs when the mouse cursor enters the bounding box of a widget. Useful for hover effects or changing widget appearance upon mouse entry. | mjui/const.mojo |
MJUI_LEAVE | 4 | Triggers when the mouse cursor leaves the bounding box of a widget. Typically used to revert changes made during an MJUI_ENTER event. | mjui/const.mojo |
MJUI_DRAG | 5 | Generated when the mouse cursor is moved while a mouse button is held down. Essential for drag-and-drop functionalities or drawing applications. | mjui/const.mojo |
MJUI_FOCUS | 6 | Indicates that a widget has gained input focus, meaning it is ready to receive keyboard input. This happens when a user clicks on an input field or tabs to it. | mjui/const.mojo |
MJUI_UNFOCUS | 7 | Occurs when a widget loses input focus, typically when another widget gains focus or the user clicks outside the widget. | mjui/const.mojo |
MJUI_KEYDOWN / MJUI_KEYBOARD | 8 | Fired when a keyboard key is pressed down. Note: MJUI_KEYDOWN and MJUI_KEYBOARD are aliases for the same event type (value 8). | mjui/const.mojo |
MJUI_KEYUP | 9 | Generated when a keyboard key is released after being pressed. This complements MJUI_KEYDOWN for full key press detection. | mjui/const.mojo |
MJUI_CLOSE | 10 | Signifies that a widget or window is being closed. This is particularly important for window management to perform cleanup operations. | mjui/const.mojo |
MJUI_MOVE | 11 | Indicates that a widget has been moved on the screen, typically by user interaction or programmatic changes to its position. | mjui/const.mojo |
MJUI_SHORTCUT | 12 | Triggered when a keyboard shortcut is activated. This allows for quick access to specific application functionalities. | mjui/const.mojo |
MJUI_DEACTIVATE | 13 | Occurs when a widget becomes inactive or disabled, meaning it can no longer receive input or interact with the user. | mjui/const.mojo |
MJUI_ACTIVATE | 14 | Fired when a widget becomes active or re-enabled, allowing it to receive user input and interactions again. | mjui/const.mojo |
MJUI_HIDE | 15 | Indicates that a widget has been hidden from view. The widget still exists but is not rendered on the screen. | mjui/const.mojo |
MJUI_SHOW | 16 | Occurs when a previously hidden widget becomes visible again. | mjui/const.mojo |
MJUI_PASTE | 17 | Generated when content is pasted into an input field or a widget that supports paste operations. | mjui/const.mojo |
MJUI_SELECTIONCLEAR | 18 | Fired when any current text selection within a widget is cleared. | mjui/const.mojo |
MJUI_MOUSEWHEEL | 19 | Triggered when the mouse scroll wheel is used. This is commonly used for scrolling content within a scrollable area or zooming. | mjui/const.mojo |
MJUI_DND_ENTER | 20 | Indicates that a drag-and-drop operation has entered the bounding box of a widget. | mjui/const.mojo |
MJUI_DND_DRAG | 21 | Occurs when a drag-and-drop operation is actively being dragged over a widget. | mjui/const.mojo |
MJUI_DND_LEAVE | 22 | Fired when a drag-and-drop operation leaves the bounding box of a widget. | mjui/const.mojo |
MJUI_DND_RELEASE | 23 | Triggered when a drag-and-drop operation is released over a widget, signaling a potential drop. | mjui/const.mojo |
MJUI_SCREEN_CONFIGURATION_CHANGED | 24 | Occurs when the screen configuration (e.g., resolution, display settings) changes. | mjui/const.mojo |
MJUI_FULLSCREEN | 25 | Indicates that a window has entered or exited fullscreen mode. | mjui/const.mojo |
MJUI_ZOOM_GESTURE | 26 | Generated by a zoom gesture, typically on touch-enabled devices. | mjui/const.mojo |
MJUI_ZOOM_EVENT | 27 | A generic zoom event, which can be triggered by various input methods. | mjui/const.mojo |
handler.attachTrigger(MJUI_PUSH)
Cursor Types
Cursor types for widgets and windows.
Name | Value | Description | Defined In |
---|---|---|---|
MJUI_CURSOR_DEFAULT | 0 | The default cursor, typically an arrow. | mjui/const.mojo |
MJUI_CURSOR_ARROW | 35 | A standard arrow cursor, used for general pointing and clicking. | mjui/const.mojo |
MJUI_CURSOR_CROSS | 66 | A crosshair cursor, often used for drawing or selecting precise points. | mjui/const.mojo |
MJUI_CURSOR_WAIT | 76 | An hourglass or spinning circle cursor, indicating that the application is busy and the user should wait. | mjui/const.mojo |
MJUI_CURSOR_INSERT | 77 | A text insertion cursor (I-beam), used for text input fields. | mjui/const.mojo |
MJUI_CURSOR_HAND | 31 | A hand cursor, typically used to indicate a clickable or draggable element. | mjui/const.mojo |
MJUI_CURSOR_HELP | 47 | A cursor with a question mark, indicating that help is available for the element under the cursor. | mjui/const.mojo |
MJUI_CURSOR_MOVE | 27 | A four-directional arrow cursor, used to indicate that an element can be moved in any direction. | mjui/const.mojo |
MJUI_CURSOR_NS | 78 | A vertical double-headed arrow, used for resizing elements vertically (North-South). | mjui/const.mojo |
MJUI_CURSOR_WE | 79 | A horizontal double-headed arrow, used for resizing elements horizontally (West-East). | mjui/const.mojo |
MJUI_CURSOR_NWSE | 80 | A diagonal double-headed arrow (North-West to South-East), used for diagonal resizing. | mjui/const.mojo |
MJUI_CURSOR_NESW | 81 | A diagonal double-headed arrow (North-East to South-West), used for diagonal resizing. | mjui/const.mojo |
MJUI_CURSOR_N | 70 | An arrow pointing North (up), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_NE | 69 | An arrow pointing North-East (up-right), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_E | 49 | An arrow pointing East (right), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_SE | 8 | An arrow pointing South-East (down-right), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_S | 9 | An arrow pointing South (down), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_SW | 7 | An arrow pointing South-West (down-left), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_W | 36 | An arrow pointing West (left), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_NW | 68 | An arrow pointing North-West (up-left), used for resizing. | mjui/const.mojo |
MJUI_CURSOR_NONE | 255 | An invisible cursor, used when no cursor should be displayed. | mjui/const.mojo |
Layout Flags
Layout direction and resize flags for flex layouts.
Name | Value | Description | Defined In |
---|---|---|---|
MJUI_MJUIEX_HORIZONTAL | 1 | Specifies that a flex layout container should arrange its child widgets horizontally, from left to right. | mjui/const.mojo |
MJUI_MJUIEX_VERTICAL | 0 | Specifies that a flex layout container should arrange its child widgets vertically, from top to bottom. | mjui/const.mojo |
RESIZE_XY | 100 | Indicates that a widget or layout should be resizable in both horizontal (X) and vertical (Y) directions. | mjui/const.mojo |
RESIZE_XONLY | 110 | Indicates that a widget or layout should only be resizable in the horizontal (X) direction. | mjui/const.mojo |
RESIZE_YONLY | 111 | Indicates that a widget or layout should only be resizable in the vertical (Y) direction. | mjui/const.mojo |
Box Types
Box types for widget backgrounds and borders.
Name | Value | Description | Defined In |
---|---|---|---|
MJUI_FLAT_BOX | 1 | A simple, flat box with no 3D appearance, often used for clean, modern interfaces. | mjui/const.mojo |
MJUI_UP_BOX | 2 | A box type that appears raised or extruding from the surface, creating a 3D button-like effect. | mjui/const.mojo |
MJUI_DOWN_BOX | 3 | A box type that appears sunken or recessed into the surface, often used to indicate a pressed state or an input field. | mjui/const.mojo |
MJUI_UP_FRAME | 4 | A raised frame border, similar to MJUI_UP_BOX but typically without a filled background. | mjui/const.mojo |
MJUI_DOWN_FRAME | 5 | A sunken frame border, similar to MJUI_DOWN_BOX but typically without a filled background. | mjui/const.mojo |
MJUI_THIN_UP_BOX | 6 | A thinner version of MJUI_UP_BOX , providing a subtle raised effect. | mjui/const.mojo |
MJUI_THIN_DOWN_BOX | 7 | A thinner version of MJUI_DOWN_BOX , providing a subtle sunken effect. | mjui/const.mojo |
MJUI_THIN_UP_FRAME | 8 | A thinner version of MJUI_UP_FRAME . | mjui/const.mojo |
MJUI_THIN_DOWN_FRAME | 9 | A thinner version of MJUI_DOWN_FRAME . | mjui/const.mojo |
MJUI_ENGRAVED_BOX | 10 | A box with an engraved appearance, making the content seem carved into the surface. | mjui/const.mojo |
MJUI_EMBOSSED_BOX | 11 | A box with an embossed appearance, making the content seem raised from the surface. | mjui/const.mojo |
MJUI_ENGRAVED_FRAME | 12 | An engraved frame, similar to MJUI_ENGRAVED_BOX but typically without a filled background. | mjui/const.mojo |
MJUI_EMBOSSED_FRAME | 13 | An embossed frame, similar to MJUI_EMBOSSED_BOX but typically without a filled background. | mjui/const.mojo |
MJUI_BORDER_BOX | 14 | A box with a simple border around its perimeter. | mjui/const.mojo |
MJUI_SHADOW_BOX | 15 | A box with a shadow effect, giving it a lifted appearance. | mjui/const.mojo |
MJUI_BORDER_FRAME | 16 | A simple border frame without a filled background. | mjui/const.mojo |
MJUI_SHADOW_FRAME | 17 | A frame with a shadow effect. | mjui/const.mojo |
MJUI_ROUNDED_BOX | 18 | A box with rounded corners, providing a softer aesthetic. | mjui/const.mojo |
MJUI_RSHADOW_BOX | 19 | A rounded box with a shadow effect. | mjui/const.mojo |
MJUI_ROUNDED_FRAME | 20 | A rounded frame without a filled background. | mjui/const.mojo |
MJUI_RFLAT_BOX | 21 | A rounded, flat box. | mjui/const.mojo |
MJUI_ROUND_UP_BOX | 22 | A rounded box with a raised appearance. | mjui/const.mojo |
MJUI_ROUND_DOWN_BOX | 23 | A rounded box with a sunken appearance. | mjui/const.mojo |
MJUI_DIAMOND_UP_BOX | 24 | A diamond-shaped box with a raised appearance. | mjui/const.mojo |
MJUI_DIAMOND_DOWN_BOX | 25 | A diamond-shaped box with a sunken appearance. | mjui/const.mojo |
MJUI_OVAL_BOX | 26 | An oval-shaped box. | mjui/const.mojo |
MJUI_OSHADOW_BOX | 27 | An oval-shaped box with a shadow effect. | mjui/const.mojo |
MJUI_OVAL_FRAME | 28 | An oval-shaped frame. | mjui/const.mojo |
MJUI_OFLAT_BOX | 29 | An oval, flat box. | mjui/const.mojo |
MJUI_PLASTIC_UP_BOX | 30 | A box with a plastic-like raised appearance. | mjui/const.mojo |
MJUI_PLASTIC_DOWN_BOX | 31 | A box with a plastic-like sunken appearance. | mjui/const.mojo |
MJUI_PLASTIC_UP_FRAME | 32 | A plastic-like raised frame. | mjui/const.mojo |
MJUI_PLASTIC_DOWN_FRAME | 33 | A plastic-like sunken frame. | mjui/const.mojo |
MJUI_PLASTIC_THIN_UP_BOX | 34 | A thin plastic-like raised box. | mjui/const.mojo |
MJUI_PLASTIC_THIN_DOWN_BOX | 35 | A thin plastic-like sunken box. | mjui/const.mojo |
MJUI_PLASTIC_THIN_UP_FRAME | 36 | A thin plastic-like raised frame. | mjui/const.mojo |
MJUI_PLASTIC_THIN_DOWN_FRAME | 37 | A thin plastic-like sunken frame. | mjui/const.mojo |
MJUI_PLASTIC_ROUND_UP_BOX | 38 | A rounded plastic-like raised box. | mjui/const.mojo |
MJUI_PLASTIC_ROUND_DOWN_BOX | 39 | A rounded plastic-like sunken box. | mjui/const.mojo |
MJUI_GTK_UP_BOX | 40 | A box style resembling the GTK+ toolkit's raised elements. | mjui/const.mojo |
MJUI_GTK_DOWN_BOX | 41 | A box style resembling the GTK+ toolkit's sunken elements. | mjui/const.mojo |
MJUI_GTK_UP_FRAME | 42 | A GTK+ style raised frame. | mjui/const.mojo |
MJUI_GTK_DOWN_FRAME | 43 | A GTK+ style sunken frame. | mjui/const.mojo |
MJUI_GTK_THIN_UP_BOX | 44 | A thin GTK+ style raised box. | mjui/const.mojo |
MJUI_GTK_THIN_DOWN_BOX | 45 | A thin GTK+ style sunken box. | mjui/const.mojo |
MJUI_GTK_THIN_UP_FRAME | 46 | A thin GTK+ style raised frame. | mjui/const.mojo |
MJUI_GTK_THIN_DOWN_FRAME | 47 | A thin GTK+ style sunken frame. | mjui/const.mojo |
MJUI_GTK_ROUND_UP_BOX | 48 | A rounded GTK+ style raised box. | mjui/const.mojo |
MJUI_GTK_ROUND_DOWN_BOX | 49 | A rounded GTK+ style sunken box. | mjui/const.mojo |
MJUI_GLEAM_UP_BOX | 50 | A box with a gleam-like raised appearance. | mjui/const.mojo |
MJUI_GLEAM_DOWN_BOX | 51 | A box with a gleam-like sunken appearance. | mjui/const.mojo |
MJUI_GLEAM_UP_FRAME | 52 | A gleam-like raised frame. | mjui/const.mojo |
MJUI_GLEAM_DOWN_FRAME | 53 | A gleam-like sunken frame. | mjui/const.mojo |
MJUI_GLEAM_THIN_UP_BOX | 54 | A thin gleam-like raised box. | mjui/const.mojo |
MJUI_GLEAM_THIN_DOWN_BOX | 55 | A thin gleam-like sunken box. | mjui/const.mojo |
MJUI_GLEAM_ROUND_UP_BOX | 56 | A rounded gleam-like raised box. | mjui/const.mojo |
MJUI_GLEAM_ROUND_DOWN_BOX | 57 | A rounded gleam-like sunken box. | mjui/const.mojo |
MJUI_OXY_UP_BOX | 58 | A box with an Oxygen-like (KDE Plasma) raised appearance. | mjui/const.mojo |
MJUI_OXY_DOWN_BOX | 59 | A box with an Oxygen-like (KDE Plasma) sunken appearance. | mjui/const.mojo |
MJUI_OXY_UP_FRAME | 60 | An Oxygen-like raised frame. | mjui/const.mojo |
MJUI_OXY_DOWN_FRAME | 61 | An Oxygen-like sunken frame. | mjui/const.mojo |
MJUI_OXY_THIN_UP_BOX | 62 | A thin Oxygen-like raised box. | mjui/const.mojo |
MJUI_OXY_THIN_DOWN_BOX | 63 | A thin Oxygen-like sunken box. | mjui/const.mojo |
MJUI_OXY_THIN_UP_FRAME | 64 | A thin Oxygen-like raised frame. | mjui/const.mojo |
MJUI_OXY_THIN_DOWN_FRAME | 65 | A thin Oxygen-like sunken frame. | mjui/const.mojo |
MJUI_OXY_ROUND_UP_BOX | 66 | A rounded Oxygen-like raised box. | mjui/const.mojo |
MJUI_OXY_ROUND_DOWN_BOX | 67 | A rounded Oxygen-like sunken box. | mjui/const.mojo |
MJUI_OXY_BUTTON_UP_BOX | 68 | An Oxygen-like raised button box. | mjui/const.mojo |
MJUI_OXY_BUTTON_DOWN_BOX | 69 | An Oxygen-like sunken button box. | mjui/const.mojo |
MJUI_FREE_BOXTYPE | 70 | A free box type, which can be customized. | mjui/const.mojo |
MJUI_MAX_BOXTYPE | 255 | Represents the maximum value for box type constants. | mjui/const.mojo |
Label Types
Label rendering types for widgets.
Name | Value | Description | Defined In |
---|---|---|---|
MJUI_LABEL_TYPE_NORMAL | 0 | Standard text rendering. | mjui/const.mojo |
MJUI_LABEL_TYPE_SHADOW | 1 | Renders text with a shadow effect, adding depth. | mjui/const.mojo |
MJUI_LABEL_TYPE_EMBOSSED | 2 | Renders text with an embossed effect, making it appear raised. | mjui/const.mojo |
MJUI_LABEL_TYPE_MULTI | 3 | Enables multi-line text rendering, allowing text to wrap within the widget's bounds. | mjui/const.mojo |
MJUI_LABEL_TYPE_IMAGE | 4 | Specifies that the label should display an image instead of text. | mjui/const.mojo |
Image Types
Image format constants for loading images.
Name | Value | Description | Defined In |
---|---|---|---|
PNG | 0 | Specifies the Portable Network Graphics (PNG) image format, known for lossless compression and support for transparency. | mjui/const.mojo |
JPEG | 1 | Specifies the Joint Photographic Experts Group (JPEG) image format, commonly used for photographs due to its lossy compression. | mjui/const.mojo |
SVG | 2 | Specifies the Scalable Vector Graphics (SVG) format, an XML-based vector image format for two-dimensional graphics with support for interactivity and animation. | mjui/const.mojo |
BMP | 3 | Specifies the Bitmap (BMP) image format, a raster graphics image file format used to store bitmap digital images. | mjui/const.mojo |
GIF | 4 | Specifies the Graphics Interchange Format (GIF), known for its support of both static and animated images with a limited color palette. | mjui/const.mojo |
ANIM_GIF | 5 | Specifically denotes an animated GIF image format, allowing for multiple frames to be displayed in sequence. | mjui/const.mojo |
Alignment
Alignment options for text and widgets.
Name | Value | Description | Defined In |
---|---|---|---|
ALIGN_CENTER | 0 | Aligns content to the center of the widget's bounding box. | mjui/const.mojo |
ALIGN_TOP | 1 | Aligns content to the top of the widget's bounding box. | mjui/const.mojo |
ALIGN_BOTTOM | 2 | Aligns content to the bottom of the widget's bounding box. | mjui/const.mojo |
ALIGN_LEFT | 3 | Aligns content to the left of the widget's bounding box. | mjui/const.mojo |
ALIGN_RIGHT | 4 | Aligns content to the right of the widget's bounding box. | mjui/const.mojo |
ALIGN_INSIDE | 5 | Aligns content within the widget's interior, respecting padding. | mjui/const.mojo |
ALIGN_CLIP | 6 | Clips content that extends beyond the widget's boundaries. | mjui/const.mojo |
ALIGN_WRAP | 7 | Wraps text content to multiple lines if it exceeds the widget's width. | mjui/const.mojo |
TEXT_OVER_IMAGE | 8 | Displays text content over an image within the same widget. | mjui/const.mojo |
IMAGE_OVER_TEXT | 9 | Displays an image over text content within the same widget. | mjui/const.mojo |
Visual Schemes
See useSchemeVisual style schemes for the UI.
Name | Value | Defined In |
---|---|---|
GTK | 0 | mjui/utils.mojo |
GLEAM | 1 | mjui/utils.mojo |
PLASTIC | 2 | mjui/utils.mojo |
useScheme(GTK)
getEventNameFromNum(num: Int) -> String
Returns the string name corresponding to an integer event type number. This utility function is helpful for debugging and logging event information.
Defined in: mjui/const.mojo
var name = getEventNameFromNum(1) # "MJUI_PUSH"
FFI Bindings (Mojo/C++)
Widget Management
mjuiGrabEvent() -> int64_t
Retrieves the next event from the event queue. The returned int64_t
combines the widget ID and event type. Returns -2 if no event is available.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
var event = mjuiGrabEvent()
mjuiShowWidget(widget)
Makes the given FLTK widget
visible.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiShowWidget(my_button)
mjuiHideWidget(widget)
Hides the given FLTK widget
.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiHideWidget(my_label)
mjuiRedraw(widget)
Forces the given FLTK widget
to redraw itself immediately, updating its appearance on the screen.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiRedraw(my_input)
mjuiSetWidgetColor(widget, color)
Sets the background color of the specified FLTK widget
.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiSetWidgetColor(my_button, rgb(255, 0, 0))
mjuiSetWidgetTextColor(widget, color)
Sets the color of the text label for the specified FLTK widget
.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiSetWidgetTextColor(my_label, rgb(0, 0, 0))
mjuiSetWidgetSelectionColor(widget, color)
Sets the selection color for the FLTK widget
, typically used for highlighting selected text in input fields or selected items in lists.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiSetWidgetSelectionColor(my_input, rgb(0, 128, 255))
mjuiSetWidgetBox(widget, box)
Applies a specific box type (Fl_Boxtype
) to the FLTK widget
, defining its border and background style.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiSetWidgetBox(my_button, MJUI_FLAT_BOX)
mjuiSetWidgetLabel(widget, label)
Sets the text label
for the specified FLTK widget
.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiSetWidgetLabel(my_label, convertStringToBytes("New Label"))
BEGIN_WIDGET_APPEND(group)
Marks the beginning of adding child widgets to an FLTK group
widget.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
BEGIN_WIDGET_APPEND(my_layout)
// Add widgets here
END_WIDGET_APPEND(my_layout)
END_WIDGET_APPEND(group)
Marks the end of adding child widgets to an FLTK group
widget.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
END_WIDGET_APPEND(my_layout)
mjuiGetWidgetHeight(widget)
Returns the current height of the specified FLTK widget
in pixels.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
var h = mjuiGetWidgetHeight(my_button)
mjuiGetWidgetWidth(widget)
Returns the current width of the specified FLTK widget
in pixels.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
var w = mjuiGetWidgetWidth(my_label)
mjuiWindowSetResizable(window, widget)
Makes a specific widget
within an Fl_Window
resizable, allowing it to adapt to window resizing.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiWindowSetResizable(my_window, my_layout)
mjuiApplyImage(widget, image)
Applies an Fl_Image
to an FLTK widget
, typically used for buttons, labels, or custom drawing areas.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
var img = mjuiLoadImg(100, 100, PNG, convertStringToBytes("logo.png"))
mjuiApplyImage(my_label, img)
mjuiImageScale(img, width, height, proportional)
Scales an Fl_Image
to the desired width
and height
. If proportional
is 1
, the image will be scaled maintaining its aspect ratio.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
mjuiImageScale(img, 200, 200, 1)
Window Management
mjuiCreateWindow(width, height, resize, fullscreen, no_border, title_r)
Creates a new FLTK Fl_Double_Window
with specified width
, height
, and options for resize
ability, fullscreen
mode, no_border
, and a title
.
Defined in: mjui/fltk_bindings/libc/Window/MJUIWindow.cc
var window = mjuiCreateWindow(800, 600, 1, 0, 0, convertStringToBytes("My App"))
mjuiWindowTitleSet(window, new_title_r)
Sets the title of the given Fl_Double_Window
to new_title_r
.
Defined in: mjui/fltk_bindings/libc/Window/MJUIWindow.cc
mjuiWindowTitleSet(window, convertStringToBytes("New Title"))
mjuiWindowVisibilityStatus(window, condition)
Returns the visibility status of the window
. condition
can be WINDOW_VISIBLE
(0) or WINDOW_MINIMIZED
(1). Returns 1 if true, 0 if false, -1 if condition is invalid.
Defined in: mjui/fltk_bindings/libc/Window/MJUIWindow.cc
var is_visible = mjuiWindowVisibilityStatus(window, 0) # 0 = WINDOW_VISIBLE
mjuiWindowPositionSet(window, x, y)
Sets the top-left position of the Fl_Double_Window
on the screen to (x, y)
.
Defined in: mjui/fltk_bindings/libc/Window/MJUIWindow.cc
mjuiWindowPositionSet(window, 100, 100)
Button & Input Widgets
mjuiCreateButton(x, y, w, h, id, label_r)
Creates a new custom FLTK Button
widget at (x, y)
with specified width
, height
, id
, and a label
.
Defined in: mjui/fltk_bindings/libc/Button/MJUIButton.cc
var button = mjuiCreateButton(100, 30, 10, 10, 1, convertStringToBytes("Click Me"))
mjuiCreateCheckButton(x, y, w, h, id, label_r)
Creates a new custom FLTK MJUI_CheckButton
widget at (x, y)
with specified width
, height
, id
, and a label
.
Defined in: mjui/fltk_bindings/libc/Button/MJUIButton.cc
var check = mjuiCreateCheckButton(100, 30, 10, 50, 2, convertStringToBytes("Check Me"))
mjuiCheckButtonGetState(checkButton)
Returns the current state of a MJUI_CheckButton
(1 if checked, 0 if unchecked).
Defined in: mjui/fltk_bindings/libc/Button/MJUIButton.cc
var state = mjuiCheckButtonGetState(check)
mjuiCreateInput(x, y, w, h, id, numOnly, label_r)
Creates a single-line Input
field. numOnly
(1 for numeric only, 0 for any text) and label
(placeholder) are configurable.
Defined in: mjui/fltk_bindings/libc/Input/MJUIInput.cc
var input = mjuiCreateInput(10, 90, 200, 30, 3, 0, convertStringToBytes("Enter text..."))
mjuiCreateChoice(x, y, w, h)
Creates a select dropdown. Options can be added using mjuiAddOptionToChoice
Defined in: mjui/fltk_bindings/libc/Input/MJUIInput.cc
var input = mjuiCreateInput(10, 90, 200, 30, 3, 0, convertStringToBytes("Enter text..."))
mjuiCreateMultilineInput(x, y, w, h, id, label_r)
Creates a multiline MultiLineInput
field with a placeholder label
.
Defined in: mjui/fltk_bindings/libc/Input/MJUIInput.cc
var multi = mjuiCreateMultilineInput(10, 130, 200, 60, 4, convertStringToBytes("Multiline..."))
mjuiSetInputValue(input, value)
Sets the current value
(text) of an FLTK Fl_Input
widget.
Defined in: mjui/fltk_bindings/libc/Input/MJUIInput.cc
mjuiSetInputValue(input, convertStringToBytes("Hello"))
mjuiGrabInput(input) -> StringBytes
Gets the current value
(text) of an FLTK Fl_Input
widget.
Defined in: mjui/fltk_bindings/libc/Input/MJUIInput.cc
var bytes = mjuiGrabInput(input)
var str = readFromStringBytes(bytes) # This is necessary since grab input returns bytes
mjuiGrabChoice(input) -> Int
Gets the current index
(text) of the selected option in FLTK Fl_Choice
widget.
Defined in: mjui/fltk_bindings/libc/Input/MJUIInput.cc
var bytes = mjuiGrabChoice(input)
var str = readFromStringBytes(bytes) # This is necessary since grab input returns bytes
Label & Image Widgets
mjuiCreateLabel(x, y, width, height, id, text)
Creates a new custom FLTK MJUILabel
widget at (x, y)
with specified width
, height
, id
, and text
.
Defined in: mjui/fltk_bindings/libc/Label/MJUILabel.cc
var label = mjuiCreateLabel(10, 10, 200, 30, 5, convertStringToBytes("Hello World"))
mjuiSetTextProperties(label, size, color, type)
Sets the font size
, color
, and type
(MJUI_LABEL_TYPE_NORMAL
, etc.) of the text for an MJUILabel
.
Defined in: mjui/fltk_bindings/libc/Label/MJUILabel.cc
mjuiSetTextProperties(label, 14, rgb(0, 0, 0), MJUI_LABEL_TYPE_NORMAL)
mjuiTextAlign(label, alignment)
Sets the text alignment
within an MJUILabel
.
Defined in: mjui/fltk_bindings/libc/Label/MJUILabel.cc
mjuiTextAlign(label, ALIGN_CENTER)
mjuiLoadImg(width, height, imgType, path)
Loads an image from the specified path
with desired width
, height
, and imgType
(e.g., PNG
, JPEG
, SVG
, GIF
, ANIM_GIF
). Returns an Fl_Image
pointer.
Defined in: mjui/fltk_bindings/libc/Label/MJUILabel.cc
var img = mjuiLoadImg(100, 100, PNG, convertStringToBytes("logo.png"))
Layouts & Containers
mjuiCreateLayoutFlex(x, y, w, h, dir)
Creates a new FLTK MJUI_Flex
layout container at (x, y)
with specified width
, height
, and layout dir
ection (MJUI_MJUIEX_HORIZONTAL
or MJUI_MJUIEX_VERTICAL
).
Defined in: mjui/fltk_bindings/libc/Layout/MJUILayouts.cc
var layout = mjuiCreateLayoutFlex(0, 0, 800, 600, MJUI_MJUIEX_VERTICAL)
mjuiSetFlexResize(l, r)
Sets the resize direction
for a MJUI_Flex
layout. r
is RESIZE_XY
, RESIZE_XONLY
, or RESIZE_YONLY
.
Defined in: mjui/fltk_bindings/libc/Layout/MJUILayouts.cc
mjuiSetFlexResize(layout, RESIZE_XY)
mjuiSetFlexMarginGapSettings(l, margin, gap)
Sets the margin
(spacing around the layout) and gap
(spacing between child widgets) for a MJUI_Flex
layout. Pass -1 for either to keep current value.
Defined in: mjui/fltk_bindings/libc/Layout/MJUILayouts.cc
mjuiSetFlexMarginGapSettings(layout, 10, 5)
mjuiSetFlex(l, w, span)
Sets the flex span
for a specific widget
within a MJUI_Flex
layout. The span
determines how much space the widget occupies relative to other flex items.
Defined in: mjui/fltk_bindings/libc/Layout/MJUILayouts.cc
mjuiSetFlex(layout, my_button, 2)
mjuiSetMarginExplicit(l, left, top, right, bottom)
Sets explicit left
, top
, right
, and bottom
margins for a MJUI_Flex
layout.
Defined in: mjui/fltk_bindings/libc/Layout/MJUILayouts.cc
mjuiSetMarginExplicit(layout, 5, 5, 5, 5)
mjuiFlexCalculateLayout(l)
Forces the MJUI_Flex
layout to recalculate and apply its child widget positions and sizes based on its current properties.
Defined in: mjui/fltk_bindings/libc/Layout/MJUILayouts.cc
mjuiFlexCalculateLayout(layout)
mjuiScrollContainer(x, y, w, h)
Creates a new Fl_Scroll
container widget at (x, y)
with specified width
and height
, enabling scrollability for its children.
Defined in: mjui/fltk_bindings/libc/Layout/Containers.cc
var scroll = mjuiScrollContainer(0, 0, 400, 300)
mjuiScrollSetBarBGColor(s, c, sbar)
Sets the background color
of the scroll bar for an Fl_Scroll
container. sbar
selects which scroll bar: 0 for vertical, 1 for horizontal, 2 for both.
Defined in: mjui/fltk_bindings/libc/Layout/Containers.cc
mjuiScrollSetBarBGColor(scroll, rgb(220, 220, 220), 0)
mjuiScrollSetBarFGColor(s, c, sbar)
Sets the foreground color of the scroll bar for an Fl_Scroll
container. sbar
selects which scroll bar: 0 for vertical, 1 for horizontal, 2 for both.
Defined in: mjui/fltk_bindings/libc/Layout/Containers.cc
mjuiScrollSetBarFGColor(scroll, rgb(100, 100, 100), 0)
mjuiScrollBy(s, x, y)
Scrolls the Fl_Scroll
container by x
pixels horizontally and y
pixels vertically from its current position.
Defined in: mjui/fltk_bindings/libc/Layout/Containers.cc
mjuiScrollBy(scroll, 0, 50) # Scrolls down by 50 pixels
Event Loop & Utility
mjuiGrabEvent() -> int64_t
Retrieves the next event from the event queue. The returned int64_t
combines the widget ID and event type. Returns -2 if no event is available.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
var event = mjuiGrabEvent()
fl_check() -> Int
Processes any pending FLTK events and returns 1 if there are still events to process, 0 otherwise. Used to keep the UI responsive without blocking.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
while fl_check():
# Do background work
fl_ready() -> Int
Checks if there are any FLTK events ready to be processed. Returns 1 if events are ready, 0 otherwise.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
if fl_ready() == 1:
fl_check()
mjuiEventKey() -> Int
Returns the integer key code of the most recent keyboard event. Useful for custom key handling in event-driven code.
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
var key = mjuiEventKey()
useScheme(scheme: Int)
Sets the global FLTK visual scheme. scheme
can be GTK
(0), GLEAM
(1), or PLASTIC
(2).
Defined in: mjui/fltk_bindings/libc/BaseWidgetHelpers.cc
useScheme(GTK)
useScheme(GLEAM)
useScheme(PLASTIC)