feat: new Window Server helpers and app migrations

This commit is contained in:
2026-03-25 21:06:58 +01:00
parent 1ad9117fc1
commit afe0442d57
16 changed files with 654 additions and 778 deletions
+14 -18
View File
@@ -147,27 +147,23 @@ Events are delivered via `win_poll()` into a `WinEvent` struct:
### Drawing Helpers
Standalone apps typically define local pixel-drawing helpers since they work with raw `uint32_t*` buffers:
For new standalone apps, prefer the shared helpers in `#include <gui/standalone.hpp>`. It provides:
- `gui::WsWindow` for `win_create()` / `win_poll()` / `win_resize()` / `win_present()`
- `gui::Canvas` for drawing into the window buffer
- immediate-mode helpers like `draw_text()`, `draw_button()`, and `fill_circle()`
Older apps in the tree still define local `px_*` helpers, but new code should not need to.
```cpp
static void px_fill(uint32_t* px, int bw, int bh,
int x, int y, int w, int h, uint32_t color) {
for (int row = y; row < y + h && row < bh; row++)
for (int col = x; col < x + w && col < bw; col++)
px[row * bw + col] = color;
}
gui::WsWindow win;
win.create("My App", 400, 300);
static void px_hline(uint32_t* px, int bw, int bh,
int x, int y, int w, uint32_t color) {
for (int col = x; col < x + w && col < bw; col++)
if (y >= 0 && y < bh) px[y * bw + col] = color;
}
static void px_text(uint32_t* px, int bw, int bh,
int x, int y, const char* text, Color c, int size) {
if (g_font)
g_font->draw_to_buffer(px, bw, bh, x, y, text, c, size);
}
gui::Canvas c = win.canvas();
c.fill(gui::colors::WHITE);
draw_text(c, g_font, 20, 30, "Hello", gui::colors::TEXT_COLOR, 18);
draw_button(c, g_font, 20, 60, 96, 28, "OK",
gui::colors::ACCENT, gui::colors::WHITE, 6, 16);
```
### Rounded Rectangles
+2 -1
View File
@@ -207,11 +207,12 @@ struct WinCreateResult {
**`WinEvent` struct:**
```cpp
struct WinEvent {
int type; // 0=Key, 1=Mouse, 2=Resize, 3=Close
int type; // 0=Key, 1=Mouse, 2=Resize, 3=Close, 4=Scale
union {
struct { uint8_t scancode; char ascii; bool pressed, shift, ctrl, alt; } key;
struct { int x, y; uint8_t buttons, prev_buttons; int32_t scroll; } mouse;
struct { int w, h; } resize;
struct { int scale; } scale;
};
};
```