-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemreq.odin
More file actions
162 lines (133 loc) · 4.1 KB
/
gemreq.odin
File metadata and controls
162 lines (133 loc) · 4.1 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package gemreq
import "uri"
import "core:c"
import "core:fmt"
import "core:log"
import "core:sync"
import "core:slice"
import "core:thread"
import "core:strconv"
import "core:strings"
import "core:sync/chan"
import "core:path/slashpath"
import "vendor:raylib"
LERP_FACTOR := 0.2
SCROLL_FACTOR := 0.6
color_text := raylib.GetColor(0xE8EAEDFF)
color_link := raylib.GetColor(0x4C97FFFF)
color_background := raylib.GetColor(0x101218FF)
Browser :: struct {
fonts: map[string]Font_Asset,
debug: bool,
hover: Maybe(string),
omnibar: Omnibar,
history: History,
document: Maybe(Document),
endpoint: Maybe(Endpoint),
endpoint_mutex: sync.Mutex,
navigate_queue: Maybe(string),
network_thread: ^Thread,
cursor_shape: raylib.MouseCursor,
scroll: struct {
current: f64,
target: f64,
},
channels: struct {
request: Channel_Request,
document: Channel_Document,
},
}
launch :: proc(browser: ^Browser) {
browser.history = make_history()
browser.document = nil
browser.cursor_shape = .DEFAULT
browser.fonts = make(map[string]Font_Asset)
font_load(browser, FONT_SANS_REGULAR, "assets/font/NotoSans-Regular.ttf")
font_load(browser, FONT_SANS_BOLD, "assets/font/NotoSans-Bold.ttf")
launch_omnibar(&browser.omnibar)
}
unload :: proc(browser: ^Browser) {
for name, asset in browser.fonts {
for font in asset do raylib.UnloadFont(font)
log.infof("font %s unloaded", name)
}
delete(browser.fonts)
unload_omnibar(&browser.omnibar)
delete_history(&browser.history)
}
update :: proc(browser: ^Browser, dt: f64) {
must_reload_layout := ui_scaling_update()
cursor_shape := raylib.MouseCursor.DEFAULT
if browser.hover != nil do cursor_shape = .POINTING_HAND
if cursor_shape != browser.cursor_shape {
raylib.SetMouseCursor(cursor_shape)
browser.cursor_shape = cursor_shape
}
if text, queued := browser.navigate_queue.(string); queued {
navigate(browser, text)
browser.navigate_queue = nil
}
update_omnibar(browser, dt)
update_history(browser, dt)
update_document(browser, dt, must_reload_layout)
key_debug := raylib.IsKeyPressed(.F3)
if key_debug do browser.debug = !browser.debug
browser.hover = nil
browser.omnibar.visible = (browser.omnibar.visible || browser.document == nil)
}
// NOTE(XENOBAS): Non ascii glyphs slow down rendering ?
draw :: proc(browser: ^Browser) {
using raylib
ClearBackground(color_background)
if document, exists := browser.document.(Document); exists do draw_document(browser, document)
if browser.history.visible do draw_history(browser)
if browser.omnibar.visible do draw_omnibar(browser)
if browser.debug {
ui := ui_scaling_pixels()
font := browser.fonts[FONT_SANS_REGULAR][.Small]
texts := [?]cstring{
fmt.ctprintf("FPS: %d", GetFPS()),
fmt.ctprintf("History: %d entries", len(browser.history.entries)),
}
offset := ui.padding.y / 4
for text in texts {
measure := MeasureTextEx(font, text, 24.0, 1.0)
DrawTextEx(font, text, { ui.padding.x / 4, offset }, 24.0, 1.0, WHITE)
offset += measure.y + measure.y / 2
}
}
}
// TODO(XENOBAS): Add a custom border with .WINDOW_UNDECORATED with resize and title close functionality
main :: proc() {
using raylib
context.logger = log.create_console_logger()
defer log.destroy_console_logger(context.logger)
SetTraceLogLevel(.WARNING)
SetConfigFlags({ .MSAA_4X_HINT, .BORDERLESS_WINDOWED_MODE, .INTERLACED_HINT, .WINDOW_RESIZABLE })
SetTargetFPS(120)
InitWindow(i32(WINDOW_WIDTH), i32(WINDOW_HEIGHT), "Gemreq - Gemini browser")
log.infof("window created %02.2fx%02.2f", WINDOW_WIDTH, WINDOW_HEIGHT)
defer {
log.info("browser loop completed")
CloseWindow()
}
SetExitKey(.KEY_NULL)
browser: Browser
launch(&browser)
defer unload(&browser)
routine_network_init(&browser)
defer routine_network_destroy(&browser)
browser.network_thread = thread.create_and_start_with_poly_data(&browser, routine_network, init_context = context)
defer routine_network_terminate(&browser)
for {
must_close := WindowShouldClose()
if must_close do break
dt := cast(f64)GetFrameTime()
update(&browser, dt)
BeginDrawing()
draw(&browser)
EndDrawing()
free_all(context.temp_allocator)
}
free_all(context.temp_allocator)
}