1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: fix fireworks exiting when minimized on windows (issue: #9485) (#9487)

This commit is contained in:
penguindark 2021-03-27 16:28:09 +01:00 committed by GitHub
parent 467c6ff726
commit f0e36ca845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,9 +12,13 @@ mut:
frames [][]objects.Rocket
// i thought about using a fixed fifo queue for the frames but the array
// seemed to work fine, if you'd like a challenge try implementing it with the queue :)
draw_flag bool = true
}
fn on_frame(mut app App) {
if !app.draw_flag {
return
}
app.gg.begin()
// drawing previous frames
@ -57,22 +61,35 @@ fn on_frame(mut app App) {
fn on_event(e &gg.Event, mut app App) {
match e.typ {
.resized, .restored, .resumed { app.resize() }
else {}
.resized, .resumed { app.resize() }
.iconified { app.draw_flag = false }
.restored {
app.draw_flag = true
app.resize()
}
else {
//println("Type ${e.typ}")
}
}
}
fn (mut app App) resize() {
size := gg.window_size()
// avoid calls when minimized
if size.width < 2 && size.height < 2 {
return
}
mut s := gg.dpi_scale()
if s == 0.0 {
s = 1.0
}
size := gg.window_size()
app.ui.dpi_scale = s
app.ui.width = size.width
app.ui.height = size.height
}
[console] // is needed for easier diagnostics on windows
fn main() {
mut font_path := os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf'))
$if android {