Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fullscreen #674

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [

### Added ⭐
* Add horizontal scrolling support to `ScrollArea` and `Window` (opt-in).
* Support for fullscreen windowing.

### Changed 🔧
* All `Ui`:s must now have a finite `max_rect`.
Expand Down
4 changes: 2 additions & 2 deletions egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,12 @@ impl Context {

// ---------------------------------------------------------------------

/// Wether or not to debug widget layout on hover.
/// Whether or not to debug widget layout on hover.
pub fn debug_on_hover(&self) -> bool {
self.memory().options.style.debug.debug_on_hover
}

/// Turn on/off wether or not to debug widget layout on hover.
/// Turn on/off whether or not to debug widget layout on hover.
pub fn set_debug_on_hover(&self, debug_on_hover: bool) {
let mut style = (*self.memory().options.style).clone();
style.debug.debug_on_hover = debug_on_hover;
Expand Down
2 changes: 1 addition & 1 deletion egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct Memory {
#[cfg_attr(feature = "persistence", serde(default))]
pub struct Options {
/// The default style for new `Ui`:s.
#[cfg_attr(feature = "persistence", serde(skip))]
#[cfg_attr(feature = "persistence", serde(default))]
pub(crate) style: std::sync::Arc<Style>,

/// Controls the tessellator.
Expand Down
10 changes: 10 additions & 0 deletions egui_demo_lib/src/backend_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ impl BackendPanel {
frame.set_window_size(egui::Vec2::new(375.0, 812.0)); // iPhone 12 mini
}

if !frame.is_web() {
ui.separator();

let mut fullscreen = frame.is_fullscreen();
ui.checkbox(&mut fullscreen, "🗖 Fullscreen")
.on_hover_text("Fullscreen the window");

frame.set_fullscreen(fullscreen);
}

ui.separator();

ui.label("egui windows:");
Expand Down
55 changes: 43 additions & 12 deletions egui_glium/src/backend.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{window_settings::WindowSettings, *};
use egui::Color32;
#[cfg(target_os = "windows")]
use glium::glutin::platform::windows::WindowBuilderExtWindows;
use glium::glutin::window::Fullscreen;
use std::time::Instant;

#[cfg(feature = "persistence")]
Expand Down Expand Up @@ -88,7 +89,12 @@ fn create_display(
.with_resizable(native_options.resizable)
.with_title(app.name())
.with_transparent(native_options.transparent)
.with_window_icon(window_icon);
.with_window_icon(window_icon)
.with_fullscreen(if native_options.fullscreen {
Some(Fullscreen::Borderless(None))
} else {
None
});

window_builder =
window_builder_drag_and_drop(window_builder, native_options.drag_and_drop_support);
Expand Down Expand Up @@ -240,6 +246,11 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: epi::NativeOptions) {
// eprintln!("Warmed up in {} ms", warm_up_start.elapsed().as_millis())
}

let mut app_output = epi::backend::AppOutput {
fullscreen: display.gl_window().window().fullscreen().is_some(),
..Default::default()
};

let mut is_focused = true;
let mut running = true;
let mut repaint_asap = true;
Expand Down Expand Up @@ -315,7 +326,6 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: epi::NativeOptions) {

egui.begin_frame(&display);
let (ctx, painter) = egui.ctx_and_painter_mut();
let mut app_output = epi::backend::AppOutput::default();
let mut frame = epi::backend::FrameBuilder {
info: integration_info(&display, previous_frame_time),
tex_allocator: painter,
Expand Down Expand Up @@ -346,16 +356,37 @@ pub fn run(mut app: Box<dyn epi::App>, native_options: epi::NativeOptions) {
}

{
let epi::backend::AppOutput { quit, window_size } = app_output;

if let Some(window_size) = window_size {
display.gl_window().window().set_inner_size(
glutin::dpi::PhysicalSize {
width: (egui.ctx().pixels_per_point() * window_size.x).round(),
height: (egui.ctx().pixels_per_point() * window_size.y).round(),
}
.to_logical::<f32>(native_pixels_per_point(&display) as f64),
);
let epi::backend::AppOutput {
quit,
fullscreen,
window_size,
} = app_output;

if fullscreen {
if display.gl_window().window().fullscreen().is_none() {
app_output.window_size = Some(Vec2 {
x: display.gl_window().window().inner_size().width as f32,
y: display.gl_window().window().inner_size().height as f32,
});
}
display
.gl_window()
.window()
.set_fullscreen(Some(Fullscreen::Borderless(None)));
} else {
display.gl_window().window().set_fullscreen(None);

if let Some(window_size) = window_size {
display.gl_window().window().set_inner_size(
glutin::dpi::PhysicalSize {
width: (egui.ctx().pixels_per_point() * window_size.x).round(),
height: (egui.ctx().pixels_per_point() * window_size.y).round(),
}
.to_logical::<f32>(native_pixels_per_point(&display) as f64),
);
} else {
app_output.window_size = None;
}
}

if quit {
Expand Down
18 changes: 14 additions & 4 deletions egui_glium/src/window_settings.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use glium::glutin;
pub struct WindowSettings {
/// outer position of window in physical pixels
pos: Option<egui::Pos2>,
/// If the window was in the fullscreen state
fullscreen: bool,
/// Inner size of window in logical pixels
inner_size_points: Option<egui::Vec2>,
}
Expand All @@ -30,6 +32,8 @@ impl WindowSettings {
.ok()
.map(|p| egui::pos2(p.x as f32, p.y as f32)),

fullscreen: display.gl_window().window().fullscreen().is_some(),

inner_size_points: Some(egui::vec2(
inner_size_points.width as f32,
inner_size_points.height as f32,
Expand All @@ -42,10 +46,16 @@ impl WindowSettings {
window: glutin::window::WindowBuilder,
) -> glutin::window::WindowBuilder {
if let Some(inner_size_points) = self.inner_size_points {
window.with_inner_size(glutin::dpi::LogicalSize {
width: inner_size_points.x as f64,
height: inner_size_points.y as f64,
})
window
.with_inner_size(glutin::dpi::LogicalSize {
width: inner_size_points.x as f64,
height: inner_size_points.y as f64,
})
.with_fullscreen(if self.fullscreen {
Some(glutin::window::Fullscreen::Borderless(None))
} else {
None
})
} else {
window
}
Expand Down
1 change: 1 addition & 0 deletions egui_web/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl AppRunner {
{
let epi::backend::AppOutput {
quit: _, // Can't quit a web page
fullscreen: _, // Can't fullscreen a web page
window_size: _, // Can't resize a web page
} = app_output;
}
Expand Down
17 changes: 17 additions & 0 deletions epi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ pub struct NativeOptions {
/// uses that use multi-threaded COM API <https://github.com/rust-windowing/winit/pull/1524>
pub drag_and_drop_support: bool,

/// Sets the default window to fullscreen mode.
pub fullscreen: bool,

/// The application icon, e.g. in the Windows task bar etc.
pub icon_data: Option<IconData>,

Expand All @@ -197,6 +200,7 @@ impl Default for NativeOptions {
maximized: false,
decorated: true,
drag_and_drop_support: false,
fullscreen: false,
icon_data: None,
initial_window_size: None,
resizable: true,
Expand Down Expand Up @@ -246,6 +250,16 @@ impl<'a> Frame<'a> {
self.0.output.quit = true;
}

/// Whether or not the window is being displayed in fullscreen mode
pub fn is_fullscreen(&self) -> bool {
self.0.output.fullscreen
}

/// Set fullscreen mode
pub fn set_fullscreen(&mut self, fullscreen: bool) {
self.0.output.fullscreen = fullscreen;
}

/// Set the desired inner size of the window (in egui points).
pub fn set_window_size(&mut self, size: egui::Vec2) {
self.0.output.window_size = Some(size);
Expand Down Expand Up @@ -502,6 +516,9 @@ pub mod backend {
/// This does nothing for web apps.
pub quit: bool,

/// Sets the window to fullscreen mode.
pub fullscreen: bool,

/// Set to some size to resize the outer window (e.g. glium window) to this size.
pub window_size: Option<egui::Vec2>,
}
Expand Down