-
Notifications
You must be signed in to change notification settings - Fork 604
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
Window Button Styles #6675
base: master
Are you sure you want to change the base?
Window Button Styles #6675
Changes from all commits
d2e4f06
7b9b57b
99d8cda
a45ad8e
6467fb3
6909d43
609bae2
6525654
65cbdbc
feac7dc
0bca313
02f2943
4286819
9710748
67cc10d
9a818a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ use core::pin::Pin; | |
use std::rc::Rc; | ||
use std::rc::Weak; | ||
|
||
use i_slint_core::window::WindowButtonState; | ||
#[cfg(target_arch = "wasm32")] | ||
use winit::platform::web::WindowExtWebSys; | ||
#[cfg(target_family = "windows")] | ||
|
@@ -39,7 +40,7 @@ use i_slint_core::{self as corelib, OpenGLAPI}; | |
use once_cell::unsync::OnceCell; | ||
#[cfg(enable_accesskit)] | ||
use winit::event_loop::EventLoopProxy; | ||
use winit::window::WindowAttributes; | ||
use winit::window::{WindowAttributes, WindowButtons}; | ||
|
||
fn position_to_winit(pos: &corelib::api::WindowPosition) -> winit::dpi::Position { | ||
match pos { | ||
|
@@ -195,6 +196,27 @@ impl WinitWindowOrNone { | |
} | ||
} | ||
|
||
fn set_window_buttons_state(&self, window_buttons_state: WindowButtonState) { | ||
match self { | ||
Self::HasWindow(window) => { | ||
let mut enabled_buttons = WindowButtons::empty(); | ||
if !window_buttons_state.minimize { | ||
enabled_buttons |= WindowButtons::MINIMIZE; | ||
} | ||
if !window_buttons_state.maximize { | ||
enabled_buttons |= WindowButtons::MAXIMIZE; | ||
} | ||
if !window_buttons_state.close { | ||
enabled_buttons |= WindowButtons::CLOSE; | ||
} | ||
window.set_enabled_buttons(enabled_buttons); | ||
} | ||
Self::None(attributes) => { | ||
attributes.borrow_mut().enabled_buttons = WindowButtons::all() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why set all buttons here? |
||
} | ||
} | ||
} | ||
|
||
fn set_minimized(&self, minimized: bool) { | ||
match self { | ||
Self::HasWindow(window) => window.set_minimized(minimized), | ||
|
@@ -764,6 +786,13 @@ impl WindowAdapter for WinitWindowAdapter { | |
winit_window_or_none.set_window_level(new_window_level); | ||
} | ||
|
||
// Get the associated window button states | ||
let mut win_props = properties.window_buttons_enabled(); | ||
win_props.close = window_item.no_close_button(); | ||
win_props.minimize = window_item.no_minimize_button(); | ||
win_props.maximize = window_item.no_maximize_button(); | ||
winit_window_or_none.set_window_buttons_state(win_props); | ||
|
||
// Use our scale factor instead of winit's logical size to take a scale factor override into account. | ||
let sf = self.window().scale_factor(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,12 @@ impl<'a> WindowProperties<'a> { | |
pub fn is_minimized(&self) -> bool { | ||
self.0.minimized.get() | ||
} | ||
|
||
/// The widow style | ||
/// Returns a tuple of three booleans: (minimize, maximize, close) | ||
pub fn window_buttons_enabled(&self) -> WindowButtonState { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it maybe |
||
self.0.window_button_state.get() | ||
} | ||
} | ||
|
||
struct WindowPropertiesTracker { | ||
|
@@ -407,6 +413,17 @@ struct WindowPinnedFields { | |
text_input_focused: Property<bool>, | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
/// The state of each window button | ||
pub struct WindowButtonState { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we consider marking this struct as Naming-wise, i believe the struct should probably be called |
||
/// The minimize button state | ||
pub minimize: bool, | ||
/// The maximize button state | ||
pub maximize: bool, | ||
/// The close button state | ||
pub close: bool, | ||
} | ||
|
||
/// Inner datastructure for the [`crate::api::Window`] | ||
pub struct WindowInner { | ||
window_adapter_weak: Weak<dyn WindowAdapter>, | ||
|
@@ -431,6 +448,7 @@ pub struct WindowInner { | |
fullscreen: Cell<bool>, | ||
maximized: Cell<bool>, | ||
minimized: Cell<bool>, | ||
window_button_state: Cell<WindowButtonState>, | ||
|
||
/// Stack of currently active popups | ||
active_popups: RefCell<Vec<PopupWindow>>, | ||
|
@@ -491,6 +509,11 @@ impl WindowInner { | |
fullscreen: Cell::new(false), | ||
maximized: Cell::new(false), | ||
minimized: Cell::new(false), | ||
window_button_state: Cell::new(WindowButtonState { | ||
minimize: true, | ||
maximize: true, | ||
close: true, | ||
}), | ||
focus_item: Default::default(), | ||
last_ime_text: Default::default(), | ||
cursor_blinker: Default::default(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Enyium has a point. It probably should be
has-maximize-button
ormaximize-button-visible
ormaximize-button-enabled
(and default to true which can be done in the builtins.slint)