lapce / floem

A native Rust UI library with fine-grained reactivity
https://docs.rs/floem
MIT License
2.57k stars 117 forks source link

stylesheets / themes #133

Open gitmalong opened 8 months ago

gitmalong commented 8 months ago

Hi!

As a lazy dev I would like to slap a kind of stylesheet to my UI to get started with a beautiful UI. Is that something that should be handled by third party component libs?

pieterdd commented 6 months ago

Are you perhaps looking for a UI component library?

I'm in the process of setting one up for Floem: https://github.com/pieterdd/prettygooey/tree/floem-rewrite Note that this is an unfinished development branch.

golota60 commented 6 months ago

Hey, I've just published a library named oxytail also implementing a couple of styled widgets if you're interested.

pieterdd commented 6 months ago

Happy to see more choices pop up! I didn't expect the floem-themes topic to welcome its first entry so quickly after it was added to the docs 😄

ArcExp commented 6 months ago

are sylesheets the only way to apply a dark theme/dark mode to a floem app? trying to figure out how floem works in this regard, for an app I'm working on

jrmoulton commented 6 months ago

@ArcExp

I've ended up building something custom to handle light/dark mode

https://github.com/jrmoulton/floem-component/blob/96fac259133b9450c15294e035e594a70e79d6df/src/style.rs#L290C1-L337C1

The way this works is I have an RwSignal<DarkMode> (DarkMode is a type alias for bool) that I initialize at the start of my program with provide_context.

Then for all my colors I use this LightDark struct. in order to get thepeniko::Color out of it I call .color(). Calling .color will use the global DarkMode bool to determine if the LightDark should return the light or dark field. Since this uses a signal it will automatically be reactive when used in any styles.

view().style(|s| s.background(LightDark.color())//  <-- Automatic light/dark mode
ArcExp commented 6 months ago

Thanks! I'll be using that in my app

jrmoulton commented 6 months ago

Cool! You might consider just copy/paste that entire file and use the parts that you want. That repo is full of experiments that I don't necessarily maintain.

ArcExp commented 6 months ago

Will do :)