Examples
All examples live in examples/ and can be built with make examples. Each example also compiles as a loadable .gem (make gems) and can be run under orion-shell. See Gem Plugin System for details.
The imageeditor, taskmanager, and formeditor examples all follow the MDI application pattern — the recommended architecture for full Orion apps. See MDI Application Architecture for the complete guide.
Hello World (helloworld.c)
The minimal Orion program: one window, one label, one button.
./build/bin/helloworld
Key patterns shown:
ui_init_graphics/ui_shutdown_graphicscreate_window+show_windowget_message/dispatch_message/repost_messagesloopevPaint→fill_rect+draw_text_smallevCommand→ button click handling
File Manager (filemanager.c)
A two-pane file browser using win_reportview.
./build/bin/filemanager
Key patterns shown:
win_reportviewwithRVM_ADDITEM/RVM_CLEARRVN_SELCHANGE/RVN_DBLCLKnotificationsevStatusBarfor path display- Directory traversal with
opendir/readdir/stat
Image Editor (imageeditor.c)
A MacPaint-inspired MDI raster image editor with PNG open/save.
./build/bin/imageeditor
Demonstrates the full framework surface:
| Feature | API used |
|---|---|
| MDI document windows | create_window with WINDOW_TOOLBAR \| WINDOW_STATUSBAR |
| Floating tool palette | WINDOW_ALWAYSONTOP top-level window |
| Floating colour palette | WINDOW_ALWAYSONTOP, left/right click = FG/BG colour |
| Menu bar (File menu) | win_menubar, kMenuBarMessageSetMenus, chained proc |
| Canvas rendering | OpenGL texture (glTexImage2D / glTexSubImage2D) + draw_rect |
| Drawing tools | Pencil, brush, eraser, flood-fill (BFS) |
| File picker dialog | Modal dialog with win_reportview |
| PNG I/O | load_image / save_image_png (stb_image, built into the framework) |
Running at larger size
By default Orion uses 2x window scaling. Build without it for a larger logical canvas:
make examples CFLAGS="-DUI_WINDOW_SCALE=1"
./build/bin/imageeditor
Mouse coordinate note for canvas children
Child windows discovered via evHitTest receive absolute logical coordinates in wparam. Convert to child-local coords with:
window_t *root = get_root_window(win);
int lx = (int16_t)LOWORD(wparam) - root->frame.x - win->frame.x;
int ly = (int16_t)HIWORD(wparam) - root->frame.y - win->frame.y;
Browser MVP (browser/main.c)
A minimal browser-style example focused on fast HTML-to-text viewing.
Key patterns shown:
- Toolbar navigation (
Back,Forward,Home,Refresh) + address bar - File menu actions (
New Window,Save Page HTML,Load Page HTML,Quit) - Help menu
Aboutaction - Async HTTP fetching and completion handling (
evHttpDone) - HTML-to-text conversion via libxml2
- Local HTML loading via
file://URL support
Keyboard shortcuts:
Ctrl+Nnew windowCtrl+Ssave page HTMLCtrl+Oload page HTMLCtrl+Qquit
Writing Your Own Example
- Create
examples/myapp.cand#include "../ui.h" - Implement your window procedure(s)
- In
main():ui_init_graphics(0, "My App", 800, 600); window_t *w = create_window("My App", 0, MAKERECT(50,50,700,500), NULL, my_proc, NULL); show_window(w, true); ui_event_t e; while (ui_is_running()) { while (get_message(&e)) dispatch_message(&e); repost_messages(); } ui_shutdown_graphics(); - Add a Makefile rule if your example needs extra libraries:
$(BIN_DIR)/myapp$(EXE_EXT): examples/myapp.c $(STATIC_LIB) | $(BIN_DIR) $(CC) $(CFLAGS) -o $@ $< $(STATIC_LIB) $(LDFLAGS) $(LDFLAGS_EXAMPLE) $(LIBS)