Compare commits
10 commits
master
...
feat-windo
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a8b7eebc19 | ||
![]() |
9c98962357 | ||
![]() |
1cb9d954d1 | ||
![]() |
e81f7c8a55 | ||
![]() |
2b819ee826 | ||
![]() |
df19fa87d8 | ||
![]() |
da056696e4 | ||
![]() |
d644b6bc8c | ||
![]() |
817236f640 | ||
![]() |
634d506012 |
4 changed files with 69 additions and 5 deletions
|
@ -11,6 +11,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
|
||||||
#### Desktop/Native:
|
#### Desktop/Native:
|
||||||
* `eframe::run_native` now returns a `Result` ([#2433](https://github.com/emilk/egui/pull/2433)).
|
* `eframe::run_native` now returns a `Result` ([#2433](https://github.com/emilk/egui/pull/2433)).
|
||||||
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).
|
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).
|
||||||
|
* Add `Frame::set_minimized` and `set_maximized` ([#2292](https://github.com/emilk/egui/pull/2292)).
|
||||||
|
|
||||||
#### Web:
|
#### Web:
|
||||||
* Prevent ctrl-P/cmd-P from opening the print dialog ([#2598](https://github.com/emilk/egui/pull/2598)).
|
* Prevent ctrl-P/cmd-P from opening the print dialog ([#2598](https://github.com/emilk/egui/pull/2598)).
|
||||||
|
|
|
@ -718,6 +718,18 @@ impl Frame {
|
||||||
self.output.close = true;
|
self.output.close = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Minimize or unminimize window. (native only)
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub fn set_minimized(&mut self, minimized: bool) {
|
||||||
|
self.output.minimized = Some(minimized);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maximize or unmaximize window. (native only)
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub fn set_maximized(&mut self, maximized: bool) {
|
||||||
|
self.output.maximized = Some(maximized);
|
||||||
|
}
|
||||||
|
|
||||||
/// Tell `eframe` to close the desktop window.
|
/// Tell `eframe` to close the desktop window.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[deprecated = "Renamed `close`"]
|
#[deprecated = "Renamed `close`"]
|
||||||
|
@ -1011,5 +1023,13 @@ pub(crate) mod backend {
|
||||||
/// Set to some bool to tell the window always on top.
|
/// Set to some bool to tell the window always on top.
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub always_on_top: Option<bool>,
|
pub always_on_top: Option<bool>,
|
||||||
|
|
||||||
|
/// Set to some bool to minimize or unminimize window.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub minimized: Option<bool>,
|
||||||
|
|
||||||
|
/// Set to some bool to maximize or unmaximize window.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub maximized: Option<bool>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,8 @@ pub fn handle_app_output(
|
||||||
window_pos,
|
window_pos,
|
||||||
visible: _, // handled in post_present
|
visible: _, // handled in post_present
|
||||||
always_on_top,
|
always_on_top,
|
||||||
|
minimized,
|
||||||
|
maximized,
|
||||||
} = app_output;
|
} = app_output;
|
||||||
|
|
||||||
if let Some(decorated) = decorated {
|
if let Some(decorated) = decorated {
|
||||||
|
@ -250,6 +252,14 @@ pub fn handle_app_output(
|
||||||
WindowLevel::Normal
|
WindowLevel::Normal
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(minimized) = minimized {
|
||||||
|
window.set_minimized(minimized);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(maximized) = maximized {
|
||||||
|
window.set_maximized(maximized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -10,8 +10,8 @@ fn main() -> Result<(), eframe::Error> {
|
||||||
decorated: false,
|
decorated: false,
|
||||||
// To have rounded corners we need transparency:
|
// To have rounded corners we need transparency:
|
||||||
transparent: true,
|
transparent: true,
|
||||||
min_window_size: Some(egui::vec2(320.0, 100.0)),
|
min_window_size: Some(egui::vec2(400.0, 100.0)),
|
||||||
initial_window_size: Some(egui::vec2(320.0, 240.0)),
|
initial_window_size: Some(egui::vec2(400.0, 240.0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
|
@ -22,7 +22,9 @@ fn main() -> Result<(), eframe::Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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) -> [f32; 4] {
|
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) {
|
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:");
|
||||||
|
@ -41,6 +43,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,
|
||||||
|
@ -92,7 +95,11 @@ fn custom_window_frame(
|
||||||
};
|
};
|
||||||
let title_bar_response =
|
let title_bar_response =
|
||||||
ui.interact(title_bar_rect, Id::new("title_bar"), Sense::click());
|
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();
|
frame.drag_window();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +112,32 @@ fn custom_window_frame(
|
||||||
frame.close();
|
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:
|
// Add the contents:
|
||||||
let content_rect = {
|
let content_rect = {
|
||||||
let mut rect = rect;
|
let mut rect = rect;
|
||||||
|
|
Loading…
Reference in a new issue