remove WindowInfo { maximized }

This commit is contained in:
SunDoge 2022-11-26 11:51:27 +08:00
parent df19fa87d8
commit 2b819ee826
3 changed files with 11 additions and 10 deletions

View file

@ -836,9 +836,6 @@ pub struct WindowInfo {
/// Current monitor size in egui points (logical pixels) /// Current monitor size in egui points (logical pixels)
pub monitor_size: Option<egui::Vec2>, pub monitor_size: Option<egui::Vec2>,
/// Are we in maximize mode?
pub maximized: bool,
} }
/// Information about the URL. /// Information about the URL.

View file

@ -41,7 +41,6 @@ pub fn read_window_info(window: &winit::window::Window, pixels_per_point: f32) -
y: size.height, y: size.height,
}, },
monitor_size, monitor_size,
maximized: window.is_maximized(),
} }
} }

View file

@ -21,7 +21,9 @@ fn main() {
} }
#[derive(Default)] #[derive(Default)]
struct MyApp {} struct MyApp {
maximized: bool,
}
impl eframe::App for MyApp { impl eframe::App for MyApp {
fn clear_color(&self, _visuals: &egui::Visuals) -> egui::Rgba { fn clear_color(&self, _visuals: &egui::Visuals) -> egui::Rgba {
@ -29,7 +31,7 @@ impl eframe::App for MyApp {
} }
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
custom_window_frame(ctx, frame, "egui with custom frame", |ui| { custom_window_frame(self, ctx, frame, "egui with custom frame", |ui| {
ui.label("This is just the contents of the window"); ui.label("This is just the contents of the window");
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("egui theme:"); ui.label("egui theme:");
@ -40,6 +42,7 @@ impl eframe::App for MyApp {
} }
fn custom_window_frame( fn custom_window_frame(
app: &mut MyApp,
ctx: &egui::Context, ctx: &egui::Context,
frame: &mut eframe::Frame, frame: &mut eframe::Frame,
title: &str, title: &str,
@ -115,17 +118,19 @@ fn custom_window_frame(
frame.set_minimized(true); frame.set_minimized(true);
} }
let is_maximized = frame.info().window_info.maximized;
let maximized_response = ui.put( let maximized_response = ui.put(
Rect::from_min_size( Rect::from_min_size(
rect.left_top() + vec2((height - 4.0) * 2.0, 0.0), rect.left_top() + vec2((height - 4.0) * 2.0, 0.0),
Vec2::splat(height), Vec2::splat(height),
), ),
Button::new(RichText::new(if is_maximized { "🗗" } else { "🗖" }).size(height - 4.0)) Button::new(
.frame(false), RichText::new(if app.maximized { "🗗" } else { "🗖" }).size(height - 4.0),
)
.frame(false),
); );
if maximized_response.clicked() { if maximized_response.clicked() {
frame.set_maximized(!is_maximized); app.maximized = !app.maximized;
frame.set_maximized(app.maximized);
} }
// Add the contents: // Add the contents: