fltk.customwidget
FLTK Custom Widget Base Class
This module provides a base class for creating custom widgets with overridable draw() and handle() methods using D delegates.
The CustomWidget class allows users to create their own widgets with custom drawing and event handling without subclassing in C++.
License
BSD-3-Clause
Copyright
Copyright © 2025 DDN (D Developer Network) Members
class CustomWidget
Types 1
classCustomWidget : Widget
Base class for creating custom widgets.
CustomWidget allows you to create widgets with custom drawing and event handling by setting the onDraw and onHandle delegates.
The onDraw delegate is called when the widget needs to redraw itself. Use the fltk.draw module functions to draw the widget content.
The onHandle delegate is called when the widget receives an event. Return true if the event was handled, false otherwise.
Example:
import fltk.customwidget;
import fltk.draw;
auto widget = new CustomWidget(10, 10, 100, 100, "Custom");
widget.onDraw = () {
// Draw a filled rectangle
setColor(Color.RED);
fillRect(widget.x, widget.y, widget.width, widget.height);
};
widget.onHandle = (int event) {
if (event == Event.PUSH) {
writeln("Mouse clicked!");
return true;
}
return false;
};Methods
void drawTrampoline(CustomWidgetPtr widget, void * userdata) nothrowStatic trampoline function to bridge C callback to D delegate for draw.int handleTrampoline(CustomWidgetPtr widget, int event, void * userdata) nothrowStatic trampoline function to bridge C callback to D delegate for handle.CustomWidgetPtr customWidgetHandle() @safe nothrow @nogcReturns the underlying custom widget handle.void delegate() onDraw()Gets the draw callback delegate.void onDraw(void delegate() dg)Sets the draw callback delegate.int delegate(int) onHandle()Gets the handle callback delegate.void onHandle(int delegate(int) dg)Sets the handle callback delegate.void redraw()Triggers a redraw of the widget.Constructors
this(int x, int y, int width, int height, string label = null)Creates a new custom widget.Destructors