Files
bananarchy/overlay/rootfs/home/user/Projects/neoui.yab
T

486 lines
18 KiB
Plaintext

// ============================================================================
// neoui.yab - Yabasic Native C FFI Wrapper for Bananarchy NeoUI (libneoui.so)
// ============================================================================
// Exposes all NeoUI 240x320 X11 + Pango/Xft + .Xresources/.xth UI SDK
// functions to Yabasic programs via libffi (frnfn_call / frnfn_call$).
//
// Usage in your Yabasic program:
// import neoui
// neoui_init("myapp", 0)
// ============================================================================
NEOUI_LIB$ = "/usr/lib/libneoui.so"
// ----------------------------------------------------------------------------
// Geometry Constants (240x320 QVGA)
// ----------------------------------------------------------------------------
SCREEN_W = 240
SCREEN_H = 320
TOPBAR_H = 24
WIN_X = 0
WIN_Y = 24
WIN_W = 240
WIN_H = 296
HEADER_H = 34
SOFTBAR_H = 26
// ----------------------------------------------------------------------------
// Theme Color Token IDs for neoui_color(color_id)
// ----------------------------------------------------------------------------
COLOR_BG_MAIN = 0
COLOR_BG_BAR = 1
COLOR_BG_HEADER = 2
COLOR_BG_FOOTER = 3
COLOR_BG_OVERLAY = 4
COLOR_BG_ALT_EVEN = 5
COLOR_BG_ALT_ODD = 6
COLOR_BG_INPUT = 7
COLOR_BG_INPUT_FOCUS = 8
COLOR_BG_BUTTON = 9
COLOR_BG_SEARCH = 10
COLOR_BG_BUBBLE_IN = 11
COLOR_BG_BUBBLE_OUT = 12
COLOR_BG_TOAST = 13
COLOR_FG_MAIN = 14
COLOR_FG_BRIGHT = 15
COLOR_FG_MUTED = 16
COLOR_SEL_BG = 17
COLOR_SEL_FG = 18
COLOR_ACCENT = 19
COLOR_ACCENT_ALT = 20
COLOR_HIGHLIGHT = 21
COLOR_BORDER = 22
COLOR_DIVIDER = 23
COLOR_SUCCESS = 24
COLOR_INFO = 25
COLOR_WARNING = 26
COLOR_DANGER = 27
COLOR_DANGER_BG = 28
// ----------------------------------------------------------------------------
// Proportional Pango Font Roles
// ----------------------------------------------------------------------------
FONT_SMALL = 0
FONT_MAIN = 1
FONT_ICON = 2
FONT_LARGE = 3
// ----------------------------------------------------------------------------
// Semantic Xft Text Color Roles
// ----------------------------------------------------------------------------
TEXT_WHITE = 0
TEXT_LIGHT = 1
TEXT_MUTED = 2
TEXT_YELLOW = 3
TEXT_GREEN = 4
TEXT_BLUE = 5
TEXT_ORANGE = 6
TEXT_RED = 7
// ----------------------------------------------------------------------------
// Event Types returned by neoui_poll_event(timeout_ms)
// ----------------------------------------------------------------------------
EV_NONE = 0
EV_EXPOSE = 1
EV_KEY_PRESS = 2
EV_KEY_RELEASE = 3
EV_SOFTKEY_LEFT = 4
EV_SOFTKEY_RIGHT = 5
EV_SOFTKEY_CHORD = 6
EV_FIFO_CMD = 7
EV_THEME_RELOAD = 8
EV_CLOSE_REQ = 9
// ----------------------------------------------------------------------------
// Logical Keypad Key Codes returned by neoui_event_key()
// ----------------------------------------------------------------------------
KEY_NONE = 0
KEY_UP = 1
KEY_DOWN = 2
KEY_LEFT = 3
KEY_RIGHT = 4
KEY_OK = 5
KEY_BACK = 6
KEY_CALL = 7
KEY_END = 8
KEY_SOFT_LEFT = 9
KEY_SOFT_RIGHT = 10
KEY_SPACE = 32
KEY_HASH = 35
KEY_STAR = 42
KEY_PLUS = 43
KEY_0 = 48
KEY_1 = 49
KEY_2 = 50
KEY_3 = 51
KEY_4 = 52
KEY_5 = 53
KEY_6 = 54
KEY_7 = 55
KEY_8 = 56
KEY_9 = 57
// ----------------------------------------------------------------------------
// Multi-Tap Input Modes
// ----------------------------------------------------------------------------
INPUT_ABC_TITLE = 0
INPUT_ABC_LOWER = 1
INPUT_ABC_UPPER = 2
INPUT_123 = 3
INPUT_SYM = 4
// ----------------------------------------------------------------------------
// Image Scaling Modes
// ----------------------------------------------------------------------------
SCALE_FIT = 0
SCALE_FILL = 1
SCALE_STRETCH = 2
// ============================================================================
// 1. Window & Daemon Lifecycle
// ============================================================================
export sub neoui_init(app_name$, preload_mode)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_init", "string", app_name$, "int32", preload_mode)
end sub
export sub neoui_init_ex(app_name$, res_name$, res_class$, win_title$, x, y, w, h, override_redirect, preload_mode)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_init_ex", "string", app_name$, "string", res_name$, "string", res_class$, "string", win_title$, "int32", x, "int32", y, "int32", w, "int32", h, "int32", override_redirect, "int32", preload_mode)
end sub
export sub neoui_shutdown()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_shutdown")
end sub
export sub neoui_show()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_show")
end sub
export sub neoui_hide()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_hide")
end sub
export sub neoui_is_visible()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_is_visible")
end sub
export sub neoui_raise_and_grab()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_raise_and_grab")
end sub
export sub neoui_ungrab()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_ungrab")
end sub
export sub neoui_width()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_width")
end sub
export sub neoui_height()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_height")
end sub
export sub neoui_begin_frame()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_begin_frame")
end sub
export sub neoui_end_frame()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_end_frame")
end sub
export sub neoui_flush()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_flush")
end sub
// ============================================================================
// 2. Unified .Xresources / .xth Theme & Icon Resolution
// ============================================================================
export sub neoui_reload_theme()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_reload_theme")
end sub
export sub neoui_check_reload_theme()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_check_reload_theme")
end sub
export sub neoui_apply_theme_file(xth_path$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_apply_theme_file", "string", xth_path$)
end sub
export sub neoui_broadcast_theme_reload(skip_plugin$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_broadcast_theme_reload", "string", skip_plugin$)
end sub
export sub neoui_theme_name$()
return frnfn_call$(NEOUI_LIB$, "string", "neoui_theme_name", "options", "copy_string_result")
end sub
export sub neoui_font_face$()
return frnfn_call$(NEOUI_LIB$, "string", "neoui_font_face", "options", "copy_string_result")
end sub
export sub neoui_icon_font_face$()
return frnfn_call$(NEOUI_LIB$, "string", "neoui_icon_font_face", "options", "copy_string_result")
end sub
export sub neoui_base_font_size()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_base_font_size")
end sub
export sub neoui_font_size(font_role)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_font_size", "int32", font_role)
end sub
export sub neoui_color(color_id)
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_color", "int32", color_id)
end sub
export sub neoui_adjust_rgb(rgb, delta)
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_adjust_rgb", "uint32", rgb, "int32", delta)
end sub
export sub neoui_blend_rgb(c1, c2, weight2_pct)
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_blend_rgb", "uint32", c1, "uint32", c2, "int32", weight2_pct)
end sub
export sub neoui_parse_hex_rgb(hex_str$, fallback_rgb)
return frnfn_call(NEOUI_LIB$, "uint32", "neoui_parse_hex_rgb", "string", hex_str$, "uint32", fallback_rgb)
end sub
export sub neoui_format_hex_rgb$(rgb)
return frnfn_call$(NEOUI_LIB$, "string", "neoui_format_hex_rgb", "uint32", rgb, "options", "copy_string_result")
end sub
export sub neoui_icon$(icon_name$)
return frnfn_call$(NEOUI_LIB$, "string", "neoui_icon", "string", icon_name$, "options", "copy_string_result")
end sub
// ============================================================================
// 3. Drawing Primitives & Text Rendering
// ============================================================================
export sub neoui_clear(rgb)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_clear", "uint32", rgb)
end sub
export sub neoui_fill_rect(x, y, w, h, rgb)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_fill_rect", "int32", x, "int32", y, "int32", w, "int32", h, "uint32", rgb)
end sub
export sub neoui_draw_rect(x, y, w, h, rgb)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_rect", "int32", x, "int32", y, "int32", w, "int32", h, "uint32", rgb)
end sub
export sub neoui_draw_line(x1, y1, x2, y2, rgb)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_line", "int32", x1, "int32", y1, "int32", x2, "int32", y2, "uint32", rgb)
end sub
export sub neoui_set_clip(x, y, w, h)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_set_clip", "int32", x, "int32", y, "int32", w, "int32", h)
end sub
export sub neoui_reset_clip()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_reset_clip")
end sub
export sub neoui_draw_text(font_role, color_role, x, y, h, text$, max_w)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text", "int32", font_role, "int32", color_role, "int32", x, "int32", y, "int32", h, "string", text$, "int32", max_w)
end sub
export sub neoui_draw_text_centered(font_role, color_role, x, y, w, h, text$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text_centered", "int32", font_role, "int32", color_role, "int32", x, "int32", y, "int32", w, "int32", h, "string", text$)
end sub
export sub neoui_draw_text_right(font_role, color_role, right_x, y, h, text$, max_w)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text_right", "int32", font_role, "int32", color_role, "int32", right_x, "int32", y, "int32", h, "string", text$, "int32", max_w)
end sub
export sub neoui_draw_text_wrapped(font_role, color_role, x, y, w, h, text$, scroll_line)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_text_wrapped", "int32", font_role, "int32", color_role, "int32", x, "int32", y, "int32", w, "int32", h, "string", text$, "int32", scroll_line)
end sub
export sub neoui_text_width(font_role, text$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_text_width", "int32", font_role, "string", text$)
end sub
export sub neoui_tail_fit_text$(font_role, text$, max_w)
return frnfn_call$(NEOUI_LIB$, "string", "neoui_tail_fit_text", "int32", font_role, "string", text$, "int32", max_w, "options", "copy_string_result")
end sub
export sub neoui_draw_image_file(path$, x, y, w, h, scale_mode)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_image_file", "string", path$, "int32", x, "int32", y, "int32", w, "int32", h, "int32", scale_mode)
end sub
// ============================================================================
// 4. Standardized OS Shell UI Components (Widgets)
// ============================================================================
export sub neoui_draw_header(icon_str$, icon_color_role, title$, right_badge$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_header", "string", icon_str$, "int32", icon_color_role, "string", title$, "string", right_badge$)
end sub
export sub neoui_draw_header_ex(h, icon_str$, icon_color_role, title$, title_color_role, right_badge$, right_color_role)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_header_ex", "int32", h, "string", icon_str$, "int32", icon_color_role, "string", title$, "int32", title_color_role, "string", right_badge$, "int32", right_color_role)
end sub
export sub neoui_draw_tabs(pipe_labels$, active_idx, y, h)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_tabs", "string", pipe_labels$, "int32", active_idx, "int32", y, "int32", h)
end sub
export sub neoui_draw_softkeys(left_label$, center_label$, right_label$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_softkeys", "string", left_label$, "string", center_label$, "string", right_label$)
end sub
export sub neoui_draw_softkeys_ex(left_label$, center_label$, right_label$, center_color_role)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_softkeys_ex", "string", left_label$, "string", center_label$, "string", right_label$, "int32", center_color_role)
end sub
export sub neoui_draw_list_row(row_index, y, h, is_selected, icon_str$, icon_color_role, title$, subtitle$, right_text$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_list_row", "int32", row_index, "int32", y, "int32", h, "int32", is_selected, "string", icon_str$, "int32", icon_color_role, "string", title$, "string", subtitle$, "string", right_text$)
end sub
export sub neoui_draw_slider_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, pct, value_text$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_slider_row", "int32", row_index, "int32", y, "int32", h, "int32", is_selected, "string", icon_str$, "int32", icon_color_role, "string", label$, "int32", pct, "string", value_text$)
end sub
export sub neoui_draw_toggle_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, is_on, state_text$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_toggle_row", "int32", row_index, "int32", y, "int32", h, "int32", is_selected, "string", icon_str$, "int32", icon_color_role, "string", label$, "int32", is_on, "string", state_text$)
end sub
export sub neoui_draw_button(x, y, w, h, is_selected, is_danger, icon_str$, label$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_button", "int32", x, "int32", y, "int32", w, "int32", h, "int32", is_selected, "int32", is_danger, "string", icon_str$, "string", label$)
end sub
export sub neoui_draw_input_box(x, y, w, h, is_focused, label$, value$, placeholder$, password_mask)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_input_box", "int32", x, "int32", y, "int32", w, "int32", h, "int32", is_focused, "string", label$, "string", value$, "string", placeholder$, "int32", password_mask)
end sub
export sub neoui_draw_progress_bar(x, y, w, h, pct, fill_rgb)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_progress_bar", "int32", x, "int32", y, "int32", w, "int32", h, "int32", pct, "uint32", fill_rgb)
end sub
export sub neoui_draw_scrollbar(x, y, h, total_items, visible_items, scroll_offset)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_scrollbar", "int32", x, "int32", y, "int32", h, "int32", total_items, "int32", visible_items, "int32", scroll_offset)
end sub
export sub neoui_draw_modal_box(x, y, w, h, icon_str$, icon_color_role, title$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_modal_box", "int32", x, "int32", y, "int32", w, "int32", h, "string", icon_str$, "int32", icon_color_role, "string", title$)
end sub
export sub neoui_draw_confirm_dialog(title$, line1$, line2$, no_label$, yes_label$, selected_yes)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_confirm_dialog", "string", title$, "string", line1$, "string", line2$, "string", no_label$, "string", yes_label$, "int32", selected_yes)
end sub
export sub neoui_draw_menu_popup(pipe_items$, pipe_icons$, selected_idx, max_visible_rows)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_menu_popup", "string", pipe_items$, "string", pipe_icons$, "int32", selected_idx, "int32", max_visible_rows)
end sub
export sub neoui_draw_toast(message$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_toast", "string", message$)
end sub
export sub neoui_show_toast(message$, duration_ms)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_show_toast", "string", message$, "int32", duration_ms)
end sub
export sub neoui_clear_toast()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_clear_toast")
end sub
// ============================================================================
// 5. Event Loop, Keypad & Multi-Tap Input Management
// ============================================================================
export sub neoui_poll_event(timeout_ms)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_poll_event", "int32", timeout_ms)
end sub
export sub neoui_event_key()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_event_key")
end sub
export sub neoui_event_keycode()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_event_keycode")
end sub
export sub neoui_event_keysym()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_event_keysym")
end sub
export sub neoui_event_command$()
return frnfn_call$(NEOUI_LIB$, "string", "neoui_event_command", "options", "copy_string_result")
end sub
export sub neoui_set_chord_xdrawer(enabled)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_set_chord_xdrawer", "int32", enabled)
end sub
export sub neoui_input_reset(initial_text$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_reset", "string", initial_text$)
end sub
export sub neoui_input_set_text(text$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_set_text", "string", text$)
end sub
export sub neoui_input_get_text$()
return frnfn_call$(NEOUI_LIB$, "string", "neoui_input_get_text", "options", "copy_string_result")
end sub
export sub neoui_input_set_mode(mode)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_set_mode", "int32", mode)
end sub
export sub neoui_input_get_mode()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_get_mode")
end sub
export sub neoui_input_cycle_mode()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_cycle_mode")
end sub
export sub neoui_input_mode_badge$()
return frnfn_call$(NEOUI_LIB$, "string", "neoui_input_mode_badge", "options", "copy_string_result")
end sub
export sub neoui_input_feed_key(neo_key)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_feed_key", "int32", neo_key)
end sub
export sub neoui_input_commit_tap()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_commit_tap")
end sub
export sub neoui_input_backspace()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_backspace")
end sub
export sub neoui_input_is_tap_active()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_input_is_tap_active")
end sub
export sub neoui_input_candidate_bar$(idle_hint$)
return frnfn_call$(NEOUI_LIB$, "string", "neoui_input_candidate_bar", "string", idle_hint$, "options", "copy_string_result")
end sub
export sub neoui_draw_multitap_bar(x, y, w, h, idle_hint$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_draw_multitap_bar", "int32", x, "int32", y, "int32", w, "int32", h, "string", idle_hint$)
end sub
// ============================================================================
// 6. System & IPC Utilities
// ============================================================================
export sub neoui_send_plugin_cmd(plugin_name$, cmd$)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_send_plugin_cmd", "string", plugin_name$, "string", cmd$)
end sub
export sub neoui_vibrate(duration_ms)
return frnfn_call(NEOUI_LIB$, "int32", "neoui_vibrate", "int32", duration_ms)
end sub
export sub neoui_now_ms()
return frnfn_call(NEOUI_LIB$, "int32", "neoui_now_ms")
end sub