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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package window_ops_example
import "core:fmt"
import win "../window"
decorated := true
maximized := false
fullscreen := false
resizable := true
visible := true
main :: proc() {
fmt.println("Window Operations Demo")
fmt.println("======================")
loop, err := win.create_event_loop()
if err != .None {
fmt.eprintln("Failed to create event loop:", err)
return
}
defer win.destroy_event_loop(loop)
_, win_err := win.create_window(loop, {
title = "Window Operations Demo",
size = {800, 600},
resizable = true,
visible = true,
decorated = true,
})
if win_err != .None {
fmt.eprintln("Failed to create window:", win_err)
return
}
fmt.println("\nControls:")
fmt.println(" D - Toggle decorations")
fmt.println(" M - Toggle maximize")
fmt.println(" F - Toggle fullscreen")
fmt.println(" R - Toggle resizable")
fmt.println(" H - Hide/show window")
fmt.println(" 1 - Set size to 400x300")
fmt.println(" 2 - Set size to 800x600")
fmt.println(" 3 - Set size to 1200x800")
fmt.println(" Arrow Keys - Move window")
fmt.println(" Space - Focus window")
fmt.println(" I - Minimize window")
fmt.println(" Escape - Exit")
fmt.println("")
win.run(loop, handle_event)
fmt.println("Goodbye!")
}
handle_event :: proc(event: win.Event, loop: ^win.Event_Loop) -> win.Control_Flow {
#partial switch e in event {
case win.Window_Event_Data:
// Get the first (and only) window
window: ^win.Window = nil
if len(loop.windows) > 0 {
window = loop.windows[0]
}
#partial switch we in e.event {
case win.Close_Requested:
fmt.println("Exiting...")
win.exit(loop)
case win.Key_Input:
if we.state == .Pressed && !we.repeat && window != nil {
#partial switch we.key {
case .D:
decorated = !decorated
win.set_decorations(window, decorated)
fmt.printfln("Decorations: %v", decorated)
case .M:
maximized = !maximized
win.set_maximized(window, maximized)
fmt.printfln("Maximized: %v", maximized)
case .F:
fullscreen = !fullscreen
if fullscreen {
win.set_fullscreen(window, win.Fullscreen_Mode{})
} else {
win.set_fullscreen(window, nil)
}
fmt.printfln("Fullscreen: %v", fullscreen)
case .R:
resizable = !resizable
win.set_resizable(window, resizable)
fmt.printfln("Resizable: %v", resizable)
case .H:
visible = !visible
win.set_visible(window, visible)
fmt.printfln("Visible: %v", visible)
case .Key_1:
win.set_size(window, {400, 300})
fmt.println("Set size to 400x300")
case .Key_2:
win.set_size(window, {800, 600})
fmt.println("Set size to 800x600")
case .Key_3:
win.set_size(window, {1200, 800})
fmt.println("Set size to 1200x800")
case .Arrow_Up:
pos := win.get_position(window)
pos.y -= 50
win.set_position(window, pos)
fmt.printfln("Moved to (%d, %d)", pos.x, pos.y)
case .Arrow_Down:
pos := win.get_position(window)
pos.y += 50
win.set_position(window, pos)
fmt.printfln("Moved to (%d, %d)", pos.x, pos.y)
case .Arrow_Left:
pos := win.get_position(window)
pos.x -= 50
win.set_position(window, pos)
fmt.printfln("Moved to (%d, %d)", pos.x, pos.y)
case .Arrow_Right:
pos := win.get_position(window)
pos.x += 50
win.set_position(window, pos)
fmt.printfln("Moved to (%d, %d)", pos.x, pos.y)
case .Space:
win.focus(window)
fmt.println("Focusing window")
case .I:
win.set_minimized(window)
fmt.println("Minimizing window")
case .Escape:
fmt.println("Exiting...")
win.exit(loop)
case:
// Ignore other keys
}
}
case win.Resized:
fmt.printfln("Resized to %dx%d", we.size.width, we.size.height)
case win.Moved:
fmt.printfln("Moved to (%d, %d)", we.position.x, we.position.y)
case win.Focused:
fmt.println("Window focused")
case win.Unfocused:
fmt.println("Window unfocused")
case:
// Ignore other window events
}
case win.Loop_Exiting:
fmt.println("Event loop exiting")
case:
// Ignore other events
}
return win.Wait{}
}