-
-
Notifications
You must be signed in to change notification settings - Fork 98
feat: Per-component themes #425
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
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #425 +/- ##
==========================================
+ Coverage 52.47% 52.63% +0.15%
==========================================
Files 145 146 +1
Lines 12847 12808 -39
==========================================
Hits 6742 6742
+ Misses 6105 6066 -39 ☔ View full report in Codecov by Sentry. |
|
There might be a bit of a problem with moving the themes to the component files... It's impossible because |
Heh, that explains why the themes are in the hooks crate. I would leave them in the hooks crate for now, maybe they can be moved to their own crate at some point in the future |
- Themes had duplicated docs in the form of "Theming properties for the `Foo` component." This commit introduces an attribute `%[component]` that will automatically generate those docs.
- The `Theme` suffix has been removed. Now to define a theme, it's enough to do just `pub Button {` and everything else is handled.
- The "attributes" have a new style: `%[attr_name]`. This replaces the old `..cows..` separators and such with `%[cows]`. It's impossible to make it the standard syntax of `#[attr_name]` because that is ambiguous. However, it is much closer
This changes the lifetime of `Cow`s from `'a` to `'static`. This removes lifetimes in certain places and is more efficient. Dynamic props still work, because a `String` can be converted to `Cow<'static, str>`. The more you know!
|
That was painful, but it's done! All layout props were moved to the themes. All examples have been updated. Please mark this as breaking though. |
|
I added an example in I also tried to update the book, but I probably didn't cover everything. As a side note, please check out #427. I tested the book to see any errors, but there was way too many of them and I couldn't be bothered to look through them to find out which ones are affected by this PR. #427 is basically a request to fix all the errors. |
|
Ready for review, but it's breaking, because layout stuff has been moved to themes. |
Closes #423
Example:
Or with the
theme_withmacro:This will only change the
backgroundandcolorof the button. Nothing else is affected. Subthemes are supported (e.g.,FontThemeWith).Internals
Example of defining a theme:
%[component]attribute will automatically generate docs that point to the component of the theme's name.The following attributes are all field "separators". This means that you specify them only once per theme, and they will apply to all following fields until they encounter another separator. These must be in the same order, but you don't need to use all of them.
%[cows]indicates that the next fields should be wrapped inCow<'static, _>. This is more specific than the others, but it's an extremely common use case, because strings should always be wrapped inCowto allow constant theme templates, but also dynamic theme overrides.%[borrowed]indicates that the next fields are borrowed data and should therefore be handled as such (this matters in theapply_optionalfunction that the macro generates).%[owned]indicates that the next fields are owned data and should therefore be handled as such (this matters in theapply_optionalfunction that the macro generates).%[subthemes]indicates that the next fields are other themes and should therefore be handled as such (this matters in theapply_optionalfunction that the macro generates).Example of using a theme (in
freya-componentscrate):Notes
This can be merged, but there is a couple things left to do that are relevant:
themeproperty definition, thelet theme = ...statement, and the/// This inherits [FooTheme](freya_hooks::FooTheme)doc. It was extremely annoying adding all of these...Default::defaultandSome). Update: seetheme_withmacro.- Move theme defs to component files.This is getting put on hold for now, since there's some cyclic dependency issues. However, in the future, it would indeed be good to move the themes somewhere else thanfreya-hooks.