pop-os / libcosmic

WIP library for COSMIC applications
https://pop-os.github.io/libcosmic/cosmic/
Mozilla Public License 2.0
460 stars 44 forks source link

`cosmic::theme::Button` doesn't provide a way to due fully custom theming per button #94

Open ids1024 opened 1 year ago

ids1024 commented 1 year ago

Prototyping an Iced version of the keyboard view for the Configurator, it's necessary to set the background color for each key to a certain RGB value. But cosmic::theme::Button::Custom uses fn(_: &Theme) -> Appearance, so it can't just be passed an Appearance, or a closure that captures the color for the button.

Not sure how to best do this:

This is perhaps a limitation of Iced's theming system, since as far as I'm aware it doesn't provide a way to completely override the theme for specialized elements other than with a custom widget.

mmstick commented 1 year ago

You can make a static function for each color variant. May need a helper function for creating a custom variant in this way, as some other widgets currently have to make it easier to define.

ids1024 commented 1 year ago

As currently implemented the colors are specified as RGB values per-key per-keyboard (to match the look of keyboards like Launch). In json files.

mmstick commented 1 year ago

Then yeah, there are some widgets already using a Box so it would make sense to opt for that for increased flexibility

ids1024 commented 1 year ago

Hm. Currently all of these types in cosmic::theme are Clone + Copy. A boxed trait can be neither. Most Iced widgets don't require their style types to be clonable, but the iced_style::text::StyleSheet::Style requires Style: Default + Copy.

Arc<dyn Fn()> or Rc<dyn Fn()> would be Clone but not Copy.

Having to use boxing here (every time view is called), or reference counting, doesn't seem ideal. Though the overhead is probably not really significant...

FreeFull commented 7 months ago

If the Color itself is Copy, then you can just use a move closure to avoid capturing a reference to it.