Skip to content

Commit f58e5a9

Browse files
authored
gg: fire resize event before init if necessary on Android (#14725)
1 parent c6b1c8d commit f58e5a9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

vlib/gg/gg.c.v

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,26 @@ fn gg_init_sokol_window(user_data voidptr) {
222222
ctx.timage_pip = sgl.make_pipeline(&pipdesc)
223223
//
224224
if ctx.config.init_fn != voidptr(0) {
225+
$if android {
226+
// NOTE on Android sokol can emit resize events *before* the init function is
227+
// called (Android has to initialize a lot more through the Activity system to
228+
// reach a valid coontext) and thus the user's code will miss the resize event.
229+
// To prevent this we emit a custom window resize event, if the screen size has
230+
// changed meanwhile.
231+
win_size := ctx.window_size()
232+
if ctx.width != win_size.width || ctx.height != win_size.height {
233+
ctx.width = win_size.width
234+
ctx.height = win_size.height
235+
if ctx.config.resized_fn != voidptr(0) {
236+
e := Event{
237+
typ: .resized
238+
window_width: ctx.width
239+
window_height: ctx.height
240+
}
241+
ctx.config.resized_fn(&e, ctx.user_data)
242+
}
243+
}
244+
}
225245
ctx.config.init_fn(ctx.user_data)
226246
}
227247
// Create images now that we can do that after sg is inited

0 commit comments

Comments
 (0)