Files
LCUI/tests/previews/preview_cursor.c
Liu 093a6a1e35 feat: add explicit window lifecycle and per-window event routing
- add the window API and lifecycle design specs
- lcui_init no longer creates a window; settings loading is explicit
- add lcui_window_* create/bind/geometry/state/show/close api
- replace display modes with window options and quit-on-last-window
- add per-window event scopes and window-based pointer/keyboard routing
- keep pending updates for widgets appended during a frame
- migrate examples, tests, previews and internals docs
- remove default-scope focus and mouseover getters
2026-11-16 00:03:50 +08:00

69 lines
2.6 KiB
C

/*
* tests/previews/preview_cursor.c
*
* Copyright (c) 2026, Liu Chao <hello@lcui.dev> All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* This file is part of LCUI, distributed under the MIT License found in the
* LICENSE.TXT file in the root directory of this source tree.
*/
#include <stdio.h>
#include <LCUI.h>
#include "preview_window.h"
#include <ptk/main.h>
#include "../scenes/cursor_scene.h"
static const char *cursor_value_names[] = {
"auto", "default", "none", "context-menu",
"help", "pointer", "progress", "wait",
"cell", "crosshair", "text", "vertical-text",
"alias", "copy", "move", "no-drop",
"not-allowed", "grab", "grabbing", "all-scroll",
"col-resize", "row-resize", "n-resize", "e-resize",
"s-resize", "w-resize", "ew-resize", "ns-resize",
"ne-resize", "nw-resize", "se-resize", "sw-resize",
"nesw-resize", "nwse-resize", "zoom-in", "zoom-out",
};
/* 36 宫格:每格绝对定位并设置 cursor:<值>,人工悬停核对平台观感 */
static void build_cursor_grid(float left0, float top0)
{
size_t i;
char value[64];
for (i = 0;
i < sizeof(cursor_value_names) / sizeof(cursor_value_names[0]);
++i) {
ui_widget_t *cell = ui_create_widget(NULL);
ui_widget_t *label = ui_create_widget("text");
float left = left0 + (float)(i % 6) * 118.f;
float top = top0 + (float)(i / 6) * 42.f;
ui_text_set_content(label, cursor_value_names[i]);
ui_widget_set_style_string(cell, "position", "absolute");
snprintf(value, 64, "%.0fpx", left);
ui_widget_set_style_string(cell, "left", value);
snprintf(value, 64, "%.0fpx", top);
ui_widget_set_style_string(cell, "top", value);
ui_widget_set_style_string(cell, "width", "112px");
ui_widget_set_style_string(cell, "height", "36px");
ui_widget_set_style_string(cell, "cursor",
cursor_value_names[i]);
ui_widget_append(cell, label);
ui_root_append(cell);
}
}
int main(int argc, char **argv)
{
lcui_init();
ui_widget_set_title(ui_root(), L"cursor preview");
cursor_scene_build();
build_cursor_grid(0.f, 160.f);
ui_widget_resize(ui_root(), 720, 420);
preview_show_default_window();
return lcui_main();
}