1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package features_test
import "core:fmt"
import win "../window"
// 4x4 red RGBA icon for testing (tiny but valid)
make_test_icon :: proc(r, g, b: u8, size: u32) -> win.Icon {
n := int(size * size * 4)
rgba := make([]u8, n)
for i := 0; i < n; i += 4 {
rgba[i + 0] = r
rgba[i + 1] = g
rgba[i + 2] = b
rgba[i + 3] = 255
}
return win.Icon{rgba = rgba, width = size, height = size}
}
// 16x16 green crosshair cursor
make_test_cursor :: proc() -> win.Cursor_Image {
size : u32 = 16
n := int(size * size * 4)
rgba := make([]u8, n)
for y in 0..<size {
for x in 0..<size {
i := int((y * size + x) * 4)
is_cross := (x == size/2 || y == size/2)
rgba[i + 0] = is_cross ? u8(0) : u8(0)
rgba[i + 1] = is_cross ? u8(200) : u8(0)
rgba[i + 2] = is_cross ? u8(0) : u8(0)
rgba[i + 3] = is_cross ? u8(255) : u8(0)
}
}
return win.Cursor_Image{rgba = rgba, width = size, height = size, hotspot = {size/2, size/2}}
}
main :: proc() {
loop, err := win.create_event_loop()
if err != .None {
fmt.eprintln("Failed to create event loop:", err)
return
}
defer win.destroy_event_loop(loop)
window, win_err := win.create_window(loop, {
title = "Features Test",
size = {600, 400},
resizable = true,
visible = true,
decorated = true,
})
if win_err != .None {
fmt.eprintln("Failed to create window:", win_err)
return
}
// --- Tier 1: state tracking ---
fmt.println("is_maximized:", win.is_maximized(window)) // should be false
fmt.println("is_minimized:", win.is_minimized(window)) // should be false
fmt.println("is_decorated:", win.is_decorated(window)) // should be true
fmt.println("is_resizable:", win.is_resizable(window)) // should be true
// --- Tier 2: icon ---
icon := make_test_icon(255, 0, 0, 32)
defer delete(icon.rgba)
win.set_icon(window, icon)
fmt.println("Set window icon (32x32 red)")
// --- Tier 2: opacity ---
win.set_opacity(window, 0.9)
fmt.println("Set opacity to 0.9")
// --- Tier 2: window level ---
win.set_window_level(window, .Always_On_Top)
fmt.println("Set window level: always-on-top")
win.set_window_level(window, .Normal)
fmt.println("Set window level: normal")
// --- Tier 2: aspect ratio ---
win.set_aspect_ratio(window, [2]u32{16, 9})
fmt.println("Set aspect ratio 16:9 (try resizing the window)")
// --- Tier 2: custom cursor ---
cursor := make_test_cursor()
defer delete(cursor.rgba)
win.set_custom_cursor(window, cursor)
fmt.println("Set custom 16x16 green cursor")
// --- Tier 2: request attention ---
win.request_attention(window)
fmt.println("Requested attention (taskbar flash)")
step := 0
win.run(loop, proc(event: win.Event, loop: ^win.Event_Loop) -> win.Control_Flow {
#partial switch e in event {
case win.Window_Event_Data:
#partial switch we in e.event {
case win.Close_Requested:
win.exit(loop)
case win.Key_Input:
if we.state == .Pressed {
fmt.printfln("Key: %v repeat=%v mods=%v", we.key, we.repeat, we.modifiers)
if we.key == .Escape {
win.exit(loop)
}
}
case win.Resized:
fmt.printfln("Resized: %dx%d", we.size.width, we.size.height)
case win.Scale_Factor_Changed:
fmt.printfln("Scale factor changed: %.2f new_size: %dx%d",
we.scale_factor, we.new_size.width, we.new_size.height)
case win.Focused:
fmt.println("Focused")
case win.Unfocused:
fmt.println("Unfocused")
}
case win.New_Events:
if e.cause == .Init {
fmt.println("Event loop initialized — close window or press Escape to exit")
}
}
return win.Wait{}
})
fmt.println("Done.")
}