Skip to content

UXApplicationDelegate

UXApplicationDelegate is the protocol your controller adopts to become a program. It has one required method and one optional one.

#use <UXKit> // or #import "UXApplication.xc"
protocol UXApplicationDelegate {
i32 applicationDidStart(UXApplication* app);
optional void windowDidResize(UXApplication* app, UXWindow* win,
i32 width, i32 height);
}
class MyApp : Object <UXApplicationDelegate>
{
i32 applicationDidStart(UXApplication* app) {
UXView* content = new UXView();
UXWindow* win = new UXWindow();
app.addWindow(win);
win.open((u8*)"Hello", UXGeom.make(80, 80, 240, 120), content);
// … build the interface …
win.tree.finalise();
win.displayAll();
return 0;
}
}

Your controller conforms to a protocol and does not inherit from an application class. Its inheritance stays free for whatever your program needs, and one small class can be the application delegate, a table data source and a table delegate at once. This is normal for a single-window program.

applicationDidStart · windowDidResize

i32 applicationDidStart(UXApplication* app)

Runs once, after the toolkit is up and before the first event. Build your interface here.

The toolkit is fully available: the driver has booted, the screen size is known, and UXMetrics can answer form-factor questions. Make decisions that depend on the platform here, not at construction time.

Return 0 for success. A non-zero return means “do not continue”. A program uses it to refuse to run when something it needs is missing. The usual case is the wiring check in a nib-loading app:

i32 applicationDidStart(UXApplication* app) {
if (!Builder.buildInto(content, self, W, H)) {
Stdio.printf("FAIL: a wiring name was rejected\n");
return 1; // a typo the nib path would hit too
}
return 0;
}
optional void windowDidResize(UXApplication* app, UXWindow* win,
i32 width, i32 height)

The user resized a window. width and height are the new content-area size.

When this runs, the native frame has finished the drag, and the toolkit has already reflowed the tree and repainted using the autoresize masks. Most programs (any whose layout springs and struts describe) ignore this method, so it is optional. Implement it when anchors cannot express your layout: a view whose contents reflow by recomputing, or one that switches arrangement at a size threshold.

The delegate is half of the pattern. The other half is four lines:

void main(void) {
gDriver = new UXAppKitDriver(); // the ONE platform-aware line
UXApplication* app = new UXApplication();
app.setDelegate(new MyApp());
app.run(); // does not return
}

run takes over. The event loop dispatches to windows, windows to views, and controls to your callbacks. It ends when the last window closes or something calls stop.

See the driver model for turning that first line into a multiplatform seam.