-
Notifications
You must be signed in to change notification settings - Fork 19
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
Theming #6
Conversation
Would it be possible to change the theme on-demand, such as if the theme is loaded from a configuration file? |
@mmstick Yes. You could load your theme in |
Would this just be at application init? Is there any interest in having included helper functions to manage theme? Both in the
i think no, it would be nice to have auto-detect for system light/dark mode (but not necessary).
I think the light/dark themes from the styling example are more than good enough for now 😄 I don't think in practice it would matter much, but currently the subscription function is run after update and before view, if I'm not mistaken? So would the order now be update->subscription->theme->view ? Thank you for putting so much thought into this, looks great! ❤️ |
No. Ideally we should build this on top of a proper OS abstraction that can listen to configuration changes.
Ideally, we will eventually detect many OS settings (including different Linux DEs) in order to choose / change the active The plan here is to introduce the foundations for allowing users to implement these features themselves as well as exposing them in a nice way! For instance, you could open-source a theming crate that exposes a new Then, in the long run,
The dark theme there is mostly a copycat of the Discord color palette. Maybe we could change the background color a bit... We should also probably discuss the different built-in variants that we want to have available for every widget.
Yeah, good point. I'm leaning towards that as well.
The ordering is irrelevant. If you are worried about
Glad you like it! |
@hecrj
Oh no I wasn't worried about propagation issues, just mostly to have an answer when people ask on the discord 😄 |
I think a reasonable starting point would be:
A future table widget could be rather complicated though, i would see all of those + alternating rows/columns + header column + divider, etc, but we don't have a table widget yet, so those details can wait |
@13r0ck Variants are not the possible states of a widget, but actually styling variations of the whole widget. For instance a |
Oh 🤦 Um, I think gnome theming uses Potentially another Maybe containers should have a similar set of themes, beyond that I think most widgets will just have their states. |
First off, love love LOVE the variant stuff! I'm kinda confused as to how color schemes play into this though - the unresolved questions/future possibilities sections seem to imply that color scheme stuff would be related to variants? IMO, they should be separate. Here's how I envision it to allow on the fly color scheme swapping goodness:
|
@emann I believe my |
@hecrj Surely that would create some redundancy then, no? If I want the widgets to all look the exact same in light mode and dark mode with the only difference being that dark mode uses black instead of white and say purple instead of a bright green, wouldn't that require some code duplication? Perhaps different vocabulary may make my thinking clearer - I see the TLDR; I feel tightly coupling the way things are shaped/styled with the colors applied to them will cause a lot of duplication and potentially introduce some annoyance. |
I don't see why. You can create any internal abstractions to manage your supported color schemes. For instance, you could have: pub enum Theme {
Light,
Dark,
}
struct Palette {
base: Color,
text: Color,
// ...
}
impl Theme {
fn palette(&self) -> Palette {
// ...
}
}
impl button::StyleSheet for Theme {
type Variant = /* ... */;
fn active(&self, variant: Self::Variant) -> button::Style {
let palette = self.palette();
// ...
}
}
|
@hecrj Damn. Couldn't agree more when you put it that way haha. I do however think that maybe there could be some basic implementation of "A theme which has switchable color palettes" somewhere, along with things like a theme that automatically detects light vs dark mode and selects the appropriate color scheme. Presumably this stuff would live in a separate crate altogether ( |
Also I think my second pass at implementing this stuff is fairly similar to what you described here, would love to help out with/lead aligning it with the RFC! |
@emann No worries. Code is the easy part! I already have a working implementation of the ideas presented here. |
Really exited to see this coming in iced! As far as I understand you are not planning to tight theming to a specific configuration format and will leave the implementation to end users for now, which is fine I guess. However reading at the rfc I am wondering if it would be possible to add some kind of css like selectors to widgets so we can override the theme in use for specific widget and define new styles that wouldn't be tight to any application code. MotivationThe current rfc allow to change the global style of an application by defining a theme and introduce an associated type to add variants to a theme for a specific widget. But the example suggest that we would still need to hard code this variant associated types in our theme implementation :
This is definitely an improvement but ultimately, end user should be able to completely change the style of an iced application without having to write any application code (at least if the application chose to expose a theme configuration file). A possible solution would be to introduce css like selectors. Note that I am not suggesting css should be used here, only that widget should bind to a selector name in the theme definition. ExampleLet's consider the following widget definition, and assume that I have implemented binding to a css like configuration file for the theme in use : Container::new(Column::new()
.push(search_bar)
.push(scrollable)) First I would like to be able to use default selectors for iceds widgets : container column {
alignment: start;
width: fill;
padding: 20
} And to use my own css like class selectors : Container::new(Column::new()
.push(search_bar)
.push(scrollable)
.class("centered")) container column.centered {
alignment: center;
width: fill;
padding: 10
} Do you think the current rfc once implemented could be extended to this ? |
I don't see why. I don't think Also, I really don't like the idea of cascading styles with selectors. I believe widgets should be explicitly styled in view logic, instead of implicitly by some separate rules and its context. Finally, styling will never affect layout. This means that a |
Would it be possible to make a castom StyleSheet for a Button? without changing the styles of other widgets. There is an idea to add a castom variant of the boxed StyleSheet for all widgets in the standard theme. |
- Rename `Variant` to `Style` in a `StyleSheet` - Introduce `Custom` variant to built-in `Theme` - Explain `Palette` type - Add section about extending the built-in themes - Clarify `Sandbox` changes
I have updated the RFC to reflect some of the decisions taken here and the latest explorations from my part. I think we are very close to getting this merged. Let me know what you think! |
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.
Looks good to me! 🎉
This proposal introduces the first-class concept of a theme in iced. A theme is defined as some data type capable of changing the default look of the widgets of an application.
Rendered