diff --git a/.gitignore b/.gitignore index 429a74d..6b3cb08 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ app.mojo /cairo/*# magic environments .magic *.png +!logo.png *.gif \ No newline at end of file diff --git a/README.md b/README.md index 46ad4c3..67f62b2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ -# CombustUI – Lightweight GUI Bindings for Mojo -

- drawing + drawing


diff --git a/build.sh b/build.sh index 9d9e669..b07eec2 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,5 @@ +set -e + cd mjui/fltk_bindings/libc/ echo "Compiling mjui-fltk bindings..." diff --git a/docs/API_REFERENCE.html b/docs/API_REFERENCE.html new file mode 100644 index 0000000..2acd41f --- /dev/null +++ b/docs/API_REFERENCE.html @@ -0,0 +1,1176 @@ + + + + + + + CombustUI-Mojo API Reference + + + + + + +
+ CombustUI-Mojo Logo +

Comprehensive documentation for all public functions, constants, and FFI bindings in CombustUI-Mojo.

+
+ Light + + Dark +
+
+
+ +
+ +

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 EventHandlers, 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.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameValueDescriptionDefined In
MJUI_NO_EVENT0Represents the absence of an event. This value is used when no specific UI interaction or system event has occurred.mjui/const.mojo
MJUI_PUSH1Indicates 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_RELEASE2Signifies 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_ENTER3Occurs 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_LEAVE4Triggers 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_DRAG5Generated 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_FOCUS6Indicates 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_UNFOCUS7Occurs 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_KEYBOARD8Fired 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_KEYUP9Generated when a keyboard key is released after being pressed. This complements MJUI_KEYDOWN for full key press detection.mjui/const.mojo
MJUI_CLOSE10Signifies that a widget or window is being closed. This is particularly important for window management to perform cleanup operations.mjui/const.mojo
MJUI_MOVE11Indicates that a widget has been moved on the screen, typically by user interaction or programmatic changes to its position.mjui/const.mojo
MJUI_SHORTCUT12Triggered when a keyboard shortcut is activated. This allows for quick access to specific application functionalities.mjui/const.mojo
MJUI_DEACTIVATE13Occurs when a widget becomes inactive or disabled, meaning it can no longer receive input or interact with the user.mjui/const.mojo
MJUI_ACTIVATE14Fired when a widget becomes active or re-enabled, allowing it to receive user input and interactions again.mjui/const.mojo
MJUI_HIDE15Indicates that a widget has been hidden from view. The widget still exists but is not rendered on the screen.mjui/const.mojo
MJUI_SHOW16Occurs when a previously hidden widget becomes visible again.mjui/const.mojo
MJUI_PASTE17Generated when content is pasted into an input field or a widget that supports paste operations.mjui/const.mojo
MJUI_SELECTIONCLEAR18Fired when any current text selection within a widget is cleared.mjui/const.mojo
MJUI_MOUSEWHEEL19Triggered 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_ENTER20Indicates that a drag-and-drop operation has entered the bounding box of a widget.mjui/const.mojo
MJUI_DND_DRAG21Occurs when a drag-and-drop operation is actively being dragged over a widget.mjui/const.mojo
MJUI_DND_LEAVE22Fired when a drag-and-drop operation leaves the bounding box of a widget.mjui/const.mojo
MJUI_DND_RELEASE23Triggered when a drag-and-drop operation is released over a widget, signaling a potential drop.mjui/const.mojo
MJUI_SCREEN_CONFIGURATION_CHANGED24Occurs when the screen configuration (e.g., resolution, display settings) changes.mjui/const.mojo
MJUI_FULLSCREEN25Indicates that a window has entered or exited fullscreen mode.mjui/const.mojo
MJUI_ZOOM_GESTURE26Generated by a zoom gesture, typically on touch-enabled devices.mjui/const.mojo
MJUI_ZOOM_EVENT27A 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.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameValueDescriptionDefined In
MJUI_CURSOR_DEFAULT0The default cursor, typically an arrow.mjui/const.mojo
MJUI_CURSOR_ARROW35A standard arrow cursor, used for general pointing and clicking.mjui/const.mojo
MJUI_CURSOR_CROSS66A crosshair cursor, often used for drawing or selecting precise points.mjui/const.mojo
MJUI_CURSOR_WAIT76An hourglass or spinning circle cursor, indicating that the application is busy and the user should wait.mjui/const.mojo
MJUI_CURSOR_INSERT77A text insertion cursor (I-beam), used for text input fields.mjui/const.mojo
MJUI_CURSOR_HAND31A hand cursor, typically used to indicate a clickable or draggable element.mjui/const.mojo
MJUI_CURSOR_HELP47A cursor with a question mark, indicating that help is available for the element under the cursor.mjui/const.mojo
MJUI_CURSOR_MOVE27A four-directional arrow cursor, used to indicate that an element can be moved in any direction.mjui/const.mojo
MJUI_CURSOR_NS78A vertical double-headed arrow, used for resizing elements vertically (North-South).mjui/const.mojo
MJUI_CURSOR_WE79A horizontal double-headed arrow, used for resizing elements horizontally (West-East).mjui/const.mojo
MJUI_CURSOR_NWSE80A diagonal double-headed arrow (North-West to South-East), used for diagonal resizing.mjui/const.mojo
MJUI_CURSOR_NESW81A diagonal double-headed arrow (North-East to South-West), used for diagonal resizing.mjui/const.mojo
MJUI_CURSOR_N70An arrow pointing North (up), used for resizing.mjui/const.mojo
MJUI_CURSOR_NE69An arrow pointing North-East (up-right), used for resizing.mjui/const.mojo
MJUI_CURSOR_E49An arrow pointing East (right), used for resizing.mjui/const.mojo
MJUI_CURSOR_SE8An arrow pointing South-East (down-right), used for resizing.mjui/const.mojo
MJUI_CURSOR_S9An arrow pointing South (down), used for resizing.mjui/const.mojo
MJUI_CURSOR_SW7An arrow pointing South-West (down-left), used for resizing.mjui/const.mojo
MJUI_CURSOR_W36An arrow pointing West (left), used for resizing.mjui/const.mojo
MJUI_CURSOR_NW68An arrow pointing North-West (up-left), used for resizing.mjui/const.mojo
MJUI_CURSOR_NONE255An invisible cursor, used when no cursor should be displayed.mjui/const.mojo
+

Layout Flags

+

Layout direction and resize flags for flex layouts.

+ + + + + + + + + + + +
NameValueDescriptionDefined In
MJUI_MJUIEX_HORIZONTAL1Specifies that a flex layout container should arrange its child widgets horizontally, from left to right.mjui/const.mojo
MJUI_MJUIEX_VERTICAL0Specifies that a flex layout container should arrange its child widgets vertically, from top to bottom.mjui/const.mojo
RESIZE_XY100Indicates that a widget or layout should be resizable in both horizontal (X) and vertical (Y) directions.mjui/const.mojo
RESIZE_XONLY110Indicates that a widget or layout should only be resizable in the horizontal (X) direction.mjui/const.mojo
RESIZE_YONLY111Indicates 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.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameValueDescriptionDefined In
MJUI_FLAT_BOX1A simple, flat box with no 3D appearance, often used for clean, modern interfaces.mjui/const.mojo
MJUI_UP_BOX2A box type that appears raised or extruding from the surface, creating a 3D button-like effect.mjui/const.mojo
MJUI_DOWN_BOX3A 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_FRAME4A raised frame border, similar to MJUI_UP_BOX but typically without a filled background.mjui/const.mojo
MJUI_DOWN_FRAME5A sunken frame border, similar to MJUI_DOWN_BOX but typically without a filled background.mjui/const.mojo
MJUI_THIN_UP_BOX6A thinner version of MJUI_UP_BOX, providing a subtle raised effect.mjui/const.mojo
MJUI_THIN_DOWN_BOX7A thinner version of MJUI_DOWN_BOX, providing a subtle sunken effect.mjui/const.mojo
MJUI_THIN_UP_FRAME8A thinner version of MJUI_UP_FRAME.mjui/const.mojo
MJUI_THIN_DOWN_FRAME9A thinner version of MJUI_DOWN_FRAME.mjui/const.mojo
MJUI_ENGRAVED_BOX10A box with an engraved appearance, making the content seem carved into the surface.mjui/const.mojo
MJUI_EMBOSSED_BOX11A box with an embossed appearance, making the content seem raised from the surface.mjui/const.mojo
MJUI_ENGRAVED_FRAME12An engraved frame, similar to MJUI_ENGRAVED_BOX but typically without a filled background.mjui/const.mojo
MJUI_EMBOSSED_FRAME13An embossed frame, similar to MJUI_EMBOSSED_BOX but typically without a filled background.mjui/const.mojo
MJUI_BORDER_BOX14A box with a simple border around its perimeter.mjui/const.mojo
MJUI_SHADOW_BOX15A box with a shadow effect, giving it a lifted appearance.mjui/const.mojo
MJUI_BORDER_FRAME16A simple border frame without a filled background.mjui/const.mojo
MJUI_SHADOW_FRAME17A frame with a shadow effect.mjui/const.mojo
MJUI_ROUNDED_BOX18A box with rounded corners, providing a softer aesthetic.mjui/const.mojo
MJUI_RSHADOW_BOX19A rounded box with a shadow effect.mjui/const.mojo
MJUI_ROUNDED_FRAME20A rounded frame without a filled background.mjui/const.mojo
MJUI_RFLAT_BOX21A rounded, flat box.mjui/const.mojo
MJUI_ROUND_UP_BOX22A rounded box with a raised appearance.mjui/const.mojo
MJUI_ROUND_DOWN_BOX23A rounded box with a sunken appearance.mjui/const.mojo
MJUI_DIAMOND_UP_BOX24A diamond-shaped box with a raised appearance.mjui/const.mojo
MJUI_DIAMOND_DOWN_BOX25A diamond-shaped box with a sunken appearance.mjui/const.mojo
MJUI_OVAL_BOX26An oval-shaped box.mjui/const.mojo
MJUI_OSHADOW_BOX27An oval-shaped box with a shadow effect.mjui/const.mojo
MJUI_OVAL_FRAME28An oval-shaped frame.mjui/const.mojo
MJUI_OFLAT_BOX29An oval, flat box.mjui/const.mojo
MJUI_PLASTIC_UP_BOX30A box with a plastic-like raised appearance.mjui/const.mojo
MJUI_PLASTIC_DOWN_BOX31A box with a plastic-like sunken appearance.mjui/const.mojo
MJUI_PLASTIC_UP_FRAME32A plastic-like raised frame.mjui/const.mojo
MJUI_PLASTIC_DOWN_FRAME33A plastic-like sunken frame.mjui/const.mojo
MJUI_PLASTIC_THIN_UP_BOX34A thin plastic-like raised box.mjui/const.mojo
MJUI_PLASTIC_THIN_DOWN_BOX35A thin plastic-like sunken box.mjui/const.mojo
MJUI_PLASTIC_THIN_UP_FRAME36A thin plastic-like raised frame.mjui/const.mojo
MJUI_PLASTIC_THIN_DOWN_FRAME37A thin plastic-like sunken frame.mjui/const.mojo
MJUI_PLASTIC_ROUND_UP_BOX38A rounded plastic-like raised box.mjui/const.mojo
MJUI_PLASTIC_ROUND_DOWN_BOX39A rounded plastic-like sunken box.mjui/const.mojo
MJUI_GTK_UP_BOX40A box style resembling the GTK+ toolkit's raised elements.mjui/const.mojo
MJUI_GTK_DOWN_BOX41A box style resembling the GTK+ toolkit's sunken elements.mjui/const.mojo
MJUI_GTK_UP_FRAME42A GTK+ style raised frame.mjui/const.mojo
MJUI_GTK_DOWN_FRAME43A GTK+ style sunken frame.mjui/const.mojo
MJUI_GTK_THIN_UP_BOX44A thin GTK+ style raised box.mjui/const.mojo
MJUI_GTK_THIN_DOWN_BOX45A thin GTK+ style sunken box.mjui/const.mojo
MJUI_GTK_THIN_UP_FRAME46A thin GTK+ style raised frame.mjui/const.mojo
MJUI_GTK_THIN_DOWN_FRAME47A thin GTK+ style sunken frame.mjui/const.mojo
MJUI_GTK_ROUND_UP_BOX48A rounded GTK+ style raised box.mjui/const.mojo
MJUI_GTK_ROUND_DOWN_BOX49A rounded GTK+ style sunken box.mjui/const.mojo
MJUI_GLEAM_UP_BOX50A box with a gleam-like raised appearance.mjui/const.mojo
MJUI_GLEAM_DOWN_BOX51A box with a gleam-like sunken appearance.mjui/const.mojo
MJUI_GLEAM_UP_FRAME52A gleam-like raised frame.mjui/const.mojo
MJUI_GLEAM_DOWN_FRAME53A gleam-like sunken frame.mjui/const.mojo
MJUI_GLEAM_THIN_UP_BOX54A thin gleam-like raised box.mjui/const.mojo
MJUI_GLEAM_THIN_DOWN_BOX55A thin gleam-like sunken box.mjui/const.mojo
MJUI_GLEAM_ROUND_UP_BOX56A rounded gleam-like raised box.mjui/const.mojo
MJUI_GLEAM_ROUND_DOWN_BOX57A rounded gleam-like sunken box.mjui/const.mojo
MJUI_OXY_UP_BOX58A box with an Oxygen-like (KDE Plasma) raised appearance.mjui/const.mojo
MJUI_OXY_DOWN_BOX59A box with an Oxygen-like (KDE Plasma) sunken appearance.mjui/const.mojo
MJUI_OXY_UP_FRAME60An Oxygen-like raised frame.mjui/const.mojo
MJUI_OXY_DOWN_FRAME61An Oxygen-like sunken frame.mjui/const.mojo
MJUI_OXY_THIN_UP_BOX62A thin Oxygen-like raised box.mjui/const.mojo
MJUI_OXY_THIN_DOWN_BOX63A thin Oxygen-like sunken box.mjui/const.mojo
MJUI_OXY_THIN_UP_FRAME64A thin Oxygen-like raised frame.mjui/const.mojo
MJUI_OXY_THIN_DOWN_FRAME65A thin Oxygen-like sunken frame.mjui/const.mojo
MJUI_OXY_ROUND_UP_BOX66A rounded Oxygen-like raised box.mjui/const.mojo
MJUI_OXY_ROUND_DOWN_BOX67A rounded Oxygen-like sunken box.mjui/const.mojo
MJUI_OXY_BUTTON_UP_BOX68An Oxygen-like raised button box.mjui/const.mojo
MJUI_OXY_BUTTON_DOWN_BOX69An Oxygen-like sunken button box.mjui/const.mojo
MJUI_FREE_BOXTYPE70A free box type, which can be customized.mjui/const.mojo
MJUI_MAX_BOXTYPE255Represents the maximum value for box type constants.mjui/const.mojo
+

Label Types

+

Label rendering types for widgets.

+ + + + + + + + + + + +
NameValueDescriptionDefined In
MJUI_LABEL_TYPE_NORMAL0Standard text rendering.mjui/const.mojo
MJUI_LABEL_TYPE_SHADOW1Renders text with a shadow effect, adding depth.mjui/const.mojo
MJUI_LABEL_TYPE_EMBOSSED2Renders text with an embossed effect, making it appear raised.mjui/const.mojo
MJUI_LABEL_TYPE_MULTI3Enables multi-line text rendering, allowing text to wrap within the widget's bounds.mjui/const.mojo
MJUI_LABEL_TYPE_IMAGE4Specifies that the label should display an image instead of text.mjui/const.mojo
+

Image Types

+

Image format constants for loading images.

+ + + + + + + + + + + + +
NameValueDescriptionDefined In
PNG0Specifies the Portable Network Graphics (PNG) image format, known for lossless compression and support for transparency.mjui/const.mojo
JPEG1Specifies the Joint Photographic Experts Group (JPEG) image format, commonly used for photographs due to its lossy compression.mjui/const.mojo
SVG2Specifies 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
BMP3Specifies the Bitmap (BMP) image format, a raster graphics image file format used to store bitmap digital images.mjui/const.mojo
GIF4Specifies the Graphics Interchange Format (GIF), known for its support of both static and animated images with a limited color palette.mjui/const.mojo
ANIM_GIF5Specifically 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.

+ + + + + + + + + + + + + + + + +
NameValueDescriptionDefined In
ALIGN_CENTER0Aligns content to the center of the widget's bounding box.mjui/const.mojo
ALIGN_TOP1Aligns content to the top of the widget's bounding box.mjui/const.mojo
ALIGN_BOTTOM2Aligns content to the bottom of the widget's bounding box.mjui/const.mojo
ALIGN_LEFT3Aligns content to the left of the widget's bounding box.mjui/const.mojo
ALIGN_RIGHT4Aligns content to the right of the widget's bounding box.mjui/const.mojo
ALIGN_INSIDE5Aligns content within the widget's interior, respecting padding.mjui/const.mojo
ALIGN_CLIP6Clips content that extends beyond the widget's boundaries.mjui/const.mojo
ALIGN_WRAP7Wraps text content to multiple lines if it exceeds the widget's width.mjui/const.mojo
TEXT_OVER_IMAGE8Displays text content over an image within the same widget.mjui/const.mojo
IMAGE_OVER_TEXT9Displays an image over text content within the same widget.mjui/const.mojo
+

Visual Schemes

+ See useScheme +

Visual style schemes for the UI.

+ + + + + + + + + +
NameValueDefined In
GTK0mjui/utils.mojo
GLEAM1mjui/utils.mojo
PLASTIC2mjui/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 resizeability, 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(w, h, x, y, 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(w, h, x, y, 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..."))
+
+

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
+
+ + +

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 direction (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)
+
+
+
+ + + \ No newline at end of file diff --git a/docs/EXAMPLES.html b/docs/EXAMPLES.html new file mode 100644 index 0000000..d9396df --- /dev/null +++ b/docs/EXAMPLES.html @@ -0,0 +1,538 @@ + + + + + + + CombustUI-Mojo Examples + + + + + + +
+ CombustUI-Mojo Logo +

Explore various UI examples built with CombustUI-Mojo.

+
+ Light + + Dark +
+
+
+ +
+
+
+ + + \ No newline at end of file diff --git a/USAGE.md b/docs/USAGE.md similarity index 100% rename from USAGE.md rename to docs/USAGE.md diff --git a/docs/examples.json b/docs/examples.json new file mode 100644 index 0000000..f871162 --- /dev/null +++ b/docs/examples.json @@ -0,0 +1,129 @@ +[ + { + "Name": "Basic Window", + "Description": "This example demonstrates how to create a simple window with a title.", + "Code": [ + "from mjui._app import Application", + "from mjui.utils import rgb, convertStringToBytes, readFromStringBytes, GTK", + "from mjui.fltk_bindings.bindings import *", + "", + "fn main() raises:", + " useScheme(GTK)", + " var app = Application()", + " var window = mjuiCreateWindow(800, 600, 1, 0, 0, convertStringToBytes(\"My First Window\"))", + " app.markWindowPTRAsMain(window)", + " mjuiShowWidget(window)", + " app.execute()" + ] + }, + { + "Name": "Flexbox Layout", + "Description": "This example shows how to use a vertical flexbox layout to arrange widgets.", + "Code": [ + "from mjui._app import Application", + "from mjui.utils import rgb, convertStringToBytes, readFromStringBytes, GTK", + "from mjui.fltk_bindings.bindings import *", + "from mjui.const import *", + "", + "fn main() raises:", + " useScheme(GTK)", + " var app = Application()", + " var window = mjuiCreateWindow(400, 300, 1, 0, 0, convertStringToBytes(\"Flexbox Example\"))", + " var layout = mjuiCreateLayoutFlex(0, 0, 400, 300, MJUI_MJUIEX_VERTICAL)", + "", + " BEGIN_WIDGET_APPEND(layout)", + " var button1 = mjuiCreateButton(100, 30, 0, 0, 1, convertStringToBytes(\"Button 1\"))", + " var label1 = mjuiCreateLabel(0, 0, 150, 20, 2, convertStringToBytes(\"Label 1\"))", + " var button2 = mjuiCreateButton(100, 30, 0, 0, 3, convertStringToBytes(\"Button 2\"))", + " END_WIDGET_APPEND(layout)", + "", + " mjuiFlexCalculateLayout(layout)", + " app.markWindowPTRAsMain(window)", + " mjuiShowWidget(window)", + " app.execute()" + ] + }, + { + "Name": "Button Click Event", + "Description": "This example demonstrates how to handle a button click event using EventHandler.", + "Code": [ + "from mjui._app import Application", + "from mjui.utils import rgb, convertStringToBytes, readFromStringBytes, GTK", + "from mjui.fltk_bindings.bindings import *", + "from mjui.const import *", + "from mjui.EventHandler import EventHandler", + "", + "var click_count = 0", + "", + "fn button_handler() raises:", + " # In Mojo, top-level variables can be directly modified within functions without 'global'.\n # This simplifies state management compared to Python's 'global' keyword.\n click_count += 1", + " print(\"Button clicked!\", click_count)", + "", + "fn main() raises:", + " useScheme(GTK)", + " var app = Application()", + " var window = mjuiCreateWindow(300, 200, 1, 0, 0, convertStringToBytes(\"Button Event\"))", + " var button = mjuiCreateButton(100, 40, 100, 80, 1001, convertStringToBytes(\"Click Me\"))", + "", + " var handler = EventHandler()", + " handler.set(MJUI_PUSH, button_handler)", + " app.addEventListener(1001, handler) # Attach to button ID", + "", + " app.markWindowPTRAsMain(window)", + " mjuiShowWidget(window)", + " app.execute()" + ] + }, + { + "Name": "Text Input", + "Description": "This example shows how to use an EventHandler to capture key presses in an input field.", + "Code": [ + "from mjui._app import Application", + "from mjui.utils import rgb, convertStringToBytes, readFromStringBytes, GTK", + "from mjui.fltk_bindings.bindings import *", + "from mjui.const import *", + "from mjui.EventHandler import EventHandler", + "", + "fn key_handler() raises:", + " # This handler is triggered when a key is pressed in the input field.\n # You can get the key code using mjuiEventKey() if needed.\n print(\"Key pressed!\")", + "", + "fn main() raises:", + " useScheme(GTK)", + " var app = Application()", + " var window = mjuiCreateWindow(500, 150, 1, 0, 0, convertStringToBytes(\"Text Input\"))", + " var input_field = mjuiCreateInput(50, 50, 400, 30, 2001, 0, convertStringToBytes(\"Type something...\"))", + "", + " # Create an EventHandler for key down events and attach it to the input field.\n # This replaces the manual event loop for handling input events.\n var handler = EventHandler()", + " handler.set(MJUI_KEYDOWN, key_handler)", + " app.addEventListener(2001, handler)", + "", + " app.markWindowPTRAsMain(window)", + " mjuiShowWidget(window)", + " app.execute()" + ] + }, + { + "Name": "Image Display", + "Description": "This example demonstrates how to load and display an image in a window.", + "Code": [ + "from mjui._app import Application", + "from mjui.utils import rgb, convertStringToBytes, readFromStringBytes, GTK", + "from mjui.fltk_bindings.bindings import *", + "from mjui.const import *", + "", + "fn main() raises:", + " useScheme(GTK)", + " var app = Application()", + " var window = mjuiCreateWindow(400, 400, 1, 0, 0, convertStringToBytes(\"Image Display\"))", + " var image_label = mjuiCreateLabel(0, 0, 400, 400, 3001, convertStringToBytes(\"\")) # Label to hold image", + "", + " # You would need an actual logo.png file in the same directory as your Mojo app", + " var img = mjuiLoadImg(300, 300, PNG, convertStringToBytes(\"docs/images/logo.png\"))", + " mjuiApplyImage(image_label, img)", + "", + " app.markWindowPTRAsMain(window)", + " mjuiShowWidget(window)", + " app.execute()" + ] + } +] \ No newline at end of file diff --git a/docs/images/logo.png b/docs/images/logo.png new file mode 100644 index 0000000..f39760a Binary files /dev/null and b/docs/images/logo.png differ diff --git a/logo.jpeg b/logo.jpeg deleted file mode 100644 index f982c08..0000000 Binary files a/logo.jpeg and /dev/null differ diff --git a/maplib/experimental/header.py b/maplib/experimental/header.py index d0d1b0d..926f31c 100644 --- a/maplib/experimental/header.py +++ b/maplib/experimental/header.py @@ -11,21 +11,31 @@ # Extracts the function name and return type from a function declaration line def get_name_ret_type(function: str): namepret = function.split(" ") # split the line by spaces - argstart = namepret[1].index('(') # find '(' to separate name from parameters - ret = namepret[0].strip() # first part is the return type + argst = 1 + if len(namepret) > 2 and namepret[0] == 'const' and namepret[1] == 'char' or namepret[1] == 'char*': + argst = 2 + + argstart = namepret[argst].index('(') # find '(' to separate name from parameters + if argst > 1: + ret = namepret[0].strip() + " " + namepret[1].strip() # first part is the return type + else: + ret = namepret[0].strip() + # Map C return types to your target types if ret == 'void': ret = 'c_void' elif 'int' in ret: ret = 'Int' + elif 'const char*' in ret or "char*" in ret: + ret = "StringBytes" elif "*" in ret: if "Fl_Image" in ret: ret = 'Int32' else: ret = 'FLTK_WIDGET_POINTER' - return namepret[1][:argstart], ret # return (function_name, return_type) + return namepret[argst][:argstart], ret # return (function_name, return_type) # Parses the arguments inside a function declaration and maps them to mojo types def get_args(function: str): @@ -60,12 +70,12 @@ def get_args(function: str): mojo_args[arg[-1].replace("*", '')] = 'Int' continue - if 'int8_t' in arg[0]: + if 'int8_t' in arg[0] : mojo_args[arg[-1].replace("*", '')] = 'StringBytes' continue # Handle pointer or widget types - if 'Fl_Image' not in arg[0] and ("Fl" in arg[0] or "MJUI" in arg[0]): + if 'Fl_Image' not in arg[0] and ("Fl" in arg[0] or "MJUI" in arg[0] or '*' in arg[1]): mojo_args[arg[-1].replace("*", '')] = 'FLTK_WIDGET_POINTER' continue elif 'Fl_Image' in arg[0]: @@ -112,7 +122,9 @@ def evaluate(header, id): res = subprocess.run(['ls'] + files, capture_output=True) header_files = (res.stdout).decode('utf-8').splitlines() -ffi_map = {} +ffi_map = { + '?': 'Auto-generated using maplib' +} # Build the entire FFI map by iterating through each header for file in header_files: diff --git a/maplib/ffi.map.gen b/maplib/ffi.map.gen index e7bdac7..a0b16b4 100644 --- a/maplib/ffi.map.gen +++ b/maplib/ffi.map.gen @@ -1,4 +1,5 @@ { + "?": "Auto-generated using maplib", "mjuiGrabEvent": { "returns": "Int", "arguments": {} @@ -182,6 +183,12 @@ "value": "StringBytes" } }, + "mjuiGrabInput": { + "returns": "StringBytes", + "arguments": { + "ptr": "FLTK_WIDGET_POINTER" + } + }, "mjuiCreateLabel": { "returns": "FLTK_WIDGET_POINTER", "arguments": { diff --git a/maplib/generator.py b/maplib/generator.py index 8fad684..37d2f0d 100755 --- a/maplib/generator.py +++ b/maplib/generator.py @@ -3,7 +3,6 @@ """ import json as j # Import JSON module with alias `j` -import copy import sys # === READ COMMAND LINE ARGUMENTS === @@ -34,7 +33,8 @@ # === LOOP OVER EACH FUNCTION IN THE MAP === for key, value in parsed_contents.items(): - + if key == '?': + continue # Build the argument list as `name: Type` args = [f"{arg_name}: {dtype}" for arg_name, dtype in value['arguments'].items()] args_str = ', '.join(args) diff --git a/mjui/fltk_bindings/bindings.mojo b/mjui/fltk_bindings/bindings.mojo index bccb272..65827bb 100644 --- a/mjui/fltk_bindings/bindings.mojo +++ b/mjui/fltk_bindings/bindings.mojo @@ -31,6 +31,7 @@ alias MJUICHECKBUTTONGETSTATE_DEFINATION= fn(checkButton: FLTK_WIDGET_POINTER) - alias MJUICREATEINPUT_DEFINATION= fn(x: Int, y: Int, w: Int, h: Int, id: Int32, numOnly: Int, label_r: StringBytes) -> FLTK_WIDGET_POINTER alias MJUICREATEMULTILINEINPUT_DEFINATION= fn(x: Int, y: Int, w: Int, h: Int, id: Int32, label_r: StringBytes) -> FLTK_WIDGET_POINTER alias MJUISETINPUTVALUE_DEFINATION= fn(input: FLTK_WIDGET_POINTER, value: StringBytes) -> c_void +alias MJUIGRABINPUT_DEFINATION= fn(ptr: FLTK_WIDGET_POINTER) -> StringBytes alias MJUICREATELABEL_DEFINATION= fn(x: Int, y: Int, width: Int, height: Int, id: Int, text: StringBytes) -> FLTK_WIDGET_POINTER alias MJUISETTEXTPROPERTIES_DEFINATION= fn(label: FLTK_WIDGET_POINTER, size: Int, color: UInt32, type: Int) -> c_void alias MJUITEXTALIGN_DEFINATION= fn(label: FLTK_WIDGET_POINTER, alignment: Int) -> c_void @@ -77,6 +78,7 @@ var mjuiCheckButtonGetState = __dll.get_function[MJUICHECKBUTTONGETSTATE_DEFINAT var mjuiCreateInput = __dll.get_function[MJUICREATEINPUT_DEFINATION]("mjuiCreateInput") var mjuiCreateMultilineInput = __dll.get_function[MJUICREATEMULTILINEINPUT_DEFINATION]("mjuiCreateMultilineInput") var mjuiSetInputValue = __dll.get_function[MJUISETINPUTVALUE_DEFINATION]("mjuiSetInputValue") +var mjuiGrabInput = __dll.get_function[MJUIGRABINPUT_DEFINATION]("mjuiGrabInput") var mjuiCreateLabel = __dll.get_function[MJUICREATELABEL_DEFINATION]("mjuiCreateLabel") var mjuiSetTextProperties = __dll.get_function[MJUISETTEXTPROPERTIES_DEFINATION]("mjuiSetTextProperties") var mjuiTextAlign = __dll.get_function[MJUITEXTALIGN_DEFINATION]("mjuiTextAlign") diff --git a/mjui/fltk_bindings/libc/Input/MJUIInput.cc b/mjui/fltk_bindings/libc/Input/MJUIInput.cc index 6cbe017..d61994d 100644 --- a/mjui/fltk_bindings/libc/Input/MJUIInput.cc +++ b/mjui/fltk_bindings/libc/Input/MJUIInput.cc @@ -6,7 +6,7 @@ #include #include "string.h" -#define NUM_ONLY true + Input::Input(int x, int y, int w, int h, long int nid, int numericInput, char *label) : Fl_Input(x, y, w, h, "") { id = nid; diff --git a/mjui/fltk_bindings/libc/Input/MJUIInput.hh b/mjui/fltk_bindings/libc/Input/MJUIInput.hh index a6ee1f1..a61af07 100644 --- a/mjui/fltk_bindings/libc/Input/MJUIInput.hh +++ b/mjui/fltk_bindings/libc/Input/MJUIInput.hh @@ -35,5 +35,5 @@ class MultiLineInput : public Fl_Multiline_Input, public BaseWidget { Input* mjuiCreateInput(int x, int y, int w, int h, long int id, int numOnly, int8_t* label_r); MultiLineInput* mjuiCreateMultilineInput(int x, int y, int w, int h, long int id, int8_t* label_r); void mjuiSetInputValue(Fl_Input* input, int8_t* value); - +const char* mjuiGrabInput(Input *ptr); #endif \ No newline at end of file diff --git a/mjui/utils.mojo b/mjui/utils.mojo index 75c90d0..fdc8190 100644 --- a/mjui/utils.mojo +++ b/mjui/utils.mojo @@ -9,6 +9,7 @@ fn rgb(r:UInt32, g:UInt32, b:UInt32) -> UInt32: """ return UInt32(((((r << 8) | g) << 8) | b)<<8) + fn str_to_int8(str: String) -> List[Int8]: """ Converts a string into a list of ASCII character codes. diff --git a/scripts/create-app.py b/scripts/create-app.py index 6a90da1..9a9e9f4 100644 --- a/scripts/create-app.py +++ b/scripts/create-app.py @@ -3,7 +3,6 @@ import subprocess import shutil from pathlib import Path -import stat get_started = 'https://raw.githubusercontent.com/Hammad-hab/CombustUI/refs/heads/main/scripts/get_started.mojo' build_fltk = 'https://raw.githubusercontent.com/Hammad-hab/CombustUI/refs/heads/main/scripts/build_fltk1.4.sh' @@ -13,7 +12,6 @@ def install_linux_dependencies(): # Try to detect package manager subprocess.run(['curl', '-L', build_fltk, '-o', './build_fltk1.4.sh'], check=True) - st = os.stat('./build_fltk1.4.sh') os.chmod("./build_fltk1.4.sh", 0o755) process = subprocess.run(['./build_fltk1.4.sh'], shell=True, check=True) if process.returncode != 0: @@ -29,13 +27,20 @@ def pixi_magic(): if sys.platform == 'darwin': # Check for brew - homebrew = subprocess.run(['which', 'brew'], capture_output=True, text=True) - if homebrew.returncode != 0: - raise SystemError('Homebrew not installed. Install Homebrew and try again') - - # Install FLTK (always try, brew is idempotent) - print("Installing FLTK...") - subprocess.run(['brew', 'install', 'fltk']) + hasFLTK = False + with open('~/.zshrc', 'r') as rc: + if 'COMBUSTUI_DLL_PATH' in rc.read(): + print('FLTK is already installed, moving on...') + hasFLTK=True + + if not hasFLTK: + homebrew = subprocess.run(['which', 'brew'], capture_output=True, text=True) + if homebrew.returncode != 0: + raise SystemError('Homebrew not installed. Install Homebrew and try again') + + # Install FLTK (always try, brew is idempotent) + print("Installing FLTK...") + subprocess.run(['brew', 'install', 'fltk']) # Clone repo subprocess.run(['git', 'clone', 'https://github.com/Hammad-hab/CombustUI.git']) @@ -79,7 +84,23 @@ def pixi_magic(): print(f"Run: source ~/.zshrc before running pixi shell | magic shell") elif sys.platform.startswith('linux'): - install_linux_dependencies() + hasFLTK = False + dll_path = str(Path.cwd() / 'mjui/fltk_bindings/libc/out/mjui.so') + bashrc = os.path.expanduser('~/.bashrc') + zshrc = os.path.expanduser('~/.zshrc') + + if os.path.exists(zshrc): + rc_file = zshrc + else: + rc_file = bashrc + + with open(rc_file, 'r') as rc: + if 'COMBUSTUI_DLL_PATH' in rc.read(): + print('FLTK is already installed, moving on...') + hasFLTK=True + + if not hasFLTK: + install_linux_dependencies() # Clone repo subprocess.run(['git', 'clone', 'https://github.com/Hammad-hab/CombustUI.git']) user = subprocess.run(['git', 'config', 'user.name'], capture_output=True, text=True) @@ -102,21 +123,14 @@ def pixi_magic(): os.rmdir('./examples') except: print('Failed to remove scripts and examples') - # Setup environment variable in bashrc or zshrc - dll_path = str(Path.cwd() / 'mjui/fltk_bindings/libc/out/mjui.so') - bashrc = os.path.expanduser('~/.bashrc') - zshrc = os.path.expanduser('~/.zshrc') - if os.path.exists(zshrc): - rc_file = zshrc + if not hasFLTK: + print('Editing environment variables...') + with open(rc_file, 'a') as f: + f.write(f'\nexport COMBUSTUI_DLL_PATH="{dll_path}"\n') + print(f"Added COMBUSTUI_DLL_PATH to {rc_file}.") else: - rc_file = bashrc - - print('Editing environment variables...') - with open(rc_file, 'a') as f: - f.write(f'\nexport COMBUSTUI_DLL_PATH="{dll_path}"\n') - print(f"Added COMBUSTUI_DLL_PATH to {rc_file}.") - os.system(f'source {rc_file}') + print('Env vars are already set, skipping....') # Clean up files for pattern in ('*.png', '*.jpeg', '*.md', 'CHANGELOG', 'LICENSE'):