-
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
Conversation
Thanks for the PR. I'm just wondering if an enum is really appropriate vs 3 boolean to hide specific buttons. Would it not be simpler? |
@ogoffart You mean something like this? I didn't think of booleans, I think this look better than my implementation. let min = false;
let max = false;
let close = true;
app.window().set_window_buttons(min, max, close); |
No, I meant something like A function with 3 boolean is quite confusing because people will write Another possibility: There is also the choice to take she same API as winit with Flags. I think your choice with an enum with 8 state is not that bad if there is only 3 buttons, but we have to think about extensibility. What if we want to add another button in the future without breaking the API? There is some WM with extra button. (Help, Menu, ...) So I don't know exactly which API is the best that combine simplicity and extensibility. Perhaps the winit API with flags is the nicest. But flags in rust are a bit awkward to do. |
Shouldn't these be component properties? export component AppWindow inherits Window {
has-minimize-button: false;
has-maximize-button: false;
has-close-button: false;
}
Why should you have to do this in the backend language? |
@ogoffart I have updated the implementation: app.window().set_window_button_enabled(WindowButton::Minimize, true);
app.window().set_window_button_enabled(WindowButton::Maximize, true);
app.window().set_window_button_enabled(WindowButton::Close, true); I am not sure that would fall in line with the current structure of the library, as you cannot make the window maximized from slint either, so this follows the current implementation of how setting a window to app.window().set_maximized(true); |
It's about what the user should be allowed to do! This is similar to the initial-size and resizing topic: You use Slint properties to define whether the user should be allowed to resize the window. (Docs: "Setting the width will result in a fixed width... The initial width can be controlled with the preferred-width property.") You can't compare something like Do you want to disable the minimize- and maximize-button for the |
It is not always easy to figure out if this should be part of the native API vs. what should be part of the slint code API. |
Please "Avoid Negative...Names". I also recommended this regarding the existing
I don't think there's a problem defining According to GPT-4o, dialogs with hidden minimize- and maximize-button are more common and |
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.
Sorry to take so long to react to your PR.
It may seem picky, but we really should try hard to get the right API and naming, and this is something that can take several iteration.
Thank you so much for contributing. I think the feature is valuable. And the implementation looks good.
I've added some comments especially regarding naming.
We should use consistently either something like "visible" or "enabled" for these buttons. Winit uses "enabled", but I wonder if these shouldn't be "visible" instead. I'm a bit unsure about that.
(Also, the implementation in the Qt backend is missing. That can be done with QWidget::setWindowFlags. But this can be done in a followup)
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
should we consider marking this struct as #[non_exhaustive]
?
Naming-wise, i believe the struct should probably be called WindowButtonVisibility
as it is about the visibility of these buttons rather than their state. Or the value should say minimize_button_visible
or has_minimize_button
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why set all buttons here?
|
||
/// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is it maybe visibility
rather than enabled
- **`no-minimize-button`** (_in_ _bool_): Whether the window should have a minimize button in the title bar. Default is `false` to show the minimize button. | ||
- **`no-maximize-button`** (_in_ _bool_): Whether the window should have a maximize button in the title bar. Default is `false` to show the maximize button. | ||
- **`no-close-button`** (_in_ _bool_): Whether the window should have a close button in the title bar. Default is `false` to show the close button. |
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
or maximize-button-visible
or maximize-button-enabled
(and default to true which can be done in the builtins.slint)
Note that this is already inconsistent under Windows. StackOverflow:
In contrast, other styles like But I don't know whether winit even uses a window class per window at all, or reuses OS-level window classes. ( |
fixes #6669
Adds three types of window button styles naming was taken from here.
There are a few winit restrictions.
Usage
Output
Full
Close
None
Note: On windows the
x
is still there just not clickable (not sure about on a different OS)MinimizeMaximize