Replies: 1 comment 2 replies
-
Have you tried |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I see in the official demo of
libadwaita
a "theme switch" button (switching between light and dark variant) which I presume involves callingStyleMan::set_color_scheme
upon clicked. I tried to replicate this behaviour using therelm4::widget
macro, and had some problems.I first tried to implement this manually (i.e., without the
widget
macro). I include atheme_variant
field in myModel
, and save a copy of theStyleManager
as astyle_man
field, so ininit_view
:and also keep a copy of the theme switch button:
and for completeness, here's the definition of the
ThemeVariant
enum:(collapsed by default to save space)
I then handle the
Msg::FlipTheme
message in theupdate
function. So far so good.However, if I use the
widget
macro, I have no where to put thestyle_man
field. I can include that in theadditional_fields! { ... }
part, but it seems I would have to write the init/update logic manually, which clutters the implementation. Is there anything I missed here? I thought of putting thestyle_man
in the model, but it requires being initialised from aDisplay
, which I presume it is not a good idea to happen beforeRelmApp::run
. I also thought of implementing the theme switch button as a standalone component (thus perhaps factor out the unidiomatic part), but I am not sure how much that would help in general.P.S. It would be great if initialisation and
track!(...)
expressions were allowed inadditional_fields! { ... }
.Edit: I managed to factor out the "theme switch" button into a component, and the code indeed looked better. However, I still want to hear someone else's opinion on this topic: generally how should we handle stateful elements outside the widget tree?
Beta Was this translation helpful? Give feedback.
All reactions