You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable implementation of various design languages within iced that can be used without having to call .style() on every widget or use pre-made widgets with styling pre-applied.
Allow developers using iced to select a design language at compile time
Enable users to change the theming of an app at runtime
Proposal
the iced_style::Styling trait
pubtraitStyling{typeTheme;}
This is bound as an associated type on an Application and dictates the default style sheets used for styling widgets as well as the Theme type that is passed as a parameter to the various stylesheet methods. Initially I had thought making the trait Theme with an associated type ColorPalette was the right way of going about it but realized that there's no reason why the struct passed to the various stylesheet methods should contain only color information - it could also contain things like button border radius etc. and allow users to completely change the look of the app at runtime.
Additionally, the Application trait (and others where required) would have a method to return an instance of the Theme type to be passed to styling methods:
/// Returns the theme used to render widgets according to the specified [`Styling`]fntheme(&self) -> <Self::StylingasStyling>::Theme{Default::default()}
The various StyleSheets then have use Theme as an associated type and their methods take a reference to the Theme as an argument:
/// A set of rules that dictate the style of a button.pubtraitStyleSheet{typeTheme;fnactive(&self,theme:&Self::Theme) -> Style;fnhovered(&self,theme:&Self::Theme) -> Style;fnpressed(&self,theme:&Self::Theme) -> Style;fndisabled(&self,theme:&Self::Theme) -> Style;}
Any widgets then specify that the Renderer's styling implements its own StyleSheet trait:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Goals
.style()
on every widget or use pre-made widgets with styling pre-applied.Proposal
the
iced_style::Styling
traitThis is bound as an associated type on an
Application
and dictates the default style sheets used for styling widgets as well as theTheme
type that is passed as a parameter to the various stylesheet methods. Initially I had thought making the traitTheme
with an associated typeColorPalette
was the right way of going about it but realized that there's no reason why the struct passed to the various stylesheet methods should contain only color information - it could also contain things like button border radius etc. and allow users to completely change the look of the app at runtime.Additionally, the
Application
trait (and others where required) would have a method to return an instance of theTheme
type to be passed to styling methods:The various
StyleSheet
s then have useTheme
as an associated type and their methods take a reference to theTheme
as an argument:Any widgets then specify that the
Renderer
's styling implements its ownStyleSheet
trait:so that their
Widget::draw()
implementation can take theStyling::Theme
as a parameter to pass along to the style sheet methods:You can find a WIP implementation in my branch or in my draft PR
Beta Was this translation helpful? Give feedback.
All reactions