# Bananarchy NeoUI SDK reference (`SDK.md`) **NeoUI** (`libneoui.so` + `/usr/include/neoui.h`) is the native `240x320` QVGA graphical user interface SDK for **Bananarchy Linux**. It encapsulates all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets, FIFO IPC, softkey chord handling (`Left+Right` softkey -> `xdrawer`), and multi-tap T9 keypad input behind: 1. A **C-compatible FFI (`neoui_*`)** designed for both C programs and foreign-function interfaces (such as **Yabasic** `frnfn_call` / `frnfn_call$`, LuaJIT FFI, Janet, Python `ctypes`, etc.). 2. A **C++20 SDK (`namespace bananarchy`)** providing `ThemeSpec`, `PluginTheme`, `NeoWindow`, and direct Pango/Xft/image helpers used across all 14 built-in Bananarchy DWM plugins. 3. A **Yabasic wrapper library (`neoui.yab`)** preinstalled in `/home/user/Projects/neoui.yab` (and symlinked at `/usr/lib/neoui.yab`), paired with a full showcase application (`/home/user/Projects/neoui_demo.yab`). --- ## 1. Architecture and files | Path on target device | Source in repository | Description | | :--- | :--- | :--- | | `/usr/lib/libneoui.so` | `src/neoui/neoui.cpp` | Shared library (`armv7` hard-float) implementing the C FFI and C++20 SDK | | `/usr/include/neoui.h` | `src/neoui/neoui.h` | Unified C99 and C++20 header file | | `/home/user/Projects/neoui.yab` | `overlay/rootfs/home/user/Projects/neoui.yab` | Yabasic native C FFI wrapper module (`import neoui`) | | `/usr/lib/neoui.yab` | `overlay/rootfs/usr/lib/neoui.yab` | Symlink to `/home/user/Projects/neoui.yab` so `import neoui` works from any working directory | | `/home/user/Projects/neoui_demo.yab` | `overlay/rootfs/home/user/Projects/neoui_demo.yab` | Interactive 3-tab Yabasic showcase demonstrating all NeoUI widgets, multi-tap input, custom drawing, modals, and live theme reload | ### Key design principles - **Zero-flicker offscreen double buffering**: every NeoUI window (`240x296` at `X=0, Y=24`, directly below the 24px `dwm` top status bar) renders into an offscreen X11 `Pixmap` during `neoui_begin_frame()` .. `neoui_end_frame()` and copies the completed frame to the visible window in a single `XCopyArea` call. - **Automatic `.Xresources` / `.xth` theme resolution**: NeoUI automatically parses the active theme from X11 `RESOURCE_MANAGER` and `~/.Xresources`, derives 29 semantic color tokens and 4 proportional Pango font sizes (`Small`, `Main`, `Icon`, `Large` scaled from `theme.baseFontSize`), and hot-reloads on the fly whenever `RELOAD_THEME` arrives on `/tmp/dwm_plugin_.fifo` or `.Xresources` changes on disk. - **FFI-safe return types**: every `extern "C"` function in `neoui.h` returns `int` (`int32`), `uint32_t` (`uint32`), or `const char*` (`string`)—never `void`—so FFI callers like Yabasic's `frnfn_call` work without `void`-return restrictions. --- ## 2. Constants and enumerations ### 2.1 Screen geometry (`NeoGeometry`) | C constant | Yabasic constant | Value | Meaning | | :--- | :--- | :--- | :--- | | `NEO_SCREEN_W` | `neoui.SCREEN_W` | `240` | Full physical display width in pixels | | `NEO_SCREEN_H` | `neoui.SCREEN_H` | `320` | Full physical display height in pixels | | `NEO_TOPBAR_H` | `neoui.TOPBAR_H` | `24` | Height of the `dwm` top status bar | | `NEO_WIN_X` | `neoui.WIN_X` | `0` | Default app window X coordinate | | `NEO_WIN_Y` | `neoui.WIN_Y` | `24` | Default app window Y coordinate (below top bar) | | `NEO_WIN_W` | `neoui.WIN_W` | `240` | Default app window width | | `NEO_WIN_H` | `neoui.WIN_H` | `296` | Default app window height (`320 - 24`) | | `NEO_HEADER_H` | `neoui.HEADER_H` | `34` | Standard NeoUI header height | | `NEO_SOFTBAR_H` | `neoui.SOFTBAR_H` | `26` | Standard bottom softkey bar height | ### 2.2 Theme color token IDs (`NeoColorId` for `neoui_color(color_id)`) | ID | C constant | Yabasic constant | Description | | :--- | :--- | :--- | :--- | | `0` | `NEO_COLOR_BG_MAIN` | `neoui.COLOR_BG_MAIN` | Primary window background | | `1` | `NEO_COLOR_BG_BAR` | `neoui.COLOR_BG_BAR` | Top status bar background | | `2` | `NEO_COLOR_BG_HEADER` | `neoui.COLOR_BG_HEADER` | App header / tab bar background | | `3` | `NEO_COLOR_BG_FOOTER` | `neoui.COLOR_BG_FOOTER` | Bottom softkey bar background | | `4` | `NEO_COLOR_BG_OVERLAY` | `neoui.COLOR_BG_OVERLAY` | Modal / popup overlay background | | `5` | `NEO_COLOR_BG_ALT_EVEN` | `neoui.COLOR_BG_ALT_EVEN` | Alternating list row background (even) | | `6` | `NEO_COLOR_BG_ALT_ODD` | `neoui.COLOR_BG_ALT_ODD` | Alternating list row background (odd) | | `7` | `NEO_COLOR_BG_INPUT` | `neoui.COLOR_BG_INPUT` | Unfocused input box / slider track background | | `8` | `NEO_COLOR_BG_INPUT_FOCUS` | `neoui.COLOR_BG_INPUT_FOCUS` | Focused input box / active pill background | | `9` | `NEO_COLOR_BG_BUTTON` | `neoui.COLOR_BG_BUTTON` | Unselected button background | | `10` | `NEO_COLOR_BG_SEARCH` | `neoui.COLOR_BG_SEARCH` | Search bar / candidate bar background | | `11` | `NEO_COLOR_BG_BUBBLE_IN` | `neoui.COLOR_BG_BUBBLE_IN` | Incoming message bubble background | | `12` | `NEO_COLOR_BG_BUBBLE_OUT` | `neoui.COLOR_BG_BUBBLE_OUT` | Outgoing message bubble background | | `13` | `NEO_COLOR_BG_TOAST` | `neoui.COLOR_BG_TOAST` | Toast banner background | | `14` | `NEO_COLOR_FG_MAIN` | `neoui.COLOR_FG_MAIN` | Primary foreground text color | | `15` | `NEO_COLOR_FG_BRIGHT` | `neoui.COLOR_FG_BRIGHT` | High-contrast bright foreground color | | `16` | `NEO_COLOR_FG_MUTED` | `neoui.COLOR_FG_MUTED` | Muted / secondary subtitle color | | `17` | `NEO_COLOR_SEL_BG` | `neoui.COLOR_SEL_BG` | Selected row / button background | | `18` | `NEO_COLOR_SEL_FG` | `neoui.COLOR_SEL_FG` | Selected row / button foreground | | `19` | `NEO_COLOR_ACCENT` | `neoui.COLOR_ACCENT` | Primary theme accent color | | `20` | `NEO_COLOR_ACCENT_ALT` | `neoui.COLOR_ACCENT_ALT` | Secondary accent shade | | `21` | `NEO_COLOR_HIGHLIGHT` | `neoui.COLOR_HIGHLIGHT` | Bright highlight color | | `22` | `NEO_COLOR_BORDER` | `neoui.COLOR_BORDER` | Box / widget border color | | `23` | `NEO_COLOR_DIVIDER` | `neoui.COLOR_DIVIDER` | Divider line / scrollbar thumb color | | `24` | `NEO_COLOR_SUCCESS` | `neoui.COLOR_SUCCESS` | Semantic green (success / active / call) | | `25` | `NEO_COLOR_INFO` | `neoui.COLOR_INFO` | Semantic blue (info / link) | | `26` | `NEO_COLOR_WARNING` | `neoui.COLOR_WARNING` | Semantic orange (warning) | | `27` | `NEO_COLOR_DANGER` | `neoui.COLOR_DANGER` | Semantic red (danger / error / reject) | | `28` | `NEO_COLOR_DANGER_BG` | `neoui.COLOR_DANGER_BG` | Selected danger button background | ### 2.3 Font roles (`NeoFontRole`) and text color roles (`NeoTextColor`) | ID | Font role (`NeoFontRole`) | Yabasic | Description | | :--- | :--- | :--- | :--- | | `0` | `NEO_FONT_SMALL` | `neoui.FONT_SMALL` | Small UI font (`baseFontSize - 2`, min `10px`) | | `1` | `NEO_FONT_MAIN` | `neoui.FONT_MAIN` | Main UI bold font (`baseFontSize`, default `13px`) | | `2` | `NEO_FONT_ICON` | `neoui.FONT_ICON` | Nerd Font icon glyph layout (`baseFontSize + 2`, default `15px`) | | `3` | `NEO_FONT_LARGE` | `neoui.FONT_LARGE` | Large bold title/number font (`baseFontSize + 3`, default `16px`) | | ID | Text color role (`NeoTextColor`) | Yabasic | Mapped theme token | | :--- | :--- | :--- | :--- | | `0` | `NEO_TEXT_WHITE` | `neoui.TEXT_WHITE` | `theme.fgBright` | | `1` | `NEO_TEXT_LIGHT` | `neoui.TEXT_LIGHT` | `theme.fgMain` | | `2` | `NEO_TEXT_MUTED` | `neoui.TEXT_MUTED` | `theme.fgMuted` | | `3` | `NEO_TEXT_YELLOW` | `neoui.TEXT_YELLOW` | `theme.accent` | | `4` | `NEO_TEXT_GREEN` | `neoui.TEXT_GREEN` | `theme.success` | | `5` | `NEO_TEXT_BLUE` | `neoui.TEXT_BLUE` | `theme.info` | | `6` | `NEO_TEXT_ORANGE` | `neoui.TEXT_ORANGE` | `theme.warning` | | `7` | `NEO_TEXT_RED` | `neoui.TEXT_RED` | `theme.danger` | ### 2.4 Event types (`NeoEventType`) and logical keypad keys (`NeoKey`) | Event ID | C constant | Yabasic constant | Description | | :--- | :--- | :--- | :--- | | `0` | `NEO_EV_NONE` | `neoui.EV_NONE` | Timeout elapsed with no event | | `1` | `NEO_EV_EXPOSE` | `neoui.EV_EXPOSE` | Window exposed or multi-tap candidate auto-committed; redraw frame | | `2` | `NEO_EV_KEY_PRESS` | `neoui.EV_KEY_PRESS` | Keypad key pressed (query key via `neoui_event_key()`) | | `3` | `NEO_EV_KEY_RELEASE` | `neoui.EV_KEY_RELEASE` | Keypad key released | | `4` | `NEO_EV_SOFTKEY_LEFT` | `neoui.EV_SOFTKEY_LEFT` | Left softkey (`Menu` / `F1`) pressed (after chord disambiguation) | | `5` | `NEO_EV_SOFTKEY_RIGHT` | `neoui.EV_SOFTKEY_RIGHT` | Right softkey (`Back` / `F2`) pressed (after chord disambiguation) | | `6` | `NEO_EV_SOFTKEY_CHORD` | `neoui.EV_SOFTKEY_CHORD` | Both softkeys pressed together (`xdrawer` toggled automatically) | | `7` | `NEO_EV_FIFO_CMD` | `neoui.EV_FIFO_CMD` | Custom command received on `/tmp/dwm_plugin_.fifo` (`neoui_event_command()`) | | `8` | `NEO_EV_THEME_RELOAD` | `neoui.EV_THEME_RELOAD` | Theme reloaded (`RELOAD_THEME`); redraw frame | | `9` | `NEO_EV_CLOSE_REQ` | `neoui.EV_CLOSE_REQ` | `CLOSE` received on FIFO | | Key ID | C constant | Yabasic constant | Physical key | | :--- | :--- | :--- | :--- | | `0` | `NEO_KEY_NONE` | `neoui.KEY_NONE` | Unmapped key | | `1`..`4` | `NEO_KEY_UP`, `DOWN`, `LEFT`, `RIGHT` | `neoui.KEY_UP`, `KEY_DOWN`, `KEY_LEFT`, `KEY_RIGHT` | D-Pad directions | | `5` | `NEO_KEY_OK` | `neoui.KEY_OK` | Center `OK` (`Return` / `KP_Enter`) | | `6` | `NEO_KEY_BACK` | `neoui.KEY_BACK` | `BackSpace` / `Delete` / `Escape` | | `7` | `NEO_KEY_CALL` | `neoui.KEY_CALL` | Green Call / Send key (`XF86PickupPhone` / `F3`) | | `8` | `NEO_KEY_END` | `neoui.KEY_END` | Red End / Power key (`XF86HangupPhone` / `F4`) | | `9` | `NEO_KEY_SOFT_LEFT` | `neoui.KEY_SOFT_LEFT` | Left softkey (`XF86KbdLcdMenu1` / `F1`) | | `10` | `NEO_KEY_SOFT_RIGHT` | `neoui.KEY_SOFT_RIGHT` | Right softkey (`XF86KbdLcdMenu2` / `F2`) | | `32` | `NEO_KEY_SPACE` | `neoui.KEY_SPACE` | Space | | `35` | `NEO_KEY_HASH` | `neoui.KEY_HASH` | `#` key (`numbersign`) | | `42` | `NEO_KEY_STAR` | `neoui.KEY_STAR` | `*` key (`asterisk`) | | `43` | `NEO_KEY_PLUS` | `neoui.KEY_PLUS` | `+` key (`plus`) | | `48`..`57` | `NEO_KEY_0` .. `NEO_KEY_9` | `neoui.KEY_0` .. `neoui.KEY_9` | Keypad digits `0`–`9` | ### 2.5 Built-in Nerd Font icon names (`neoui_icon(name)`) Any widget parameter accepting `icon_str` (or `neoui_icon(name)`) resolves the following symbolic names to their Nerd Font UTF-8 codepoints (or passes raw UTF-8 strings through unchanged): - **Telephony and messaging**: `"phone"`, `"hangup"`, `"contacts"`, `"user"`, `"sms"`, `"reply"`, `"in_call"`, `"out_call"`, `"missed_call"`, `"sim"`, `"signal"`, `"ussd"`, `"voicemail"` - **Connectivity and hardware**: `"wifi"`, `"bluetooth"`, `"globe"`, `"hotspot"`, `"usb"`, `"torch"`, `"sun"`, `"speaker"`, `"earpiece"`, `"mute"`, `"mic"`, `"mic_off"`, `"bell"`, `"vibrate"`, `"silent"`, `"dnd"`, `"camera"`, `"battery"`, `"lock"` - **Files, media, and UI actions**: `"folder"`, `"file"`, `"image"`, `"music"`, `"Gamepad"`, `"term"`, `"theme"`, `"settings"`, `"search"`, `"plus"`, `"edit"`, `"trash"`, `"check"`, `"close"`, `"info"`, `"warning"`, `"star"`, `"refresh"`, `"copy"`, `"sort"`, `"eye"`, `"backspace"`, `"up"`, `"down"`, `"left"`, `"right"` --- ## 3. C SDK reference (`/usr/include/neoui.h`) ### 3.1 Compiling C applications on the device ```bash gcc -O2 myapp.c -lneoui -o myapp ``` ### 3.2 C function summary #### Window and daemon lifecycle ```c int neoui_init(const char* app_name, int preload_mode); int neoui_init_ex(const char* app_name, const char* res_name, const char* res_class, const char* win_title, int x, int y, int w, int h, int override_redirect, int preload_mode); int neoui_shutdown(void); int neoui_show(void); int neoui_hide(void); int neoui_is_visible(void); int neoui_raise_and_grab(void); int neoui_ungrab(void); int neoui_width(void); int neoui_height(void); int neoui_begin_frame(void); int neoui_end_frame(void); int neoui_flush(void); ``` #### Unified `.Xresources` / `.xth` theme and icon resolution ```c int neoui_reload_theme(void); int neoui_check_reload_theme(void); int neoui_apply_theme_file(const char* xth_path); int neoui_broadcast_theme_reload(const char* skip_plugin); const char* neoui_theme_name(void); const char* neoui_font_face(void); const char* neoui_icon_font_face(void); int neoui_base_font_size(void); int neoui_font_size(int font_role); uint32_t neoui_color(int color_id); uint32_t neoui_adjust_rgb(uint32_t rgb, int delta); uint32_t neoui_blend_rgb(uint32_t c1, uint32_t c2, int weight2_pct); uint32_t neoui_parse_hex_rgb(const char* hex_str, uint32_t fallback_rgb); const char* neoui_format_hex_rgb(uint32_t rgb); const char* neoui_icon(const char* icon_name); ``` #### Drawing primitives, text, and image rendering ```c int neoui_clear(uint32_t rgb); int neoui_fill_rect(int x, int y, int w, int h, uint32_t rgb); int neoui_draw_rect(int x, int y, int w, int h, uint32_t rgb); int neoui_draw_line(int x1, int y1, int x2, int y2, uint32_t rgb); int neoui_set_clip(int x, int y, int w, int h); int neoui_reset_clip(void); int neoui_draw_text(int font_role, int color_role, int x, int y, int h, const char* text, int max_w); int neoui_draw_text_centered(int font_role, int color_role, int x, int y, int w, int h, const char* text); int neoui_draw_text_right(int font_role, int color_role, int right_x, int y, int h, const char* text, int max_w); int neoui_draw_text_wrapped(int font_role, int color_role, int x, int y, int w, int h, const char* text, int scroll_line); int neoui_text_width(int font_role, const char* text); const char* neoui_tail_fit_text(int font_role, const char* text, int max_w); int neoui_draw_image_file(const char* path, int x, int y, int w, int h, int scale_mode); ``` #### Standardized OS shell widgets ```c int neoui_draw_header(const char* icon_str, int icon_color_role, const char* title, const char* right_badge); int neoui_draw_header_ex(int h, const char* icon_str, int icon_color_role, const char* title, int title_color_role, const char* right_badge, int right_color_role); int neoui_draw_tabs(const char* pipe_labels, int active_idx, int y, int h); int neoui_draw_softkeys(const char* left_label, const char* center_label, const char* right_label); int neoui_draw_softkeys_ex(const char* left_label, const char* center_label, const char* right_label, int center_color_role); int neoui_draw_list_row(int row_index, int y, int h, int is_selected, const char* icon_str, int icon_color_role, const char* title, const char* subtitle, const char* right_text); int neoui_draw_slider_row(int row_index, int y, int h, int is_selected, const char* icon_str, int icon_color_role, const char* label, int pct, const char* value_text); int neoui_draw_toggle_row(int row_index, int y, int h, int is_selected, const char* icon_str, int icon_color_role, const char* label, int is_on, const char* state_text); int neoui_draw_button(int x, int y, int w, int h, int is_selected, int is_danger, const char* icon_str, const char* label); int neoui_draw_input_box(int x, int y, int w, int h, int is_focused, const char* label, const char* value, const char* placeholder, int password_mask); int neoui_draw_progress_bar(int x, int y, int w, int h, int pct, uint32_t fill_rgb); int neoui_draw_scrollbar(int x, int y, int h, int total_items, int visible_items, int scroll_offset); int neoui_draw_modal_box(int x, int y, int w, int h, const char* icon_str, int icon_color_role, const char* title); int neoui_draw_confirm_dialog(const char* title, const char* line1, const char* line2, const char* no_label, const char* yes_label, int selected_yes); int neoui_draw_menu_popup(const char* pipe_items, const char* pipe_icons, int selected_idx, int max_visible_rows); int neoui_draw_toast(const char* message); int neoui_show_toast(const char* message, int duration_ms); int neoui_clear_toast(void); ``` #### Event loop, keypad, and multi-tap input ```c int neoui_poll_event(int timeout_ms); int neoui_event_key(void); int neoui_event_keycode(void); int neoui_event_keysym(void); const char* neoui_event_command(void); int neoui_set_chord_xdrawer(int enabled); int neoui_input_reset(const char* initial_text); int neoui_input_set_text(const char* text); const char* neoui_input_get_text(void); int neoui_input_set_mode(int mode); int neoui_input_get_mode(void); int neoui_input_cycle_mode(void); const char* neoui_input_mode_badge(void); int neoui_input_feed_key(int neo_key); int neoui_input_commit_tap(void); int neoui_input_backspace(void); int neoui_input_is_tap_active(void); const char* neoui_input_candidate_bar(const char* idle_hint); int neoui_draw_multitap_bar(int x, int y, int w, int h, const char* idle_hint); ``` #### System and IPC utilities ```c int neoui_send_plugin_cmd(const char* plugin_name, const char* cmd); int neoui_vibrate(int duration_ms); int neoui_now_ms(void); ``` ### 3.3 Minimal C example ```c #include #include static void render(int sel, int enabled, int pct) { char pct_str[16]; snprintf(pct_str, sizeof(pct_str), "%d%%", pct); neoui_begin_frame(); neoui_draw_header("settings", NEO_TEXT_YELLOW, "My NeoUI App", neoui_theme_name()); neoui_draw_toggle_row(0, 40, 38, sel == 0, "wifi", NEO_TEXT_BLUE, "Wireless Radio", enabled, enabled ? "ON" : "OFF"); neoui_draw_slider_row(1, 78, 38, sel == 1, "speaker", NEO_TEXT_GREEN, "Output Level", pct, pct_str); neoui_draw_softkeys("Toast", "Toggle", "Quit"); neoui_end_frame(); } int main(void) { if (!neoui_init("my_c_app", 0)) return 1; int sel = 0, enabled = 1, pct = 70, running = 1; render(sel, enabled, pct); while (running) { int ev = neoui_poll_event(250); if (ev == NEO_EV_CLOSE_REQ || ev == NEO_EV_SOFTKEY_RIGHT) { running = 0; } else if (ev == NEO_EV_EXPOSE || ev == NEO_EV_THEME_RELOAD) { render(sel, enabled, pct); } else if (ev == NEO_EV_SOFTKEY_LEFT) { neoui_show_toast("Hello from C!", 1800); render(sel, enabled, pct); } else if (ev == NEO_EV_KEY_PRESS) { int k = neoui_event_key(); if (k == NEO_KEY_BACK) running = 0; else if (k == NEO_KEY_UP || k == NEO_KEY_DOWN) sel = 1 - sel; else if (k == NEO_KEY_OK && sel == 0) enabled = 1 - enabled; else if (k == NEO_KEY_LEFT && sel == 1 && pct >= 5) pct -= 5; else if (k == NEO_KEY_RIGHT && sel == 1 && pct <= 95) pct += 5; render(sel, enabled, pct); } } neoui_shutdown(); return 0; } ``` --- ## 4. C++20 SDK reference (`namespace bananarchy`) When `#include ` is compiled under C++, it also exposes the `bananarchy` namespace used by Bananarchy's native DWM plugins (`src/dwm-plugins/*.cpp` and `src/xdrawer/xdrawer.cpp`). ### 4.1 Compiling C++ applications or plugins ```bash g++ -O2 -std=c++17 myapp.cpp \ $(pkgconf --cflags --libs x11 xft fontconfig freetype2 pango pangoxft) \ -lneoui -o myapp ``` ### 4.2 Core C++ classes and helpers - **`bananarchy::ThemeSpec`**: - Holds all 29 RGB color tokens (`bgMain`, `bgHeader`, `bgFooter`, `selBg`, `selFg`, `accent`, `fgMain`, `fgBright`, `fgMuted`, `border`, `divider`, `success`, `info`, `warning`, `danger`, etc.), `fontFace`, `iconFontFace`, and `baseFontSize`. - Methods: `loadActive(dpy, screen)`, `loadFromFile(path)`, `saveToFile(path)`, `serializeXresources()`, `recomputeDerivedFromCore()`, `colorById(id)`, `sizeSmall()`, `sizeMain()`, `sizeIcon()`, `sizeLarge()`. - **`bananarchy::PluginTheme`**: - Manages allocated `XftColor` instances (`colWhite`, `colLight`, `colMuted`, `colYellow`, `colGreen`, `colBlue`, `colOrange`, `colRed`) and `PangoLayout*` instances (`layoutMain`, `layoutSmall`, `layoutIcon`, `layoutNum`) with automatic `.Xresources` mtime/size change detection (`checkAndReload()`). - **`bananarchy::NeoWindow`**: - RAII wrapper managing the X11 `Display*`, `Window`, offscreen `Pixmap`, `GC`, `XftDraw*`, `PangoContext*`, `PangoLayout*` (`layoutMain`, `layoutSmall`, `layoutIcon`, `layoutNum`), and `PluginTheme theme`. - Methods: - `bool create(resName, resClass, title, winX, winY, winW, winH, overrideRedirect, eventMask)` - `void destroy()` - `int drawPango(layout, color, x, y, h, text, maxW = -1, align = 0)` (`align`: `0=left`, `1=center`, `2=right`) - `int pangoWidth(layout, text)` - `void drawSoftbar(leftLabel, centerLabel, rightLabel, centerCol = nullptr, softbarH = 26)` - `void drawScrollbar(x, y, h, totalItems, visibleItems, scrollOffset)` - `void drawToast(msg, softbarH = 26)` - `void clearBg()` / `void present()` - `bool checkReloadTheme()` / `void reloadTheme()` - **Shared text, multi-tap, and image helpers in `libneoui.so`**: - `std::string formatMultiTapBar(prefix, table, activeIdx, makeUpper, maxItems = 7, maxChars = 21)`: formats a scrolling candidate bar window centered around `activeIdx` so long symbol sequences (such as the 33-character `1` key table) never overflow the `240px` viewport. - `std::string tailFitPangoText(layout, text, maxWidthPx)`: returns the UTF-8 suffix of `text` that fits within `maxWidthPx`. - `bool loadImageRgb24(path, &outRgb, &outW, &outH)`: decodes JPEG (`libjpeg-turbo`), PNG (`libpng`), or other formats (`ffmpeg` fallback) into 24-bit RGB. - `void scaleRgb24ToBgrxCanvas(srcRgb, srcW, srcH, dstBgrx, canvasW, canvasH, bgPixel, scaleMode)`: scales 24-bit RGB into a 32-bit BGRX `XImage` buffer (`NEO_SCALE_FIT`, `NEO_SCALE_FILL`, or `NEO_SCALE_STRETCH`). - `void downscaleViewfinder800x600To240x180(srcRgb, dstBgrx, zoomFactor)`: rotates the raw `800x600` `GC2395` camera frame 90 degrees clockwise and samples the centered 4:3 region (`600x450`) into the `240x180` viewfinder buffer. - `bool saveRgb24AsJpeg(path, rgb, width, height, quality = 92)` - `std::string formatFileSize(bytes)` --- ## 5. Yabasic SDK reference (`neoui.yab`) Bananarchy includes `/home/user/Projects/neoui.yab` (symlinked to `/usr/lib/neoui.yab`), which wraps every C FFI function in `/usr/lib/libneoui.so` using Yabasic's native `libffi` foreign function interface (`frnfn_call` and `frnfn_call$`). ### 5.1 Running Yabasic NeoUI programs - **From the file manager (`xfiles`)**: navigate to `/home/user/Projects/`, highlight `neoui_demo.yab` (or your own `.yab` file), and press **Center `OK` (`Return`)**. - **From a terminal or SSH**: ```bash DISPLAY=:0 yabasic ~/Projects/neoui_demo.yab ``` ### 5.2 Importing `neoui.yab` Because `/usr/lib/neoui.yab` is symlinked to `/home/user/Projects/neoui.yab`, any `.yab` script in any directory can import `neoui` with a single line: ```yabasic import neoui ``` - All exported subroutines can be called directly (e.g. `neoui_init("myapp", 0)`, `neoui_draw_header(...)`) or qualified with `neoui.` (`neoui.neoui_init(...)`). - All module constants are accessed with the `neoui.` prefix (e.g. `neoui.TEXT_YELLOW`, `neoui.FONT_MAIN`, `neoui.COLOR_ACCENT`, `neoui.EV_KEY_PRESS`, `neoui.KEY_OK`). ### 5.3 Exported Yabasic functions in `neoui.yab` #### 1. Window and frame lifecycle - `neoui_init(app_name$, preload_mode)` -> `1` on success, `0` on error - `neoui_init_ex(app_name$, res_name$, res_class$, win_title$, x, y, w, h, override_redirect, preload_mode)` - `neoui_shutdown()` - `neoui_show()` / `neoui_hide()` / `neoui_is_visible()` - `neoui_raise_and_grab()` / `neoui_ungrab()` - `neoui_width()` / `neoui_height()` - `neoui_begin_frame()` / `neoui_end_frame()` / `neoui_flush()` #### 2. Theme, color, and icon resolution - `neoui_reload_theme()` / `neoui_check_reload_theme()` - `neoui_apply_theme_file(xth_path$)` / `neoui_broadcast_theme_reload(skip_plugin$)` - `neoui_theme_name$()` / `neoui_font_face$()` / `neoui_icon_font_face$()` - `neoui_base_font_size()` / `neoui_font_size(font_role)` - `neoui_color(color_id)` - `neoui_adjust_rgb(rgb, delta)` / `neoui_blend_rgb(c1, c2, weight2_pct)` - `neoui_parse_hex_rgb(hex_str$, fallback_rgb)` / `neoui_format_hex_rgb$(rgb)` - `neoui_icon$(icon_name$)` #### 3. Drawing primitives, text, and images - `neoui_clear(rgb)` - `neoui_fill_rect(x, y, w, h, rgb)` / `neoui_draw_rect(x, y, w, h, rgb)` - `neoui_draw_line(x1, y1, x2, y2, rgb)` - `neoui_set_clip(x, y, w, h)` / `neoui_reset_clip()` - `neoui_draw_text(font_role, color_role, x, y, h, text$, max_w)` - `neoui_draw_text_centered(font_role, color_role, x, y, w, h, text$)` - `neoui_draw_text_right(font_role, color_role, right_x, y, h, text$, max_w)` - `neoui_draw_text_wrapped(font_role, color_role, x, y, w, h, text$, scroll_line)` - `neoui_text_width(font_role, text$)` / `neoui_tail_fit_text$(font_role, text$, max_w)` - `neoui_draw_image_file(path$, x, y, w, h, scale_mode)` #### 4. Standardized OS shell widgets - `neoui_draw_header(icon_str$, icon_color_role, title$, right_badge$)` - `neoui_draw_header_ex(h, icon_str$, icon_color_role, title$, title_color_role, right_badge$, right_color_role)` - `neoui_draw_tabs(pipe_labels$, active_idx, y, h)` - `neoui_draw_softkeys(left_label$, center_label$, right_label$)` - `neoui_draw_softkeys_ex(left_label$, center_label$, right_label$, center_color_role)` - `neoui_draw_list_row(row_index, y, h, is_selected, icon_str$, icon_color_role, title$, subtitle$, right_text$)` - `neoui_draw_slider_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, pct, value_text$)` - `neoui_draw_toggle_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, is_on, state_text$)` - `neoui_draw_button(x, y, w, h, is_selected, is_danger, icon_str$, label$)` - `neoui_draw_input_box(x, y, w, h, is_focused, label$, value$, placeholder$, password_mask)` - `neoui_draw_progress_bar(x, y, w, h, pct, fill_rgb)` - `neoui_draw_scrollbar(x, y, h, total_items, visible_items, scroll_offset)` - `neoui_draw_modal_box(x, y, w, h, icon_str$, icon_color_role, title$)` - `neoui_draw_confirm_dialog(title$, line1$, line2$, no_label$, yes_label$, selected_yes)` - `neoui_draw_menu_popup(pipe_items$, pipe_icons$, selected_idx, max_visible_rows)` - `neoui_draw_toast(message$)` / `neoui_show_toast(message$, duration_ms)` / `neoui_clear_toast()` #### 5. Event loop, keypad, and multi-tap input - `neoui_poll_event(timeout_ms)` - `neoui_event_key()` / `neoui_event_keycode()` / `neoui_event_keysym()` / `neoui_event_command$()` - `neoui_set_chord_xdrawer(enabled)` - `neoui_input_reset(initial_text$)` / `neoui_input_set_text(text$)` / `neoui_input_get_text$()` - `neoui_input_set_mode(mode)` / `neoui_input_get_mode()` / `neoui_input_cycle_mode()` / `neoui_input_mode_badge$()` - `neoui_input_feed_key(neo_key)` / `neoui_input_commit_tap()` / `neoui_input_backspace()` / `neoui_input_is_tap_active()` - `neoui_input_candidate_bar$(idle_hint$)` / `neoui_draw_multitap_bar(x, y, w, h, idle_hint$)` #### 6. System and IPC utilities - `neoui_send_plugin_cmd(plugin_name$, cmd$)` - `neoui_vibrate(duration_ms)` - `neoui_now_ms()` ### 5.4 Minimal Yabasic starter template ```yabasic #!/usr/bin/yabasic import neoui if neoui_init("hello_neoui", 0) = 0 then print "Failed to open X11 window" exit 1 fi sel = 0 count = 0 sub render() neoui_begin_frame() neoui_draw_header(neoui_icon$("star"), neoui.TEXT_YELLOW, "Hello NeoUI", neoui_theme_name$()) neoui_draw_list_row(0, 42, 38, sel = 0, neoui_icon$("plus"), neoui.TEXT_GREEN, "Increment Counter", "Press OK to add 1", str$(count)) neoui_draw_list_row(1, 80, 38, sel = 1, neoui_icon$("bell"), neoui.TEXT_BLUE, "Vibrate & Toast", "Test haptic feedback", "60ms") neoui_draw_softkeys("Toast", "Select", "Quit") neoui_end_frame() end sub render() running = 1 while running ev = neoui_poll_event(250) if ev = neoui.EV_CLOSE_REQ or ev = neoui.EV_SOFTKEY_RIGHT then running = 0 elsif ev = neoui.EV_EXPOSE or ev = neoui.EV_THEME_RELOAD then render() elsif ev = neoui.EV_SOFTKEY_LEFT then neoui_show_toast("Theme: " + neoui_theme_name$(), 1500) render() elsif ev = neoui.EV_KEY_PRESS then k = neoui_event_key() if k = neoui.KEY_BACK then running = 0 elsif k = neoui.KEY_UP or k = neoui.KEY_DOWN then sel = 1 - sel elsif k = neoui.KEY_OK then if sel = 0 then count = count + 1 else neoui_vibrate(60) neoui_show_toast("Counter = " + str$(count), 1500) fi fi render() fi wend neoui_shutdown() ```