How to apply a style to a container #1266
-
I've been puzzling about this for two days now, so let me ask: I know it is possible to apply styles like background colors and frames to containers. I can see that it works in the sample projects, but... ...how does it work? I've been trying to make sense of if, but no matter what I try, all I get is error messages. For an example, let us consider this case: I have an iced Element. I want to put it in a colored box, somewhat like this:
That doesn't work because of this error:
I've tried to figure out how this works for two days now, looking at the sample projects, but wasn't able to figure it out. Can someone please explain to me how this is supposed to work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The error is saying you haven’t implemented ‘style’ correctly. Implementing a style has quite some boiler plate. or if the light/dark is confusing here is an example from a personal project Basically your style needs to implement ‘From’ for each widget you want to put it on, then that let’s rust “find” the right value for each widget, which you then you can implement the style sheet for each widget https://github.com/13r0ck/bathtub/blob/main/src/style.rs#L125 |
Beta Was this translation helpful? Give feedback.
The error is saying you haven’t implemented ‘style’ correctly.
Implementing a style has quite some boiler plate.
https://github.com/iced-rs/iced/blob/master/examples/styling/src/main.rs#L157
or if the light/dark is confusing here is an example from a personal project
https://github.com/13r0ck/bathtub/blob/main/src/style.rs
Basically your style needs to implement ‘From’ for each widget you want to put it on, then that let’s rust “find” the right value for each widget, which you then you can implement the style sheet for each widget
https://github.com/13r0ck/bathtub/blob/main/src/style.rs#L125