Skip to content

Commit

Permalink
feat: scale to available ui area
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Jan 28, 2024
1 parent ba834e4 commit 89969e1
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,22 +861,7 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
app.window().request_frame();
}

if state.reset_image {
let window_size = app.window().size().size_vec();
if let Some(current_image) = &state.current_image {
let img_size = current_image.size_vec();
let scale_factor = (window_size.x / img_size.x)
.min(window_size.y / img_size.y)
.min(1.0);
state.image_geometry.scale = scale_factor;
state.image_geometry.offset =
window_size / 2.0 - (img_size * state.image_geometry.scale) / 2.0;

debug!("Image has been reset.");
state.reset_image = false;
}
// app.window().request_frame();
}


// TODO: Do we need/want a "global" checker?
// if state.persistent_settings.show_checker_background {
Expand Down Expand Up @@ -1043,10 +1028,35 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
} else {
state.key_grab = false;
}

if state.reset_image {
let draw_area = ctx.available_rect();

let mut window_size = app.window().size().size_vec();
window_size.x = draw_area.width();

if let Some(current_image) = &state.current_image {
let img_size = current_image.size_vec();
let scale_factor = (window_size.x / img_size.x)
.min(window_size.y / img_size.y)
.min(1.0);
state.image_geometry.scale = scale_factor;
state.image_geometry.offset =
window_size / 2.0 - (img_size * state.image_geometry.scale) / 2.0 ;
// offset by left draw area
state.image_geometry.offset.x += draw_area.left();
debug!("Image has been reset.");
state.reset_image = false;
}
app.window().request_frame();
}

// Settings come last, as they block keyboard grab (for hotkey assigment)
settings_ui(app, ctx, state, gfx);
});



if state.network_mode {
app.window().request_frame();
}
Expand Down

0 comments on commit 89969e1

Please sign in to comment.