-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui-borderless.oak
More file actions
138 lines (107 loc) · 5 KB
/
gui-borderless.oak
File metadata and controls
138 lines (107 loc) · 5 KB
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
// gui-borderless.oak
// Demonstrates a borderless (top-barless) window with custom title bar.
//
// Features:
// - No OS title bar or window chrome (WS_POPUP style)
// - Custom-drawn title bar with close button
// - Client-area window dragging via beginDrag/updateDrag/endDrag
//
// Run: magnolia run samples/gui-borderless.oak
{
println: println
string: string
int: int
float: float
} := import('std')
gui := import('GUI')
// ─── Colours ───────────────────────────────────────────────────────────────
C_BG := gui.rgb(22, 24, 30)
C_TITLEBAR := gui.rgb(30, 32, 42)
C_TITLEBAR_TEXT := gui.rgb(200, 210, 230)
C_CLOSE_HOVER := gui.rgb(200, 50, 50)
C_CLOSE_NORMAL := gui.rgb(120, 130, 150)
C_BORDER := gui.rgb(60, 70, 90)
C_CONTENT := gui.rgb(180, 190, 210)
C_ACCENT := gui.rgb(80, 140, 255)
// ─── Layout constants ──────────────────────────────────────────────────────
WIN_W := 640
WIN_H := 420
TITLEBAR_H := 32
CLOSE_SIZE := 16
CLOSE_PAD := 8
// ─── State ─────────────────────────────────────────────────────────────────
state := {
hoverClose: false
dragging: false
}
// ─── Helpers ───────────────────────────────────────────────────────────────
fn inRect?(mx, my, x, y, w, h) mx >= x & mx < x + w & my >= y & my < y + h
fn closeButtonX() WIN_W - CLOSE_SIZE - CLOSE_PAD
fn closeButtonY() (TITLEBAR_H - CLOSE_SIZE) / 2
// ─── Drawing ───────────────────────────────────────────────────────────────
fn drawFrame(window) {
gui.beginFrame(window)
// Background
gui.draw(window, { shape: :rect, x: 0, y: 0, width: WIN_W, height: WIN_H, color: C_BG })
// Border (1px all around)
gui.draw(window, { shape: :line, x1: 0, y1: 0, x2: WIN_W - 1, y2: 0, color: C_BORDER })
gui.draw(window, { shape: :line, x1: 0, y1: WIN_H - 1, x2: WIN_W - 1, y2: WIN_H - 1, color: C_BORDER })
gui.draw(window, { shape: :line, x1: 0, y1: 0, x2: 0, y2: WIN_H - 1, color: C_BORDER })
gui.draw(window, { shape: :line, x1: WIN_W - 1, y1: 0, x2: WIN_W - 1, y2: WIN_H - 1, color: C_BORDER })
// Title bar background
gui.draw(window, { shape: :rect, x: 1, y: 1, width: WIN_W - 2, height: TITLEBAR_H - 1, color: C_TITLEBAR })
// Title text
gui.draw(window, { shape: :text, x: 12, y: 9, text: 'Borderless Window' })
// Close button
cbx := closeButtonX()
cby := closeButtonY()
closeColor := if state.hoverClose { true -> C_CLOSE_HOVER, _ -> C_CLOSE_NORMAL }
// Draw X as two crossing lines
gui.draw(window, { shape: :line, x1: cbx, y1: cby, x2: cbx + CLOSE_SIZE, y2: cby + CLOSE_SIZE, color: closeColor })
gui.draw(window, { shape: :line, x1: cbx + CLOSE_SIZE, y1: cby, x2: cbx, y2: cby + CLOSE_SIZE, color: closeColor })
// Separator line below title bar
gui.draw(window, { shape: :line, x1: 1, y1: TITLEBAR_H, x2: WIN_W - 2, y2: TITLEBAR_H, color: C_BORDER })
// Content area
gui.draw(window, { shape: :text, x: 20, y: TITLEBAR_H + 24, text: 'This window has no OS title bar.' })
gui.draw(window, { shape: :text, x: 20, y: TITLEBAR_H + 48, text: 'Drag the title bar area to move it.' })
gui.draw(window, { shape: :text, x: 20, y: TITLEBAR_H + 72, text: 'Click the X to close.' })
// Accent stripe at bottom
gui.draw(window, { shape: :rect, x: 1, y: WIN_H - 4, width: WIN_W - 2, height: 3, color: C_ACCENT })
gui.endFrame(window)
}
// ─── Main ──────────────────────────────────────────────────────────────────
fn main() {
window := gui.createWindow('Borderless Window', WIN_W, WIN_H, {
borderless: true
updateOnDispatch: true
threading: true
})
if window.type != :ok -> {
println('Could not create window.')
println(string(window))
exit(1)
}
gui.show(window)
gui.onMouseMove(window, fn(mx, my) {
state.hoverClose <- inRect?(mx, my, closeButtonX(), closeButtonY(), CLOSE_SIZE, CLOSE_SIZE)
if state.dragging -> gui.updateDrag(window)
})
gui.onLButtonDown(window, fn(mx, my) {
if inRect?(mx, my, closeButtonX(), closeButtonY(), CLOSE_SIZE, CLOSE_SIZE) -> {
gui.close(window)
}
// Drag if clicking in the title bar (but not the close button)
if my < TITLEBAR_H & !inRect?(mx, my, closeButtonX(), closeButtonY(), CLOSE_SIZE, CLOSE_SIZE) -> {
gui.beginDrag(window)
state.dragging <- true
}
})
gui.onLButtonUp(window, fn(mx, my) {
if state.dragging -> {
gui.endDrag(window)
state.dragging <- false
}
})
gui.run(window, fn(step) drawFrame(window))
}
main()