Skip to content

Commit

Permalink
feat: Enable borderless mode and allow to toggle via settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Feb 4, 2024
1 parent c9dead5 commit 01d4825
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ bitflags = "2.4.1"
flate2 = "1.0.28"
ruzstd = "0.5.0"
basis-universal = "0.3.1"
mouse_position = "0.1.3"

[features]
heif = ["libheif-rs"]
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn main() -> Result<(), String> {
Ok(settings) => {
window_config.vsync = settings.vsync;
window_config.lazy_loop = !settings.force_redraw;
window_config.decorations = !settings.borderless;
if settings.window_geometry != Default::default() {
window_config.width = settings.window_geometry.1 .0 as u32;
window_config.height = settings.window_geometry.1 .1 as u32;
Expand Down
2 changes: 2 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct PersistentSettings {
pub linear_mag_filter: bool,
pub fit_image_on_window_resize: bool,
pub zoom_multiplier: f32,
pub borderless: bool,
}

impl Default for PersistentSettings {
Expand Down Expand Up @@ -85,6 +86,7 @@ impl Default for PersistentSettings {
linear_mag_filter: false,
fit_image_on_window_resize: false,
zoom_multiplier: 1.0,
borderless: false,
}
}
}
Expand Down
60 changes: 54 additions & 6 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use crate::{

const ICON_SIZE: f32 = 24.;

use egui_phosphor::regular::*;

use arboard::Clipboard;
use egui_phosphor::regular::*;
use egui_plot::{Plot, PlotPoints, Points};
use image::RgbaImage;
use log::{debug, error, info};
use mouse_position::mouse_position::Mouse;
use notan::{
egui::{self, *},
prelude::{App, Graphics},
Expand Down Expand Up @@ -177,14 +177,12 @@ impl EguiExt for Ui {
}
}


/// Proof-of-concept funtion to draw texture completely with egui
#[allow(unused)]
pub fn image_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) {
if let Some(texture) = &state.current_texture {
let tex_id = gfx.egui_register_texture(texture);


let image_rect = Rect::from_center_size(
Pos2::new(
state.image_geometry.offset.x
Expand All @@ -207,9 +205,8 @@ pub fn image_ui(ctx: &Context, state: &mut OculanteState, gfx: &mut Graphics) {
tex_id.id,
image_rect,
Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)),
Color32::WHITE
Color32::WHITE,
);

}

// state.image_geometry.scale;
Expand Down Expand Up @@ -598,6 +595,10 @@ pub fn settings_ui(app: &mut App, ctx: &Context, state: &mut OculanteState, gfx:
ui.end_row();

ui.add(egui::DragValue::new(&mut state.persistent_settings.zoom_multiplier).clamp_range(0.05..=10.0).prefix("Zoom multiplier: ").speed(0.01)).on_hover_text("Adjust how much you zoom when you use the mouse wheel or the trackpad.");
ui.checkbox(&mut state.persistent_settings.borderless, "Borderless mode").on_hover_text("Don't draw OS window decorations. Needs restart.");
ui.end_row();


});

ui.horizontal(|ui| {
Expand Down Expand Up @@ -1795,6 +1796,11 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu
use crate::shortcuts::InputEvent::*;

// ui.label("Channels");
if state.persistent_settings.borderless {
if unframed_button(X, ui).clicked() {
app.backend.exit();
}
}

#[cfg(feature = "file_open")]
if unframed_button(FOLDER, ui)
Expand Down Expand Up @@ -2008,6 +2014,48 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu
app.window().request_frame();
}

if state.persistent_settings.borderless {
let r = ui.interact(
ui.available_rect_before_wrap(),
Id::new("drag"),
Sense::click_and_drag(),
);

if r.dragged() {
// improve responsiveness
app.window().request_frame();
let position = Mouse::get_mouse_position();
match position {
Mouse::Position { mut x, mut y } => {
// translate mouse pos into real pixels
let dpi = app.backend.window().dpi();
x = (x as f64 * dpi) as i32;
y = (y as f64 * dpi) as i32;

let offset = match ui
.ctx()
.memory(|r| r.data.get_temp::<(i32, i32)>("offset".into()))
{
Some(o) => o,
None => {
let window_pos = app.window().position();
let offset = (window_pos.0 - x, window_pos.1 - y);
ui.ctx()
.memory_mut(|w| w.data.insert_temp(Id::new("offset"), offset));
offset
}
};
app.window().set_position(x + offset.0, y + offset.1);
}
Mouse::Error => error!("Error getting mouse position"),
}
}
if r.drag_released() {
ui.ctx()
.memory_mut(|w| w.data.remove::<(i32, i32)>("offset".into()))
}
}

ui.add_space(ui.available_width() - 32.);

ui.scope(|ui| {
Expand Down

0 comments on commit 01d4825

Please sign in to comment.