mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
eframe: add set_minimized and set_maximized (#2292)
* add actions for window controls
* add maximized to WindowInfo
update button text
fix clippy
* add overlap icon when maximized
* remove argument `app`
* remove WindowInfo { maximized }
* Update minimum window size
* Double-click titlebar to toggle maximized state
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -10,8 +10,8 @@ fn main() -> Result<(), eframe::Error> {
|
||||
decorated: false,
|
||||
// To have rounded corners we need transparency:
|
||||
transparent: true,
|
||||
min_window_size: Some(egui::vec2(320.0, 100.0)),
|
||||
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
||||
min_window_size: Some(egui::vec2(400.0, 100.0)),
|
||||
initial_window_size: Some(egui::vec2(400.0, 240.0)),
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
@@ -22,7 +22,9 @@ fn main() -> Result<(), eframe::Error> {
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct MyApp {}
|
||||
struct MyApp {
|
||||
maximized: bool,
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn clear_color(&self, _visuals: &egui::Visuals) -> [f32; 4] {
|
||||
@@ -30,7 +32,7 @@ impl eframe::App for MyApp {
|
||||
}
|
||||
|
||||
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.horizontal(|ui| {
|
||||
ui.label("egui theme:");
|
||||
@@ -41,6 +43,7 @@ impl eframe::App for MyApp {
|
||||
}
|
||||
|
||||
fn custom_window_frame(
|
||||
app: &mut MyApp,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
title: &str,
|
||||
@@ -92,7 +95,11 @@ fn custom_window_frame(
|
||||
};
|
||||
let title_bar_response =
|
||||
ui.interact(title_bar_rect, Id::new("title_bar"), Sense::click());
|
||||
if title_bar_response.is_pointer_button_down_on() {
|
||||
|
||||
if title_bar_response.double_clicked() {
|
||||
app.maximized = !app.maximized;
|
||||
frame.set_maximized(app.maximized);
|
||||
} else if title_bar_response.is_pointer_button_down_on() {
|
||||
frame.drag_window();
|
||||
}
|
||||
|
||||
@@ -105,6 +112,32 @@ fn custom_window_frame(
|
||||
frame.close();
|
||||
}
|
||||
|
||||
let minimized_response = ui.put(
|
||||
Rect::from_min_size(
|
||||
rect.left_top() + vec2((height - 4.0) * 1.0, 0.0),
|
||||
Vec2::splat(height),
|
||||
),
|
||||
Button::new(RichText::new("🗕").size(height - 4.0)).frame(false),
|
||||
);
|
||||
if minimized_response.clicked() {
|
||||
frame.set_minimized(true);
|
||||
}
|
||||
|
||||
let maximized_response = ui.put(
|
||||
Rect::from_min_size(
|
||||
rect.left_top() + vec2((height - 4.0) * 2.0, 0.0),
|
||||
Vec2::splat(height),
|
||||
),
|
||||
Button::new(
|
||||
RichText::new(if app.maximized { "🗗" } else { "🗖" }).size(height - 4.0),
|
||||
)
|
||||
.frame(false),
|
||||
);
|
||||
if maximized_response.clicked() {
|
||||
app.maximized = !app.maximized;
|
||||
frame.set_maximized(app.maximized);
|
||||
}
|
||||
|
||||
// Add the contents:
|
||||
let content_rect = {
|
||||
let mut rect = rect;
|
||||
|
||||
Reference in New Issue
Block a user