Skip to content

Proposal: Styling capabilities for the std-widgets  #5392

Open
@FloVanGH

Description

@FloVanGH

While it is already possible to do custom styling with Slint by doing custom widget development like [SurrealismUI] (https://github.com/Surrealism-All/SurrealismUI) and coop a highly requested features is to do change style settings on the Slint's std-widgets like background, border-color and font-size. The profit for developers is that they have something to start with and they don't need to start from scratch. Connected to this features I see some question that we should also keep in mind to help developers by doing custom styling base on the std widgets:

  • How can we help developers to keep consistency in their styling if they want to styling that should fit in one dedicated style e.g. fluent
  • How can we help developers to keep consistency in their styling if they want to styling that should fit in all styles

What I have in mind to solve this questions it to provide design / styling guidelines and best practices. I think this could follow as seconds step after custom styling is done.

Before going in to details of this proposal I want to say about the possibility to create custom widgets that matches e.g. the colors settings of one of the provides Slint styles like fluent or material. There is already a global with that settings called Palette there will be soon a more complex example that displays how to work with it called TodoMVC, more details soon ;-).

I see there two different ways to implement this feature:

Base widgets

First one is to provide the developers a set of all std widgets as base with no predefined styling. Benefit of this is, the developer / designer is completely free, could do easily a complete custom design for the std widgets without the need to start from scratch. So it would be possible to use base widgets with predefined layout, content and behavior. Disadvantage of this is that for support all std-widget it is necessary to do styling for all std widgets:

Example

import { MyFancyPalette } from "my-fancy-styling.slint";
import { ButtonBase } from "std-widgets.slint";

export component MyFancyButton inherits ButtonBase {
    // do the styling here
}

Add styling to the current std-widget

Other approach is to add styling properties to the current std-widgets. Profit is the developer / designer don't need to start from scratch and don't need to do styling for all widgets. Disadvantage is if it should work with all styles it needs to ensured that colors e.g. that are set works with all styles. It is harder to ensure consistency with the style.

For styling in common we should keep in mind that wee need to provide this also for the different states of a widget. E.g. it's not enough to just change the background. Depending on the style there are different background brushes depending on the state e.g. a background-hover and a background-pressed.

I see there two way to add styling properties to the widgets:

Add properties directly to the widgets

I see there one disadvantage this will bloat the api of a widget a lot with properties.

import { MyFancyPalette } from "my-fancy-styling.slint";
import { Button } from "std-widgets.slint";

export component MyFancyButton inherits Button {
     background: MyFancyPalette.control-background;
     background-pressed: MyFancyPalette.control-background-pressed;
     background-hover: MyFancyPalette.control-background-hover;
}

Add a style property to each widget (style as struct)

Disadvantage right now is that it is not possible to overwrite single field of a struct. So all field that are not set will be set to default values check #5201. Profit is it give the style a clean structure. There is one extra property per widget. Styles can be also stored in a global.

import { MyFancyPalette } from "my-fancy-styling.slint";
import { Button } from "std-widgets.slint";

export component MyFancyButton inherits Button {
     style: {
          background: MyFancyPalette.control-background;
          background-pressed: MyFancyPalette.control-background-pressed;
          background-hover: MyFancyPalette.control-background-hover;
     }
}

I hope that gives people that are requesting styling features for std widgets some answers and a way how we can solve this. So I'm open for feedback and I hope that is something we can put on the agenda for the near future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:widgetsImplementation of widgets (from std-widgets.slint) and their styles (mF,bS)rfcRequest for comments: proposals for changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions