-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Application-wide Theming Set/Changed at Runtime #1277
Application-wide Theming Set/Changed at Runtime #1277
Conversation
@hecrj marking as a draft as there are still some ToDo items (see below) but wanted to see if you had any input/requests in the meantime. ToDo
|
I'm not sure this is the right approach. Instead of listing the For instance, something like: pub struct Theme {
pub base: Color,
pub action: Color,
pub text: Color,
pub positive: Color,
pub negative: Color,
// and more...
} Then, all of the widgets can use the colors of this Before we write any code, the first step would be deciding the different fields of this |
@hecrj I love the idea of a color palette but we also need to be able to specify widget-specific styling e.g. button border radius, slider handle shape, etc. How should we go about doing so? Adding fields to the |
this looks familiar :-D |
Closing since the RFC efforts have landed with #1362. Thank you for starting all of it! 😁 |
A precursor for #1022. Allows users to create entirely custom themes that can be set/updated during runtime.
Implementation Details
renderer::Style
was already passed around toWidget::draw()
calls so I just added fields to the struct to store aBox<dyn a_widget::StyleSheet + 'static>
for each widget.fn styling(&self) -> renderer::Style
toSandbox
,Application
, and a few other places where needed which allows the user to dynamically select which style to use. A default implementation is provided that returns what were previously hardcoded values for the current default style of an iced application.Widget::draw()
implementations for widgets that allow custom styling have been updated to fall back on therenderer::Style
's style sheet if no custom styling was specifiedstyle_sheet: Box<dyn StyleSheet + 'a>
field for said structs has been changed tocustom_style_sheet: Option<Box<dyn StyleSheet + 'a>>
StyleSheet
traits that take some state data (e.g.is_mouse_over
,) and return the style that should be used. The default implementation of these methods operate identically to the implementations that were previously in thedraw()
methods (delegating to one of the other style sheet's methods which return amy_widget::Style
e.g.hovered()
,active()
, etc.) but both clean up the code in thedraw()
methods and allow for greater flexibility when creating custom themes.Example
The
application_theme
example project