Репозитории /
gui /
docs/index.html
index.html
| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | <title>X11 GUI Library — Documentation</title> |
| 7 | <style> |
| 8 | :root{--bg:#202020;--bg2:#2b2b2b;--bg3:#383838;--tx:#fff;--tx2:#9d9d9d;--ac:#0078d4;--ach:#2488e0;--bd:#3b3b3b;--r:8px} |
| 9 | *{margin:0;padding:0;box-sizing:border-box} |
| 10 | body{font-family:'Segoe UI',system-ui,sans-serif;background:var(--bg);color:var(--tx);display:flex} |
| 11 | ::-webkit-scrollbar{width:8px}::-webkit-scrollbar-thumb{background:var(--bg3);border-radius:4px} |
| 12 | .sb{width:260px;position:fixed;inset:0 auto 0 0;background:var(--bg2);border-right:1px solid var(--bd);padding:16px 12px;overflow-y:auto} |
| 13 | .logo{font-size:17px;font-weight:600;padding:6px 12px 18px;display:flex;gap:10px;align-items:center} |
| 14 | .logo .sq{width:22px;height:22px;background:var(--ac);border-radius:5px} |
| 15 | #q{width:100%;background:var(--bg);border:1px solid var(--bd);border-radius:6px;color:var(--tx);padding:8px 10px;font-size:13px;margin-bottom:12px;outline:none} |
| 16 | #q:focus{border-color:var(--ac)} |
| 17 | .nv{display:block;width:100%;text-align:left;background:none;border:none;color:var(--tx2);padding:10px 12px;border-radius:6px;font-size:14px;cursor:pointer;margin-bottom:2px;position:relative} |
| 18 | .nv:hover{background:var(--bg3);color:var(--tx)} |
| 19 | .nv.on{background:var(--bg3);color:var(--tx)} |
| 20 | .nv.on::before{content:'';position:absolute;left:0;top:8px;bottom:8px;width:3px;background:var(--ac);border-radius:2px} |
| 21 | main{margin-left:260px;flex:1;padding:32px 40px;max-width:1100px} |
| 22 | h1{font-size:28px;font-weight:600;margin-bottom:6px} |
| 23 | h2{font-size:20px;font-weight:600;margin:26px 0 10px} |
| 24 | h3{font-size:15px;font-weight:600;margin:18px 0 8px} |
| 25 | p,li{color:var(--tx2);font-size:14px;line-height:1.7} |
| 26 | ul{padding-left:20px;margin:8px 0} |
| 27 | .card{background:var(--bg2);border:1px solid var(--bd);border-radius:var(--r);padding:20px;margin:14px 0} |
| 28 | table{width:100%;border-collapse:collapse;margin:12px 0;font-size:13px} |
| 29 | th,td{padding:8px 10px;text-align:left;border-bottom:1px solid var(--bd);color:var(--tx2);vertical-align:top} |
| 30 | th{color:var(--tx);background:var(--bg3)} |
| 31 | code{font-family:'Cascadia Code',Consolas,monospace;font-size:12.5px;color:#4cc2ff} |
| 32 | pre{background:#1a1a1a;border:1px solid var(--bd);border-radius:var(--r);padding:14px;overflow-x:auto;margin:10px 0} |
| 33 | pre code{color:#e8e8e8;line-height:1.6} |
| 34 | .cb{position:relative} |
| 35 | .cp{position:absolute;top:8px;right:8px;background:var(--bg3);border:1px solid var(--bd);color:var(--tx2);border-radius:5px;padding:3px 10px;font-size:11px;cursor:pointer} |
| 36 | .cp:hover{background:var(--ac);color:#fff} |
| 37 | .page{display:none}.page.on{display:block} |
| 38 | .badge{display:inline-block;background:var(--ac);color:#fff;border-radius:4px;padding:2px 8px;font-size:11px;margin-right:6px} |
| 39 | .tip{border-left:3px solid var(--ac);background:var(--bg2);padding:12px 16px;border-radius:0 6px 6px 0;margin:12px 0} |
| 40 | .warn{border-left:3px solid #f59e0b;background:var(--bg2);padding:12px 16px;border-radius:0 6px 6px 0;margin:12px 0} |
| 41 | </style> |
| 42 | </head> |
| 43 | <body> |
| 44 | |
| 45 | <aside class="sb"> |
| 46 | <div class="logo"><div class="sq"></div>X11 GUI Library</div> |
| 47 | <input id="q" placeholder="Search..."> |
| 48 | <button class="nv on" data-p="start"> Getting Started</button> |
| 49 | <button class="nv" data-p="window">🪟 Window & Pages</button> |
| 50 | <button class="nv" data-p="widgets">🧩 Widgets</button> |
| 51 | <button class="nv" data-p="themes">🎨 Themes & Customization</button> |
| 52 | <button class="nv" data-p="custom">🛠 Custom Widgets</button> |
| 53 | <button class="nv" data-p="events">📡 Events</button> |
| 54 | <button class="nv" data-p="anim">✨ Animations</button> |
| 55 | <button class="nv" data-p="debug">🐞 Debug & Performance</button> |
| 56 | <button class="nv" data-p="api">📚 API Reference</button> |
| 57 | </aside> |
| 58 | |
| 59 | <main> |
| 60 | |
| 61 | <!-- ============ START ============ --> |
| 62 | <section id="p-start" class="page on"> |
| 63 | <h1>Getting Started</h1> |
| 64 | <p>Lightweight X11 GUI library for C++20 with software rendering, dirty-rectangle partial updates, TTF fonts (FreeType), two built-in themes (WIN11 / TERMINAL) and smooth animations.</p> |
| 65 | <div class="card"> |
| 66 | <h3>Features</h3> |
| 67 | <ul> |
| 68 | <li>Partial redraw (dirty rectangles) — only changed regions repaint</li> |
| 69 | <li>Double buffering — no flicker</li> |
| 70 | <li>TTF fonts via FreeType with cached 1-bit masks (fast text)</li> |
| 71 | <li>Two themes: <code>WIN11</code> and <code>TERMINAL</code>, fully customizable</li> |
| 72 | <li>Animations: hover, press, push-down, check, dropdown</li> |
| 73 | <li>EventBus + per-widget callbacks</li> |
| 74 | <li>Debug overlay, dirty-rect visualization, click markers (F1–F6)</li> |
| 75 | </ul> |
| 76 | </div> |
| 77 | <h2>Build</h2> |
| 78 | <pre><code>find_package(X11 REQUIRED) |
| 79 | find_package(Freetype REQUIRED) |
| 80 | |
| 81 | add_executable(host |
| 82 | main.cpp |
| 83 | libs/gui/core/event_bus.cpp |
| 84 | libs/gui/core/raw_picture.cpp |
| 85 | libs/gui/core/font_manager.cpp |
| 86 | libs/gui/core/theme.cpp |
| 87 | libs/gui/widgets/widget.cpp |
| 88 | libs/gui/widgets/draw_basic.cpp |
| 89 | libs/gui/widgets/draw_toggles.cpp |
| 90 | libs/gui/widgets/draw_lists.cpp |
| 91 | libs/gui/window.cpp |
| 92 | libs/gui/demo.cpp |
| 93 | ) |
| 94 | target_include_directories(host PRIVATE libs/gui ${X11_INCLUDE_DIR}) |
| 95 | target_link_libraries(host PRIVATE ${X11_LIBRARIES} Freetype::Freetype)</code></pre> |
| 96 | <h2>Quick start</h2> |
| 97 | <pre><code>#include "gui.h" |
| 98 | int main() { |
| 99 | gui::set_theme(gui::ThemeStyle::WIN11); |
| 100 | gui::window win("My App"); |
| 101 | win.set_font("SGr-Iosevka-Regular.ttc"); |
| 102 | win.set_default_icon(); |
| 103 | |
| 104 | win.configur_page("main", [](gui::page& p) { |
| 105 | gui::WidgetData b; |
| 106 | b.id = "btn"; b.text = "Hello"; |
| 107 | b.x = 100; b.y = 100; b.width = 300; b.height = 70; |
| 108 | p.Button(b); |
| 109 | }, true); |
| 110 | |
| 111 | gui::EventBus::get().on("button.click", [](const gui::EventData& e) { |
| 112 | std::cout << "clicked: " << e.source_id << "\n"; |
| 113 | }); |
| 114 | |
| 115 | while (win.running()) win.update(); |
| 116 | }</code></pre> |
| 117 | <div class="tip">Put <code>SGr-Iosevka-Regular.ttc</code> (or any TTF/TTC) next to the binary. If not found, a fallback X11 core font is used.</div> |
| 118 | </section> |
| 119 | |
| 120 | <!-- ============ WINDOW ============ --> |
| 121 | <section id="p-window" class="page"> |
| 122 | <h1>Window & Pages</h1> |
| 123 | <h2>gui::window</h2> |
| 124 | <table> |
| 125 | <tr><th>Method</th><th>Description</th></tr> |
| 126 | <tr><td><code>window(title)</code></td><td>Create X11 window (1600×900), backbuffer, load font</td></tr> |
| 127 | <tr><td><code>update()</code></td><td>Process events + render one frame (call in a loop)</td></tr> |
| 128 | <tr><td><code>running()</code></td><td>false after WM_DELETE (close button)</td></tr> |
| 129 | <tr><td><code>set_font(path)</code></td><td>Load TTF/TTC font</td></tr> |
| 130 | <tr><td><code>set_font_size(px)</code></td><td>Global font size (default 32)</td></tr> |
| 131 | <tr><td><code>set_icon(path)</code> / <code>set_icon(pic)</code> / <code>set_default_icon()</code></td><td>Window icon (_NET_WM_ICON)</td></tr> |
| 132 | <tr><td><code>set_max_fps(n)</code></td><td>Frame cap (default 240)</td></tr> |
| 133 | <tr><td><code>on_key</code></td><td>std::function<void(KeySym)> — custom hotkeys (F6+)</td></tr> |
| 134 | </table> |
| 135 | <h2>Pages & tabs</h2> |
| 136 | <pre><code>// tabs (left column) |
| 137 | gui::WidgetData tab; tab.id = "main"; tab.text = "main"; |
| 138 | tab.on_window_click = [&win](gui::window& w){ w.openPAGE("main"); }; |
| 139 | win.addTAB_BUTTON(tab); |
| 140 | |
| 141 | // pages |
| 142 | win.addPAGE("main"); |
| 143 | win.configur_page("main", [](gui::page& p){ /* fill widgets */ }, true); |
| 144 | win.openPAGE("main");</code></pre> |
| 145 | <div class="tip">Only the <b>active page</b> is ticked and rendered — inactive pages cost zero CPU.</div> |
| 146 | <h2>Finding widgets</h2> |
| 147 | <pre><code>gui::Widget* w = win.find("btn"); // search all pages |
| 148 | if (w) { w->setValue(0.7f); win.mark_dirty(100,100,300,70); }</code></pre> |
| 149 | </section> |
| 150 | |
| 151 | <!-- ============ WIDGETS ============ --> |
| 152 | <section id="p-widgets" class="page"> |
| 153 | <h1>Widgets</h1> |
| 154 | <h2>WidgetData fields</h2> |
| 155 | <table> |
| 156 | <tr><th>Field</th><th>Default</th><th>Meaning</th></tr> |
| 157 | <tr><td><code>id, text</code></td><td>""</td><td>identifier / label</td></tr> |
| 158 | <tr><td><code>x,y,width,height</code></td><td>0,0,200,60</td><td>geometry (2× scale)</td></tr> |
| 159 | <tr><td><code>bg_color, fg_color, frame_color</code></td><td>0</td><td>0 = take from theme, else override</td></tr> |
| 160 | <tr><td><code>font_size</code></td><td>0</td><td>0 = theme size, else per-widget</td></tr> |
| 161 | <tr><td><code>primary</code></td><td>false</td><td>accent-colored button</td></tr> |
| 162 | <tr><td><code>checked</code></td><td>false</td><td>checkbox / radio state</td></tr> |
| 163 | <tr><td><code>value, target_value</code></td><td>0</td><td>slider / progress (0..1)</td></tr> |
| 164 | <tr><td><code>items</code></td><td>[]</td><td>listbox / dropdown entries</td></tr> |
| 165 | <tr><td><code>picture</code></td><td>null</td><td>RawPicture for sprite / raw widgets</td></tr> |
| 166 | <tr><td><code>on_change / on_page_click / on_window_click</code></td><td>null</td><td>callbacks</td></tr> |
| 167 | </table> |
| 168 | <h2>Factory methods (on page or any container)</h2> |
| 169 | <pre><code>p.Button(d); p.Label(d); p.Input(d); p.Checkbox(d); p.Radiobutton(d); |
| 170 | p.Slider(d); p.Progressbar(d); p.Listbox(d); p.Dropdown(d); |
| 171 | p.TreeView(d); p.TreeNode(d); p.ScrollView(d); |
| 172 | p.RawPictureWidget(d); p.SpriteButton(d);</code></pre> |
| 173 | <h2>Examples</h2> |
| 174 | <pre><code>// accent button |
| 175 | gui::WidgetData b; b.id="go"; b.text="Run"; b.primary=true; |
| 176 | b.x=100; b.y=100; b.width=300; b.height=70; |
| 177 | p.Button(b); |
| 178 | |
| 179 | // input field (click to focus, bottom line + blinking caret) |
| 180 | gui::WidgetData i; i.id="name"; i.x=100; i.y=200; i.width=500; i.height=68; |
| 181 | p.Input(i); |
| 182 | |
| 183 | // slider drives progress |
| 184 | gui::WidgetData s; s.id="vol"; s.x=100; s.y=300; s.width=600; s.height=48; s.value=0.4f; |
| 185 | p.Slider(s); |
| 186 | gui::WidgetData pr; pr.id="prog"; pr.x=100; pr.y=380; pr.width=600; pr.height=44; |
| 187 | p.Progressbar(pr);</code></pre> |
| 188 | <h2>Nested containers</h2> |
| 189 | <pre><code>auto& sv = p.ScrollView(d); // returns Widget& |
| 190 | sv.Button(inner); // children live inside |
| 191 | auto& tv = p.TreeView(d); |
| 192 | auto& n1 = tv.TreeNode(n); // node |
| 193 | n1.Label(child); // leaf inside node</code></pre> |
| 194 | </section> |
| 195 | |
| 196 | <!-- ============ THEMES ============ --> |
| 197 | <section id="p-themes" class="page"> |
| 198 | <h1>Themes & Customization</h1> |
| 199 | <h2>Switch built-in themes</h2> |
| 200 | <pre><code>gui::set_theme(gui::ThemeStyle::WIN11); // rounded, blue accent |
| 201 | gui::set_theme(gui::ThemeStyle::TERMINAL); // square, green accent |
| 202 | // hotkey F6 toggles at runtime (see demo)</code></pre> |
| 203 | <h2>Theme struct (all tunable)</h2> |
| 204 | <pre><code>struct Theme { |
| 205 | ThemeStyle style; |
| 206 | int radius, radius_sm, font_size; // 12/8/32 (win11), 0/0/32 (term) |
| 207 | uint32_t window_bg, panel_bg, text, text_dim; |
| 208 | uint32_t btn, btn_h, btn_p, border, border_h; // button + hover + press |
| 209 | uint32_t accent, accent_h, accent_p, on_accent; |
| 210 | uint32_t input_bg, focus; |
| 211 | uint32_t track, prog_bg; |
| 212 | uint32_t list_bg, list_h, list_sel, list_sel_text; |
| 213 | uint32_t tab_bg, tab_h, tab_active; |
| 214 | }; |
| 215 | const Theme& theme(); // current</code></pre> |
| 216 | <h2>Per-widget override (beats theme)</h2> |
| 217 | <pre><code>gui::WidgetData d; |
| 218 | d.bg_color = 0x332211; // non-zero overrides theme |
| 219 | d.fg_color = 0xFFCC00; |
| 220 | d.frame_color = 0x00FF88; |
| 221 | d.font_size = 40; // per-widget size</code></pre> |
| 222 | <div class="tip">Rule: <code>0</code> = use theme. Any other value = your override. This is the <code>C(override, theme)</code> helper in <code>widget.h</code>.</div> |
| 223 | <h2>Where theme values live</h2> |
| 224 | <p>Edit <code>libs/gui/core/theme.cpp</code> — the two static structs <code>t_win11</code> / <code>t_term</code>. Field order matches the struct above (e.g. the pair <code>input_bg, focus</code> is the 14th/15th value).</p> |
| 225 | </section> |
| 226 | |
| 227 | <!-- ============ CUSTOM ============ --> |
| 228 | <section id="p-custom" class="page"> |
| 229 | <h1>Custom Widgets</h1> |
| 230 | <p>Three levels of extension, from easy to full.</p> |
| 231 | <h2>1. Restyle an existing widget (no code change)</h2> |
| 232 | <pre><code>gui::WidgetData d; |
| 233 | d.type = gui::WidgetType::BUTTON; // or set via factory |
| 234 | d.bg_color = 0x402020; d.frame_color = 0xFF4444; d.font_size = 28; |
| 235 | p.Button(d);</code></pre> |
| 236 | <h2>2. Compose with RawPicture (sprite button)</h2> |
| 237 | <pre><code>auto pic = std::make_shared<gui::RawPicture>(300, 100, 32); |
| 238 | pic->clear(0x202020); |
| 239 | pic->fillRoundRect(0,0,300,100,16,0x0078D4); |
| 240 | pic->drawText(win.display(), 20, 30, "Custom", 0xFFFFFF, 1); |
| 241 | gui::WidgetData d; d.picture = pic; d.width=300; d.height=100; |
| 242 | p.SpriteButton(d); // still clickable, emits button.click</code></pre> |
| 243 | <h2>3. Add a brand-new widget type</h2> |
| 244 | <ol> |
| 245 | <li><code>widget.h</code>: add enum value <code>WidgetType::MY_WIDGET</code></li> |
| 246 | <li><code>widget.h</code>: add factory decl <code>Widget& MyWidget(WidgetData);</code></li> |
| 247 | <li><code>widget.cpp</code>: implement factory (<code>a.type = ...; return add_widget(...)</code>)</li> |
| 248 | <li>draw: add a case in <code>Widget::draw</code> dispatch → your <code>wdraw::my(...)</code></li> |
| 249 | <li>input: add a case in <code>Widget::handle_press</code> (return 1 consumed / 2 capture)</li> |
| 250 | </ol> |
| 251 | <pre><code>// widget.cpp factory |
| 252 | Widget& combat::MyWidget(WidgetData a){ a.type=WidgetType::MY_WIDGET; return add_widget(std::move(a)); } |
| 253 | |
| 254 | // draw dispatch (Widget::draw) |
| 255 | case WidgetType::MY_WIDGET: wdraw::my(d, win, gc, *this, ax, ay); break; |
| 256 | |
| 257 | // your renderer (any draw_*.cpp) |
| 258 | void wdraw::my(Display* d, Drawable win, GC gc, const Widget& w, int ax, int ay) { |
| 259 | const auto& t = theme(); |
| 260 | XSetForeground(d, gc, t.accent); |
| 261 | x_fill_round(d, win, gc, ax, ay, w.data.width, w.data.height, t.radius); |
| 262 | gui_text(d, win, gc, ax+12, gui_base_c(ay, w.data.height, t.font_size), |
| 263 | w.data.text, t.on_accent, t.font_size); |
| 264 | }</code></pre> |
| 265 | <div class="warn">Declare your <code>wdraw::my</code> in <code>widget.h</code> and, if it needs protected <code>widgets</code>, add it as <code>friend</code> of <code>combat</code> (like basic/toggles/lists).</div> |
| 266 | </section> |
| 267 | |
| 268 | <!-- ============ EVENTS ============ --> |
| 269 | <section id="p-events" class="page"> |
| 270 | <h1>Events</h1> |
| 271 | <h2>EventBus</h2> |
| 272 | <pre><code>int tok = gui::EventBus::get().on("button.click", [](const gui::EventData& e){ ... }); |
| 273 | gui::EventBus::get().off(tok); |
| 274 | gui::EventBus::get().emit("my.event", {"id","text",0.5f,1,true});</code></pre> |
| 275 | <h2>Built-in events</h2> |
| 276 | <table> |
| 277 | <tr><th>Event</th><th>Data</th></tr> |
| 278 | <tr><td><code>button.click</code></td><td>source_id, text</td></tr> |
| 279 | <tr><td><code>checkbox.change</code></td><td>source_id, flag</td></tr> |
| 280 | <tr><td><code>radio.change</code></td><td>source_id, flag=true</td></tr> |
| 281 | <tr><td><code>slider.change</code></td><td>source_id, value 0..1</td></tr> |
| 282 | <tr><td><code>list.select</code></td><td>source_id, text, index</td></tr> |
| 283 | <tr><td><code>dropdown.select</code></td><td>source_id, text, index</td></tr> |
| 284 | <tr><td><code>tree.toggle</code></td><td>source_id, flag=expanded</td></tr> |
| 285 | <tr><td><code>input.submit</code></td><td>source_id, text (Enter)</td></tr> |
| 286 | <tr><td><code>page.open</code></td><td>source_id = page name</td></tr> |
| 287 | </table> |
| 288 | <h2>Per-widget callbacks (alternative)</h2> |
| 289 | <pre><code>d.on_change = []{ ... }; // value/state changed |
| 290 | d.on_page_click = [](gui::page& p){ ... }; // button clicked |
| 291 | d.on_window_click= [](gui::window& w){ ... };</code></pre> |
| 292 | <h2>Global logger (debug)</h2> |
| 293 | <pre><code>gui::EventBus::get().set_global_logger([](const std::string& e, const gui::EventData& d){ |
| 294 | std::cout << "[LOG] " << e << "\n"; |
| 295 | });</code></pre> |
| 296 | </section> |
| 297 | |
| 298 | <!-- ============ ANIM ============ --> |
| 299 | <section id="p-anim" class="page"> |
| 300 | <h1>Animations</h1> |
| 301 | <p>All animation state lives in <code>struct Widget</code> as 0..1 floats, advanced in <code>Widget::tick(dt)</code> and applied in <code>Widget::draw()</code>.</p> |
| 302 | <table> |
| 303 | <tr><th>Field</th><th>Drives</th><th>Where applied</th></tr> |
| 304 | <tr><td><code>hover_a</code></td><td>hover highlight</td><td>draw_basic / toggles color mix</td></tr> |
| 305 | <tr><td><code>press_a</code></td><td>press darkening</td><td>draw_basic color mix</td></tr> |
| 306 | <tr><td><code>push_a</code></td><td>push-down offset (6px)</td><td><code>Widget::draw</code>: <code>ay += ease(push_a)*6</code></td></tr> |
| 307 | <tr><td><code>check_a</code></td><td>checkmark / radio dot reveal</td><td>draw_toggles</td></tr> |
| 308 | <tr><td><code>anim</code></td><td>dropdown open/close</td><td>draw_lists popup height</td></tr> |
| 309 | <tr><td><code>cursor_timer / cursor_visible</code></td><td>input caret blink (0.5s)</td><td>draw_basic</td></tr> |
| 310 | </table> |
| 311 | <h2>Tune speed</h2> |
| 312 | <pre><code>// Widget::tick — the speed constants |
| 313 | hover_a = approach(hover_a, hovered?1:0, dt, 10); // higher = snappier |
| 314 | push_a = approach(push_a, pressed?1:0, dt, 18); |
| 315 | check_a = approach(check_a, checked?1:0, dt, 10);</code></pre> |
| 316 | <h2>Disable push-down (e.g. for slider)</h2> |
| 317 | <pre><code>// Widget::draw |
| 318 | int ay = data.y + oy + (data.type == WidgetType::SLIDER ? 0 : (int)(ease(push_a)*6));</code></pre> |
| 319 | <h2>Remove color flicker (design rule)</h2> |
| 320 | <div class="tip">Colors fed into <code>x_fill_round</code>/<code>x_draw_round</code>/<code>XDrawArc</code> must NOT depend on animated <code>hover_a</code>/<code>press_a</code>. Keep animation in safe places: checkmark lines, radio dot, slider thumb position, push-down offset. This is why checkbox/radio use static border colors.</div> |
| 321 | </section> |
| 322 | |
| 323 | <!-- ============ DEBUG ============ --> |
| 324 | <section id="p-debug" class="page"> |
| 325 | <h1>Debug & Performance</h1> |
| 326 | <h2>Hotkeys</h2> |
| 327 | <table> |
| 328 | <tr><th>Key</th><th>Action</th></tr> |
| 329 | <tr><td>F1</td><td>Debug overlay (FPS, widgets, partial updates, mouse, event log)</td></tr> |
| 330 | <tr><td>F2</td><td>Dirty-rect visualization (XOR flash of repainted regions)</td></tr> |
| 331 | <tr><td>F3</td><td>Click markers (red cross at click point)</td></tr> |
| 332 | <tr><td>F4</td><td>Widget bounds (magenta outlines)</td></tr> |
| 333 | <tr><td>F5</td><td>Console event logging</td></tr> |
| 334 | <tr><td>F6</td><td>Toggle theme WIN11 ↔ TERMINAL (via <code>on_key</code>)</td></tr> |
| 335 | </table> |
| 336 | <h2>Programmatic access</h2> |
| 337 | <pre><code>win.debug().show_debug_overlay = true; |
| 338 | win.debug().show_dirty_rects = true; |
| 339 | win.debug().max_log_size = 30; |
| 340 | std::cout << win.debug().fps << "\n"; |
| 341 | |
| 342 | win.mark_dirty(x,y,w,h); // invalidate a region |
| 343 | win.mark_all_dirty(); // full repaint</code></pre> |
| 344 | <h2>Why it's fast</h2> |
| 345 | <ul> |
| 346 | <li><b>Dirty rectangles</b> — only changed regions redraw; <code>Partial updates</code> counter shows it</li> |
| 347 | <li><b>Only active page</b> is ticked/rendered</li> |
| 348 | <li><b>Text cache</b> — strings rendered once to 1-bit masks, drawn with one <code>XFillRectangle</code> (no XGetImage)</li> |
| 349 | <li><b>Overlay throttle</b> — debug panel refreshes at 10 Hz</li> |
| 350 | <li><b>Idle sleep</b> — <code>usleep(10ms)</code> when nothing is dirty → ~0% CPU at rest</li> |
| 351 | <li><b>Frame cap</b> — <code>set_max_fps()</code>, default 240</li> |
| 352 | </ul> |
| 353 | <div class="warn">F2 flashes only visualize <i>user</i> dirty rects (snapshot taken before flash/marker/overlay rects) — no feedback loop, FPS stays high.</div> |
| 354 | </section> |
| 355 | |
| 356 | <!-- ============ API ============ --> |
| 357 | <section id="p-api" class="page"> |
| 358 | <h1>API Reference</h1> |
| 359 | <h2>gui::window</h2> |
| 360 | <pre><code>window(title) / ~window() |
| 361 | update() running() display() |
| 362 | addTAB_BUTTON(d) addPAGE(n) configur_page(n, fn, active) openPAGE(n) |
| 363 | find(id) set_focus(w) |
| 364 | set_font(p) set_font_size(px) set_icon(p|pic) set_default_icon() set_max_fps(n) |
| 365 | debug() mark_dirty(x,y,w,h) mark_all_dirty() |
| 366 | std::function<void(KeySym)> on_key;</code></pre> |
| 367 | <h2>gui::combat (container base: page, Widget)</h2> |
| 368 | <pre><code>Button/Label/Input/Checkbox/Radiobutton/Slider/Progressbar/ |
| 369 | Listbox/Dropdown/TreeView/TreeNode/ScrollView/RawPictureWidget/SpriteButton |
| 370 | visit(fn) find(id) find_at(x,y) count_widgets() |
| 371 | tick(dt) render_all(...) render_dirty(...) mark_all_dirty(...) |
| 372 | process_press(...) process_wheel(...)</code></pre> |
| 373 | <h2>gui::Widget</h2> |
| 374 | <pre><code>WidgetData data; |
| 375 | float hover_a, press_a, check_a, push_a, anim, phase; |
| 376 | bool hovered, pressed, focused, cursor_visible, open_target; |
| 377 | float cursor_timer; |
| 378 | setValue(v) getValue() |
| 379 | tick(dt) draw(...) draw_popup(...) |
| 380 | handle_press/drag/release/wheel(...) |
| 381 | contains(...) content_height() mark_dirty(...)</code></pre> |
| 382 | <h2>gui::RawPicture</h2> |
| 383 | <pre><code>create(w,h,bits) clear(c) setPixel/getPixel/blendPixel |
| 384 | drawLine/drawRect/fillRect/fillRoundRect |
| 385 | drawCircle/fillCircle/fillTriangle/fillPolygon |
| 386 | drawText(dpy,x,y,t,c,scale) blit(src,dx,dy) |
| 387 | load(path) // BMP 24/32, PPM P6 |
| 388 | present(dpy,win,gc,dx,dy)</code></pre> |
| 389 | <h2>gui::FontManager</h2> |
| 390 | <pre><code>FontManager::get() |
| 391 | load(path) available() set_default_size(px) default_size() |
| 392 | ascent/descent/line_height/text_width(size) |
| 393 | draw(RawPicture&,...) draw(Display*,Drawable,GC,...)</code></pre> |
| 394 | <h2>gui::EventBus / gui::DirtyRegion / gui::Theme</h2> |
| 395 | <pre><code>EventBus::get().on/off/emit/set_global_logger |
| 396 | DirtyRegion: add/mark_all/is_dirty/intersects/get/clear |
| 397 | theme() set_theme(ThemeStyle)</code></pre> |
| 398 | </section> |
| 399 | |
| 400 | </main> |
| 401 | |
| 402 | <script> |
| 403 | function go(id){ |
| 404 | document.querySelectorAll('.page').forEach(p=>p.classList.remove('on')); |
| 405 | document.querySelectorAll('.nv').forEach(n=>n.classList.remove('on')); |
| 406 | document.getElementById('p-'+id).classList.add('on'); |
| 407 | document.querySelector('[data-p="'+id+'"]').classList.add('on'); |
| 408 | window.scrollTo(0,0); |
| 409 | } |
| 410 | document.querySelectorAll('.nv').forEach(n=>n.onclick=()=>go(n.dataset.p)); |
| 411 | |
| 412 | // wrap every <pre> with copy button |
| 413 | document.querySelectorAll('pre').forEach(pre=>{ |
| 414 | const wrap=document.createElement('div'); wrap.className='cb'; |
| 415 | pre.parentNode.insertBefore(wrap,pre); wrap.appendChild(pre); |
| 416 | const b=document.createElement('button'); b.className='cp'; b.textContent='Copy'; |
| 417 | b.onclick=()=>{ navigator.clipboard.writeText(pre.innerText).then(()=>{ |
| 418 | b.textContent='Copied!'; setTimeout(()=>b.textContent='Copy',1200); |
| 419 | });}; |
| 420 | wrap.appendChild(b); |
| 421 | }); |
| 422 | |
| 423 | // sidebar search |
| 424 | document.getElementById('q').addEventListener('input',e=>{ |
| 425 | const t=e.target.value.toLowerCase(); |
| 426 | document.querySelectorAll('.nv').forEach(n=>{ |
| 427 | n.style.display = n.textContent.toLowerCase().includes(t) ? 'block' : 'none'; |
| 428 | }); |
| 429 | }); |
| 430 | </script> |
| 431 | </body> |
| 432 | </html> |