Allow users to create viewports larger than monitor on Windows & macOS (#4337)

Added clamp_size_to_monitor_size field on ViewportBuilder, which means
whether clamp the window's size to monitor's size. (default to `true`)

* Closes https://github.com/emilk/egui/issues/3389

### simple example

```rust
pub struct MyApp {}

impl MyApp {
    pub fn new() -> MyApp {
        MyApp {}
    }
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
        egui::CentralPanel::default()
            .frame(Frame::none().fill(Color32::DARK_GRAY))
            .show(ctx, |ui| {
                if ctx.input(|i| i.key_pressed(Key::Escape)) {
                    ctx.send_viewport_cmd(ViewportCommand::Close);
                }
            });
    }
}

pub fn main() {
    let option = eframe::NativeOptions {
        viewport: ViewportBuilder::default()
            .with_position([10.0, 10.0])
            .with_inner_size([3000.0, 2000.0])
            .with_clamp_size_to_monitor_size(false),
        ..Default::default()
    };

    eframe::run_native(
        "a large window app",
        option,
        Box::new(|ctx| Box::new(MyApp::new())),
    ).unwrap();
}
```

It works on my windows (with 3 monitors), but I don't have a test
environment for macos

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
lopo
2024-04-22 12:44:21 +02:00
committed by GitHub
co-authored by Emil Ernerfeldt
parent 436c671331
commit ff8cfc2aa0
3 changed files with 40 additions and 6 deletions
+22
View File
@@ -275,6 +275,11 @@ pub struct ViewportBuilder {
pub min_inner_size: Option<Vec2>,
pub max_inner_size: Option<Vec2>,
/// Whether clamp the window's size to monitor's size. The default is `true` on linux, otherwise it is `false`.
///
/// Note: On some Linux systems, a window size larger than the monitor causes crashes
pub clamp_size_to_monitor_size: Option<bool>,
pub fullscreen: Option<bool>,
pub maximized: Option<bool>,
pub resizable: Option<bool>,
@@ -493,6 +498,15 @@ impl ViewportBuilder {
self
}
/// Sets whether clamp the window's size to monitor's size. The default is `true` on linux, otherwise it is `false`.
///
/// Note: On some Linux systems, a window size larger than the monitor causes crashes
#[inline]
pub fn with_clamp_size_to_monitor_size(mut self, value: bool) -> Self {
self.clamp_size_to_monitor_size = Some(value);
self
}
/// Does not work on X11.
#[inline]
pub fn with_close_button(mut self, value: bool) -> Self {
@@ -606,6 +620,7 @@ impl ViewportBuilder {
inner_size: new_inner_size,
min_inner_size: new_min_inner_size,
max_inner_size: new_max_inner_size,
clamp_size_to_monitor_size: new_clamp_size_to_monitor_size,
fullscreen: new_fullscreen,
maximized: new_maximized,
resizable: new_resizable,
@@ -740,6 +755,13 @@ impl ViewportBuilder {
let mut recreate_window = false;
if new_clamp_size_to_monitor_size.is_some()
&& self.clamp_size_to_monitor_size != new_clamp_size_to_monitor_size
{
self.clamp_size_to_monitor_size = new_clamp_size_to_monitor_size;
recreate_window = true;
}
if new_active.is_some() && self.active != new_active {
self.active = new_active;
recreate_window = true;