跳转至

ui/core/material/material_factory.hpp

Material Design 3 Color Scheme Factory Functions. More...

Namespaces

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

Classes

Name
struct cf::ui::core::material::MaterialSchemeError
Error type for material scheme operations.

Detailed Description

Material Design 3 Color Scheme Factory Functions.

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

Version: 0.1

Date: 2026-02-25

Copyright: Copyright © 2026

Source code

#pragma once

#include <QByteArray>

#include "../../export.h"
#include "base/expected/expected.hpp"
#include "cfmaterial_fonttype.h"
#include "cfmaterial_motion.h"
#include "cfmaterial_radius_scale.h"
#include "cfmaterial_scheme.h"

namespace cf::ui::core::material {

// =============================================================================
// Error Types
// =============================================================================

struct MaterialSchemeError {
    enum class Kind {
        InvalidJson,        
        MissingColor,       
        InvalidColorFormat, 
        GenerationFailed    
    } kind = Kind::InvalidJson;

    std::string message;

    MaterialSchemeError() = default;

    MaterialSchemeError(Kind k, std::string msg) : kind(k), message(std::move(msg)) {}
};

using Result = cf::expected<MaterialColorScheme, MaterialSchemeError>;

// =============================================================================
// Factory Functions
// =============================================================================

CF_UI_EXPORT MaterialColorScheme light();

CF_UI_EXPORT MaterialColorScheme dark();

CF_UI_EXPORT Result fromJson(const QByteArray& json, bool isDark = false);

CF_UI_EXPORT MaterialColorScheme fromKeyColor(cf::ui::base::CFColor keyColor, bool isDark = false);

CF_UI_EXPORT QByteArray toJson(const MaterialColorScheme& scheme);

// =============================================================================
// Typography Factory Functions
// =============================================================================

CF_UI_EXPORT MaterialTypography defaultTypography();

// =============================================================================
// Radius Scale Factory Functions
// =============================================================================

CF_UI_EXPORT MaterialRadiusScale defaultRadiusScale();

// =============================================================================
// Motion Factory Functions
// =============================================================================

CF_UI_EXPORT MaterialMotionScheme motion();

} // namespace cf::ui::core::material

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