跳转至

ui/core/material/cfmaterial_scheme.cpp

Material Design 3 Color Scheme implementation. More...

Namespaces

Name
cf
cf::ui
cf::ui::core

Detailed Description

Material Design 3 Color Scheme implementation.

Author: Charliechen114514 (chengh1922@mails.jlu.edu.cn)

Version: 0.1

Date: 2026-02-25

Copyright: Copyright © 2026

Source code

#include "cfmaterial_scheme.h"

namespace cf::ui::core {

MaterialColorScheme::MaterialColorScheme() {
    color_cache_.reserve(32);
}

QColor& MaterialColorScheme::queryExpectedColor(const char* name) {
    auto it = color_cache_.find(name);
    if (it != color_cache_.end()) {
        return it->second;
    }

    auto result = registry_.get_dynamic<CFColor>(name);
    if (result && *result) {
        auto [iter, inserted] = color_cache_.emplace(name, (*result)->native_color());
        return iter->second;
    }

    // Fallback color
    static QColor fallback(Qt::black);
    return fallback;
}

QColor MaterialColorScheme::queryColor(const char* name) const {
    auto it = color_cache_.find(name);
    if (it != color_cache_.end()) {
        return it->second;
    }

    auto result = registry_.get_dynamic_const<CFColor>(name);
    if (result && *result) {
        return (*result)->native_color();
    }

    return QColor(Qt::black);
}

} // namespace cf::ui::core

Updated on 2026-03-09 at 10:14:01 +0000