#!/usr/bin/yabasic // ============================================================================ // neoui_demo.yab - Bananarchy NeoUI SDK Showcase for Yabasic // ============================================================================ // Demonstrates: // - Live .Xresources / ~/.xthemes/*.xth theme resolution & hot-reload // - Header bar, 3-Tab navigation bar, and Softkey bar // - List rows, Toggle rows, Slider rows, Progress bars, and Buttons // - Multi-tap T9 keypad text input with scrolling candidate bar & mode badge // - Custom drawing primitives, Nerd Font icons, and theme color swatches // - Popup action menu, Confirmation dialog, and Toast notification banner // // Controls: // - 1 / 2 / 3 (when not typing): Switch tabs (Widgets / Input / Theme) // - Up / Down: Navigate rows or menu items // - Left / Right: Adjust sliders, switch tabs, or toggle No/Yes in dialog // - OK (Enter): Toggle item / Submit text / Trigger action // - Left Softkey (F1): Open Action Menu // - Right Softkey (F2) / Backspace: Close modal / Delete char / Exit // - Both Softkeys together: Open Bananarchy XDrawer overlay // ============================================================================ import neoui if neoui_init("neoui_demo", 0) = 0 then print "Failed to initialize NeoUI X11 window" exit 1 fi // Tab index: 0 = Widgets, 1 = Input, 2 = Theme & Canvas active_tab = 0 // Tab 0 (Widgets) state widget_sel = 0 wifi_enabled = 1 torch_enabled = 0 volume_pct = 75 bright_pct = 80 progress_pct = 45 // Tab 1 (Multi-Tap Input) state input_focus = 0 dim notes$(10) notes$(0) = "Welcome to NeoUI SDK!" notes$(1) = "Try typing with 0-9 keys" notes$(2) = "Press # to switch mode" note_count = 3 neoui_input_reset("Bananarchy ") // Modal state: 0 = None, 1 = Popup Menu, 2 = Confirm Reset Dialog modal_mode = 0 menu_sel = 0 confirm_yes = 0 sub render_widgets_tab() local y, wifi_txt$, torch_txt$, vol_txt$, brt_txt$ y = 60 if wifi_enabled then wifi_txt$ = "Connected" else wifi_txt$ = "Off" fi neoui_draw_toggle_row(0, y, 36, widget_sel = 0, neoui_icon$("wifi"), neoui.TEXT_BLUE, "Wi-Fi Radio", wifi_enabled, wifi_txt$) y = y + 36 if torch_enabled then torch_txt$ = "Active" else torch_txt$ = "Off" fi neoui_draw_toggle_row(1, y, 36, widget_sel = 1, neoui_icon$("torch"), neoui.TEXT_YELLOW, "Flashlight", torch_enabled, torch_txt$) y = y + 36 vol_txt$ = str$(volume_pct) + "%" neoui_draw_slider_row(2, y, 38, widget_sel = 2, neoui_icon$("speaker"), neoui.TEXT_GREEN, "Speaker Vol", volume_pct, vol_txt$) y = y + 38 brt_txt$ = str$(bright_pct) + "%" neoui_draw_slider_row(3, y, 38, widget_sel = 3, neoui_icon$("sun"), neoui.TEXT_ORANGE, "Backlight", bright_pct, brt_txt$) y = y + 42 neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 8, y, 14, "Task Progress (" + str$(progress_pct) + "%)", 160) neoui_draw_progress_bar(8, y + 15, 224, 10, progress_pct, neoui_color(neoui.COLOR_ACCENT)) y = y + 30 neoui_draw_button(12, y, 104, 26, widget_sel = 4, 0, neoui_icon$("check"), "Step +15%") neoui_draw_button(124, y, 104, 26, widget_sel = 5, 1, neoui_icon$("trash"), "Reset All") neoui_draw_scrollbar(236, 60, 210, 6, 6, 0) end sub sub render_input_tab() local i, y, txt$, badge$ txt$ = neoui_input_get_text$() badge$ = neoui_input_mode_badge$() neoui_draw_input_box(8, 64, 224, 42, input_focus = 0, "Multi-Tap Keypad Input [" + badge$ + "]", txt$, "Type with 0-9, # mode...", 0) neoui_draw_button(8, 110, 108, 24, input_focus = 1, 0, neoui_icon$("plus"), "Add Note") neoui_draw_button(124, 110, 108, 24, input_focus = 2, 0, neoui_icon$("refresh"), "Clear Text") neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 8, 138, 16, "Saved Notes (" + str$(note_count) + "):", 220) y = 156 for i = 0 to note_count - 1 if y + 28 <= 246 then neoui_draw_list_row(i, y, 28, input_focus = (3 + i), neoui_icon$("edit"), neoui.TEXT_BLUE, notes$(i), "", "#" + str$(i + 1)) y = y + 28 fi next i if input_focus = 0 then neoui_draw_multitap_bar(0, 248, 240, 22, "0-9:Type 1:Sym #:Mode OK:Add") fi end sub sub render_theme_tab() local y, c_id, sx, sy, sw, sh, rgb y = 64 neoui_fill_rect(8, y, 224, 68, neoui_color(neoui.COLOR_BG_ALT_ODD)) neoui_draw_rect(8, y, 224, 68, neoui_color(neoui.COLOR_BORDER)) neoui_draw_text(neoui.FONT_MAIN, neoui.TEXT_YELLOW, 14, y + 4, 18, "Theme: " + neoui_theme_name$(), 210) neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_LIGHT, 14, y + 24, 16, "Font: " + neoui_font_face$() + " (" + str$(neoui_base_font_size()) + "px)", 210) neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 14, y + 42, 16, "BG: " + neoui_format_hex_rgb$(neoui_color(neoui.COLOR_BG_MAIN)) + " ACC: " + neoui_format_hex_rgb$(neoui_color(neoui.COLOR_ACCENT)), 210) y = 138 neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_WHITE, 8, y, 16, "Active .Xresources Palette Swatches:", 224) y = 158 sw = 26 sh = 22 for c_id = 0 to 15 sx = 8 + mod(c_id, 8) * 28 sy = y + int(c_id / 8) * 26 rgb = neoui_color(c_id + 13) neoui_fill_rect(sx, sy, sw, sh, rgb) neoui_draw_rect(sx, sy, sw, sh, neoui_color(neoui.COLOR_BORDER)) next c_id y = 214 neoui_fill_rect(8, y, 224, 48, neoui_color(neoui.COLOR_BG_HEADER)) neoui_draw_rect(8, y, 224, 48, neoui_color(neoui.COLOR_ACCENT)) neoui_draw_line(14, y + 24, 226, y + 24, neoui_color(neoui.COLOR_DIVIDER)) neoui_draw_text_centered(neoui.FONT_ICON, neoui.TEXT_YELLOW, 8, y + 2, 224, 20, neoui_icon$("phone") + " " + neoui_icon$("sms") + " " + neoui_icon$("music") + " " + neoui_icon$("camera") + " " + neoui_icon$("theme") + " " + neoui_icon$("wifi")) neoui_draw_text_centered(neoui.FONT_SMALL, neoui.TEXT_GREEN, 8, y + 26, 224, 18, "Press OK to hot-reload .Xresources") end sub sub render_all() local badge$, mid_lbl$, right_lbl$ neoui_begin_frame() if active_tab = 1 then badge$ = neoui_input_mode_badge$() else badge$ = neoui_theme_name$() fi neoui_draw_header(neoui_icon$("theme"), neoui.TEXT_YELLOW, "NeoUI SDK Demo", badge$) neoui_draw_tabs("1:Widgets|2:Input|3:Theme", active_tab, 34, 24) if active_tab = 0 then render_widgets_tab() mid_lbl$ = "Toggle" right_lbl$ = "Quit" elsif active_tab = 1 then render_input_tab() mid_lbl$ = "Add" if input_focus = 0 and len(neoui_input_get_text$()) > 0 then right_lbl$ = "Del" else right_lbl$ = "Quit" fi else render_theme_tab() mid_lbl$ = "Reload" right_lbl$ = "Quit" fi if modal_mode = 1 then neoui_draw_menu_popup("Show Toast Banner|Vibrate Phone|Reload Theme|Reset Demo State|Quit Demo", neoui_icon$("bell") + "|" + neoui_icon$("audio") + "|" + neoui_icon$("refresh") + "|" + neoui_icon$("trash") + "|" + neoui_icon$("close"), menu_sel, 5) neoui_draw_softkeys("Close", "Select", "Back") elsif modal_mode = 2 then neoui_draw_confirm_dialog("Reset Demo State?", "Restore all sliders, toggles,", "and notes to default values?", "Cancel", "Reset", confirm_yes) neoui_draw_softkeys("Cancel", "Confirm", "Back") else neoui_draw_softkeys("Menu", mid_lbl$, right_lbl$) fi neoui_end_frame() end sub sub reset_demo_state() wifi_enabled = 1 torch_enabled = 0 volume_pct = 75 bright_pct = 80 progress_pct = 45 note_count = 3 notes$(0) = "Welcome to NeoUI SDK!" notes$(1) = "Try typing with 0-9 keys" notes$(2) = "Press # to switch mode" neoui_input_reset("Bananarchy ") neoui_show_toast("Demo state reset!", 1800) end sub sub add_current_note() local t$ neoui_input_commit_tap() t$ = neoui_input_get_text$() if len(t$) = 0 then neoui_show_toast("Input is empty!", 1500) return fi if note_count < 10 then notes$(note_count) = t$ note_count = note_count + 1 else notes$(9) = t$ fi neoui_input_reset("") neoui_show_toast("Note added!", 1500) end sub render_all() running = 1 while running ev = neoui_poll_event(250) if ev = neoui.EV_CLOSE_REQ then running = 0 elsif ev = neoui.EV_EXPOSE or ev = neoui.EV_THEME_RELOAD then render_all() elsif ev = neoui.EV_SOFTKEY_LEFT then if modal_mode = 0 then modal_mode = 1 menu_sel = 0 else modal_mode = 0 fi render_all() elsif ev = neoui.EV_SOFTKEY_RIGHT then if modal_mode <> 0 then modal_mode = 0 render_all() elsif active_tab = 1 and input_focus = 0 and len(neoui_input_get_text$()) > 0 then neoui_input_backspace() render_all() else running = 0 fi elsif ev = neoui.EV_KEY_PRESS then k = neoui_event_key() if modal_mode = 1 then if k = neoui.KEY_UP then menu_sel = mod(menu_sel + 4, 5) elsif k = neoui.KEY_DOWN then menu_sel = mod(menu_sel + 1, 5) elsif k = neoui.KEY_BACK then modal_mode = 0 elsif k = neoui.KEY_OK then modal_mode = 0 if menu_sel = 0 then neoui_show_toast("Hello from Yabasic NeoUI!", 2000) elsif menu_sel = 1 then neoui_vibrate(60) neoui_show_toast("Vibrated 60 ms", 1500) elsif menu_sel = 2 then neoui_reload_theme() neoui_show_toast("Theme reloaded!", 1500) elsif menu_sel = 3 then modal_mode = 2 confirm_yes = 1 elsif menu_sel = 4 then running = 0 fi fi render_all() elsif modal_mode = 2 then if k = neoui.KEY_LEFT or k = neoui.KEY_RIGHT or k = neoui.KEY_UP or k = neoui.KEY_DOWN then confirm_yes = 1 - confirm_yes elsif k = neoui.KEY_BACK then modal_mode = 0 elsif k = neoui.KEY_OK then modal_mode = 0 if confirm_yes then reset_demo_state() fi fi render_all() else // Normal tab navigation & interaction if active_tab = 1 and input_focus = 0 then // When focused on the text input box, feed digits/star/hash to multi-tap if k = neoui.KEY_UP then input_focus = 2 + note_count elsif k = neoui.KEY_DOWN then input_focus = 1 elsif k = neoui.KEY_LEFT then if neoui_input_is_tap_active() then neoui_input_commit_tap() else active_tab = 0 fi elsif k = neoui.KEY_RIGHT then if neoui_input_is_tap_active() then neoui_input_commit_tap() else active_tab = 2 fi elsif k = neoui.KEY_OK then add_current_note() else neoui_input_feed_key(k) fi render_all() else // Global tab shortcuts 1 / 2 / 3 when not typing in input box if k = neoui.KEY_1 then active_tab = 0 elsif k = neoui.KEY_2 then active_tab = 1 elsif k = neoui.KEY_3 then active_tab = 2 elsif k = neoui.KEY_BACK then running = 0 elsif active_tab = 0 then if k = neoui.KEY_UP then widget_sel = mod(widget_sel + 5, 6) elsif k = neoui.KEY_DOWN then widget_sel = mod(widget_sel + 1, 6) elsif k = neoui.KEY_LEFT then if widget_sel = 2 then volume_pct = max(0, volume_pct - 5) elsif widget_sel = 3 then bright_pct = max(5, bright_pct - 5) else active_tab = 2 fi elsif k = neoui.KEY_RIGHT then if widget_sel = 2 then volume_pct = min(100, volume_pct + 5) elsif widget_sel = 3 then bright_pct = min(100, bright_pct + 5) else active_tab = 1 fi elsif k = neoui.KEY_OK then if widget_sel = 0 then wifi_enabled = 1 - wifi_enabled neoui_show_toast("Wi-Fi toggled", 1200) elsif widget_sel = 1 then torch_enabled = 1 - torch_enabled neoui_show_toast("Flashlight toggled", 1200) elsif widget_sel = 4 then progress_pct = mod(progress_pct + 15, 105) if progress_pct > 100 then progress_pct = 0 fi elsif widget_sel = 5 then modal_mode = 2 confirm_yes = 1 fi fi elsif active_tab = 1 then total_focus = 3 + note_count if k = neoui.KEY_UP then input_focus = mod(input_focus + total_focus - 1, total_focus) elsif k = neoui.KEY_DOWN then input_focus = mod(input_focus + 1, total_focus) elsif k = neoui.KEY_LEFT then if input_focus = 2 then input_focus = 1 else active_tab = 0 fi elsif k = neoui.KEY_RIGHT then if input_focus = 1 then input_focus = 2 else active_tab = 2 fi elsif k = neoui.KEY_OK then if input_focus = 1 then add_current_note() elsif input_focus = 2 then neoui_input_reset("") neoui_show_toast("Input cleared", 1200) fi fi elsif active_tab = 2 then if k = neoui.KEY_LEFT then active_tab = 1 elsif k = neoui.KEY_RIGHT then active_tab = 0 elsif k = neoui.KEY_OK then neoui_reload_theme() neoui_show_toast("Reloaded .Xresources theme!", 1600) fi fi render_all() fi fi fi wend neoui_shutdown()