fltk.widget

FLTK Widget Base Class

This module provides the base Widget class that wraps FLTK's Fl_Widget. All other widget types inherit from this class.

The Widget class provides:

  • Property-based access to geometry (x, y, width, height)
  • Label management
  • Visibility and activation state
  • Callback support with D delegates

    Note

    Widget instances do not own their underlying handles by default. Derived classes (Window, Button, etc.) manage ownership appropriately.

    Authors

    Dejan Lekić

    License

    BSD-3-Clause
class Widget

Types 1

classWidget

Base class for all FLTK widgets.

This class wraps a low-level WidgetPtr handle and provides idiomatic D access to widget properties and methods. It does not own the handle by default - derived classes manage ownership.

Example:

// Usually you work with derived classes like Window or Button
auto button = new Button(10, 10, 100, 30, "Click");
button.x = 20;  // Move button
button.visible = false;  // Hide it

Fields
WidgetPtr _handleThe underlying low-level widget handle
bool _ownsHandleWhether this instance owns the handle and should delete it
Callback _callbackStored callback delegate
CallbackContext * _callbackContextCallback context for GC pinning and C bridging
Methods
GroupPtr parent() nothrow @nogcReturns the widget's parent group.
WidgetPtr handle() @safe nothrow @nogcReturns the underlying low-level handle.
bool isValid() const @safe nothrow @nogcChecks if this widget has a valid handle.
int x() const nothrow @nogcGets the widget's X position.
int y() const nothrow @nogcGets the widget's Y position.
int width() const nothrow @nogcGets the widget's width.
int height() const nothrow @nogcGets the widget's height.
Rect bounds() const nothrow @nogcGets the widget's bounds as a Rect.
Size size() const nothrow @nogcGets the widget's size.
Point position() const nothrow @nogcGets the widget's position.
void resize(int newX, int newY, int newWidth, int newHeight) nothrow @nogcResizes and repositions the widget.
void resize(Rect rect) nothrow @nogcResizes and repositions the widget using a Rect.
string label() constGets the widget's label text.
void label(string text)Sets the widget's label text.
bool visible() const nothrow @nogcChecks if the widget is visible.
void visible(bool value) nothrow @nogcSets the widget's visibility.
void show() nothrow @nogcShows the widget.
void hide() nothrow @nogcHides the widget.
bool active() const nothrow @nogcChecks if the widget is active (enabled).
void active(bool value) nothrow @nogcSets the widget's active state.
void activate() nothrow @nogcActivates the widget.
void deactivate() nothrow @nogcDeactivates the widget.
void redraw() nothrow @nogcMarks the widget for redrawing.
void image(Image img)Sets the widget's image.
Image image()Gets the widget's image.
void deimage(Image img)Sets the widget's deactivation image.
Image deimage()Gets the widget's deactivation image.
void onClick(Callback callback)Sets the widget's callback delegate.
Callback onClick()Gets the widget's callback delegate.
Constructors
this(WidgetPtr handle, bool ownsHandle = false)Creates a Widget wrapper around an existing handle.
Destructors
~thisDestroys the widget.