Skip to content

New theme system #680

@takev

Description

@takev

I want widgets to be able to get theme values:

  • It needs to be fast as it is used inside the draw functions.
  • The theme needs to be able to change at runtime.
  • Use a sort of cascading style sheet for themes.
  • Have the hierarchy of widgets be like tags in HTML.
  • A developer can assign attributes to a widget using a string:
    • Add zero or one identifier names by prefixing with #
    • Add zero or more class names by prefixing with .
    • Add zero or more style-attributes using name=value.
  • The CSS theme file has a selector so that the style can change depending on the depth of a widget in the hierarchy.
    • There needs to be a way to reset the count, for example an overlay-widget resets the count
    • Maybe some widgets that are not visible need to be skipped when counting.

widget attribute syntax:

attribute: ( attribute ( ' ' attribute )* )?
selector: identifier | class | style
identifier: '#' [a-zA-Z-][a-zA-Z0-9-]
class: '.' [a-zA-Z-][a-zA-Z0-9-]
style: style-name '=' style-value
style-name: [a-zA-Z-][a-zA-Z0-9-]
style-value: style-size-value | style-color-value | style-string-value
class my_widget : public widget_intf {
   void draw(widget_draw_context const &content) noexcept {
        auto tmp1 = left_margin();
        auto tmp2 = background_color();
   }
};

class widget_intf {
    theme_context _theme_context;

    float left_margin() const noexcept {
       return (_theme_context.left_margin() * _dpi).numeric_value_in(pixel);
    }
};

struct detail::theme_attributes {
    std::string tag; // if .empty() then attribute is not in use.
    std::string id;
    std::vector<std::string> classes;
    attribute_flags left_margin_flags;
    theme_length left_margin;
};

std::vector<detail::theme_attributes> detail::theme_contexts;

class theme_context {
    uint32_t _id;
    ~theme_context() { detail::theme_contexts_delete_id(_id); }
    theme_context() : _id(detail::theme_contexts_new_id()) {}

   auto left_margin(pixel_density dpi) const noexcept {
      return convert_to_pixel(detail::theme_contexts[_id].left_margin, dpi);
   }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions