Skip to content

Light/dark theming #676

@Alex2772

Description

@Alex2772

A solution is needed for light/dark theming. It's probably depends on #572.

API sketch

namespace aui::theme {


// 1. enum
enum class Theme { // i don't like this name, just for sake of demo
  LIGHT,
  DARK,
  HIGH_CONTRAST, // etc...
};

// 2. this reflects setting in OS settings
// Windows: Settings -> System -> Theme -> Dark/light
// Linux: depends on DE
const AProperty<Theme>& systemPreference();

// 3. main observable for theme value
//
// this is up to be defined by AUI-based application.
// by default, we'll return light theme because the application
// developer might not know/care about light/dark themes.
//
// if they want, they'll override application preference to
//
//  appPreference = [] { return *aui::theme::systemPreference(); }
//
// or, if they want to introduce their application-specific setting,
//
// appPreference = [] {
//   // assuming AProperty<AOptional<Theme>> theme
//   if (MyAppSettings::theme->hasValue()) {
//     return MyAppSettings::theme->value();
//  }
//  return *systemPreference();
// }
APropertyPrecomputed<Theme> appPreference = [] { return Theme::LIGHT; }
//
// this value should be observed in entire application. If AUI can adjust system UI elements
// (i.e., titlebars #675), appPreference will affect them too.
}


// 4. Assuming #572 is resolved (at least partially)
// AUI_OVERRIDE_STYLE implicitly subscribes for aui::theme::appPreference changes
static _<AView> myThemeAwareButton() {
  return Button { ... } AUI_OVERRIDE_STYLE {
    BackgroundSolid(aui::theme::appPreference == Theme::LIGHT ? AColor::WHITE : AColor::BLACK),
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedThis issue hard depends on another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions