Skip to content

Commit 67e10a5

Browse files
committed
Improves UI element handling and font loading.
Prevents unnecessary font reloads in text boxes, improving performance. Adds error handling for click events on rectangles, and debug logging for UI events, enhancing stability and debugging capabilities.
1 parent 4a97c47 commit 67e10a5

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/engine/UI/ImmediateUI.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ module ImmediateUIModule
160160

161161
if needsUpdate
162162
# Reload font and regenerate texture
163-
UI.load_font(textBox, joinpath(BasePath, "assets", "fonts"), fontPath)
163+
if textBox.fontSize != fontSize
164+
UI.load_font(textBox, joinpath(BasePath, "assets", "fonts"), fontPath)
165+
end
164166
UI.rerender_text(textBox)
165167
end
166168

src/engine/UI/Rectangle.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,12 @@ module RectangleModule
432432
if evt.type == evt.type == SDL2.SDL_MOUSEBUTTONDOWN
433433
elseif evt.type == SDL2.SDL_MOUSEBUTTONUP
434434
for eventToCall in this.clickEvents
435-
Base.invokelatest(eventToCall,(evt = evt, x = x, y = y))
435+
@debug("calling event $(eventToCall) with $(evt) and $(x) and $(y)")
436+
try
437+
Base.invokelatest(eventToCall, (evt = evt, x = x, y = y))
438+
catch
439+
Base.invokelatest(eventToCall)
440+
end
436441
end
437442
end
438443
end

src/engine/UI/TextBox.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ module TextBoxModule
151151

152152
# If the font is already loaded, clean it up
153153
if this.font != C_NULL
154-
println("closing font")
155-
println(this.font)
154+
@debug("closing font")
155+
#println(this.font)
156156
SDL2.TTF_CloseFont(this.font)
157157
this.font = C_NULL
158158
end
@@ -511,7 +511,7 @@ module TextBoxModule
511511
function UI.handle_window_resize(this::TextBox)
512512
if this.font != C_NULL
513513
# Close the current font
514-
println("closing font from handle_window_resize")
514+
@debug("closing font from handle_window_resize")
515515
SDL2.TTF_CloseFont(this.font)
516516
this.font = C_NULL
517517
# Reload the font with the new scaled size

0 commit comments

Comments
 (0)