Skip to content

Commit 6824a94

Browse files
committed
Clean up SDL code and fix sloppy mistakes
1 parent eb83682 commit 6824a94

File tree

4 files changed

+298
-446
lines changed

4 files changed

+298
-446
lines changed

bindings/odin/examples/shared_layouts/clay_video_demo.odin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ video_demo_layout :: proc(data: ^Video_Demo_Data) -> clay.ClayArray(clay.RenderC
100100
// Child elements go inside braces
101101
if clay.UI(clay.ID("HeaderBar"))(
102102
{
103-
layout = {sizing = {height = clay.SizingFixed(60), width = clay.SizingFixed(0)}, padding = {16, 16, 0, 0}, childGap = 16, childAlignment = {y = .Center}},
103+
layout = {sizing = {height = clay.SizingFixed(60), width = clay.SizingGrow()}, padding = {16, 16, 0, 0}, childGap = 16, childAlignment = {y = .Center}},
104104
backgroundColor = contentBackgroundColor,
105105
cornerRadius = clay.CornerRadiusAll(8),
106106
},
@@ -154,7 +154,7 @@ video_demo_layout :: proc(data: ^Video_Demo_Data) -> clay.ClayArray(clay.RenderC
154154
clay.TextDynamic(document.title, clay.TextConfig({fontId = VIDEO_DEMO_FONT_ID_BODY, fontSize = 20, textColor = {255, 255, 255, 255}}))
155155
}
156156
} else {
157-
clickData := new_clone((Sidebar_Click_Data) {
157+
clickData := new_clone(Sidebar_Click_Data {
158158
requestedDocumentIndex = i,
159159
selectedDocumentIndex = &data.selectedDocumentIndex,
160160
}, context.temp_allocator)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Odin doesn't directly package SDL, so on Windows, you'll want to copy `SDL3.dll` and `SDL3_ttf.dll` into this directory. On Linux and Mac, you should install SDL3 via your package manager
1+
Odin doesn't directly package SDL, so on Windows, you'll want to copy `SDL3.dll` and `SDL3_ttf.dll` into this directory from odin's `vendor/sdl3` directory located next to the compiler. You can use `odin root` to figure out where your compiler is installed. On Linux and Mac, you should install SDL3 via your package manager
22

33
## Running on Windows
44
In an embdedded termninal, missing dependencies will fail silently on Windows, so if you have any unexplainable crashes, make sure the DLLs are in your current working directory (the path you run the command from). It's easiest to just copy them next to this file, and run from here as well.

bindings/odin/examples/video_demo_sdl/main.odin

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import "vendor:sdl3/ttf"
1010

1111
App_State :: struct {
1212
window: ^sdl.Window,
13-
rendererData: Clay_SDL3RendererData,
13+
rendererData: Clay_SDL_Render_Data,
1414
}
1515

1616
state: App_State
@@ -22,7 +22,7 @@ errorHandler :: proc "c" (errorData: clay.ErrorData) {
2222
}
2323

2424
load_font :: proc(data: []byte, size: f32, id: u16, fonts: ^[dynamic]^ttf.Font) {
25-
font_stream := sdl.IOFromConstMem(raw_data(ROBOTO), uint(len(ROBOTO)))
25+
font_stream := sdl.IOFromConstMem(raw_data(data), uint(len(data)))
2626
font := ttf.OpenFontIO(font_stream, true, size * 2)
2727
assign_at(fonts, int(id), font)
2828
}
@@ -38,7 +38,7 @@ measure_text :: proc "c" (text: clay.StringSlice, config: ^clay.TextElementConfi
3838
sdl.LogError(i32(sdl.LogCategory.ERROR), "Failed to measure text: %s", sdl.GetError())
3939
}
4040

41-
return clay.Dimensions{f32(width), f32(height)}
41+
return {f32(width), f32(height)}
4242
}
4343
// Load at compile time, directly into the binary
4444
ROBOTO := #load("./Roboto-Regular.ttf")
@@ -58,9 +58,9 @@ main :: proc() {
5858

5959
state.window = window
6060
state.rendererData.renderer = renderer
61-
state.rendererData.textEngine = ttf.CreateRendererTextEngine(renderer)
61+
state.rendererData.text_engine = ttf.CreateRendererTextEngine(renderer)
6262

63-
minMemorySize := (uint)(clay.MinMemorySize())
63+
minMemorySize := uint(clay.MinMemorySize())
6464
arena: clay.Arena = clay.CreateArenaWithCapacityAndMemory(minMemorySize, make([^]u8, minMemorySize))
6565
clay.Initialize(arena, {1280, 720}, {handler = errorHandler})
6666
clay.SetMeasureTextFunction(measure_text, &state.rendererData.fonts)
@@ -78,12 +78,10 @@ main :: proc() {
7878
window_width, window_height: i32
7979

8080
for !done {
81-
defer free_all(context.temp_allocator)
82-
8381
scrollDelta: clay.Vector2
8482

85-
for (sdl.PollEvent(&event)) {
86-
if (event.type == .QUIT) {
83+
for sdl.PollEvent(&event) {
84+
if event.type == .QUIT {
8785
done = true
8886
} else if event.type == .MOUSE_WHEEL {
8987
scrollDelta.x = event.wheel.x
@@ -99,10 +97,8 @@ main :: proc() {
9997

10098
clay.SetLayoutDimensions({width = f32(window_width), height = f32(window_height)})
10199

102-
mouseX: f32 = 0
103-
mouseY: f32 = 0
104-
mouseState := sdl.GetMouseState(&mouseX, &mouseY)
105-
mousePosition := (clay.Vector2){mouseX, mouseY}
100+
mousePosition : clay.Vector2
101+
mouseState := sdl.GetMouseState(&mousePosition.x, &mousePosition.y)
106102
clay.SetPointerState(mousePosition, .LEFT in mouseState)
107103

108104
clay.UpdateScrollContainers(false, scrollDelta, f32(deltaTime))
@@ -112,7 +108,7 @@ main :: proc() {
112108

113109
sdl.SetRenderDrawColor(renderer, 0, 0, 0, 255)
114110
sdl.RenderClear(renderer)
115-
sdl_Clay_RenderClayCommands(&state.rendererData, &commands)
111+
sdl_render_clay_commands(&state.rendererData, &commands)
116112

117113
sdl.RenderPresent(renderer)
118114
}

0 commit comments

Comments
 (0)