mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
eframe: add function to set, query and toggle fullscreen mode (#1866)
Closes https://github.com/emilk/egui/pull/674 Adds `NativeOptions:fullscreen`, `Frame::set_fullscreen` and `WindowInfo::fullscreen`.
This commit is contained in:
@@ -180,6 +180,11 @@ pub struct NativeOptions {
|
||||
/// If false it will be difficult to move and resize the app.
|
||||
pub decorated: bool,
|
||||
|
||||
/// Start in (borderless) fullscreen?
|
||||
///
|
||||
/// Default: `false`.
|
||||
pub fullscreen: bool,
|
||||
|
||||
/// On Windows: enable drag and drop support. Drag and drop can
|
||||
/// not be disabled on other platforms.
|
||||
///
|
||||
@@ -270,6 +275,7 @@ impl Default for NativeOptions {
|
||||
always_on_top: false,
|
||||
maximized: false,
|
||||
decorated: true,
|
||||
fullscreen: false,
|
||||
drag_and_drop_support: true,
|
||||
icon_data: None,
|
||||
initial_window_pos: None,
|
||||
@@ -547,11 +553,17 @@ impl Frame {
|
||||
}
|
||||
|
||||
/// Set whether to show window decorations (i.e. a frame around you app).
|
||||
///
|
||||
/// If false it will be difficult to move and resize the app.
|
||||
pub fn set_decorations(&mut self, decorated: bool) {
|
||||
self.output.decorated = Some(decorated);
|
||||
}
|
||||
|
||||
/// Turn borderless fullscreen on/off (native only).
|
||||
pub fn set_fullscreen(&mut self, fullscreen: bool) {
|
||||
self.output.fullscreen = Some(fullscreen);
|
||||
}
|
||||
|
||||
/// set the position of the outer window
|
||||
pub fn set_window_pos(&mut self, pos: egui::Pos2) {
|
||||
self.output.window_pos = Some(pos);
|
||||
@@ -591,6 +603,9 @@ pub struct WindowInfo {
|
||||
/// Unit: egui points (logical pixels).
|
||||
pub position: egui::Pos2,
|
||||
|
||||
/// Are we in fullscreen mode?
|
||||
pub fullscreen: bool,
|
||||
|
||||
/// Window inner size in egui points (logical pixels).
|
||||
pub size: egui::Vec2,
|
||||
}
|
||||
@@ -740,6 +755,9 @@ pub mod backend {
|
||||
/// Set to some bool to change window decorations.
|
||||
pub decorated: Option<bool>,
|
||||
|
||||
/// Set to some bool to change window fullscreen.
|
||||
pub fullscreen: Option<bool>,
|
||||
|
||||
/// Set to true to drag window while primary mouse button is down.
|
||||
pub drag_window: bool,
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ pub fn read_window_info(
|
||||
.to_logical::<f32>(pixels_per_point.into());
|
||||
Some(WindowInfo {
|
||||
position: egui::Pos2 { x: pos.x, y: pos.y },
|
||||
fullscreen: window.fullscreen().is_some(),
|
||||
size: egui::Vec2 {
|
||||
x: size.width,
|
||||
y: size.height,
|
||||
@@ -39,6 +40,7 @@ pub fn window_builder(
|
||||
always_on_top,
|
||||
maximized,
|
||||
decorated,
|
||||
fullscreen,
|
||||
drag_and_drop_support,
|
||||
icon_data,
|
||||
initial_window_pos,
|
||||
@@ -54,8 +56,9 @@ pub fn window_builder(
|
||||
|
||||
let mut window_builder = winit::window::WindowBuilder::new()
|
||||
.with_always_on_top(*always_on_top)
|
||||
.with_maximized(*maximized)
|
||||
.with_decorations(*decorated)
|
||||
.with_fullscreen(fullscreen.then(|| winit::window::Fullscreen::Borderless(None)))
|
||||
.with_maximized(*maximized)
|
||||
.with_resizable(*resizable)
|
||||
.with_transparent(*transparent)
|
||||
.with_window_icon(window_icon);
|
||||
@@ -118,6 +121,7 @@ pub fn handle_app_output(
|
||||
window_size,
|
||||
window_title,
|
||||
decorated,
|
||||
fullscreen,
|
||||
drag_window,
|
||||
window_pos,
|
||||
visible,
|
||||
@@ -137,6 +141,10 @@ pub fn handle_app_output(
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(fullscreen) = fullscreen {
|
||||
window.set_fullscreen(fullscreen.then(|| winit::window::Fullscreen::Borderless(None)));
|
||||
}
|
||||
|
||||
if let Some(window_title) = window_title {
|
||||
window.set_title(&window_title);
|
||||
}
|
||||
|
||||
@@ -298,6 +298,7 @@ impl AppRunner {
|
||||
window_size: _, // Can't resize a web page
|
||||
window_title: _, // TODO(emilk): change title of window
|
||||
decorated: _, // Can't toggle decorations
|
||||
fullscreen: _, // TODO(emilk): fullscreen web window
|
||||
drag_window: _, // Can't be dragged
|
||||
window_pos: _, // Can't set position of a web page
|
||||
visible: _, // Can't hide a web page
|
||||
|
||||
Reference in New Issue
Block a user