跳转至

ui/widget/material/widget/label/label.h

Material Design 3 Label widget. More...

Namespaces

Name
cf
cf::ui
cf::ui::widget
cf::ui::widget::material

Classes

Name
class cf::ui::widget::material::Label
Material Design 3 Label widget.

Detailed Description

Material Design 3 Label widget.

Author: CFDesktop Team

Version: 0.1

Since: 0.1

Date: 2026-03-01

Implements Material Design 3 label with support for multiple typography styles (Display, Headline, Title, Body, Label), color variants (OnSurface, OnSurfaceVariant, Primary, Secondary, etc.), and theme integration.

Source code

#pragma once

#include "base/color.h"
#include "base/include/base/weak_ptr/weak_ptr.h"
#include "export.h"

#include <QLabel>
#include <QWidget>

namespace cf::ui::widget::material {

using CFColor = cf::ui::base::CFColor;

enum class TypographyStyle {
    // Display styles (57sp, 45sp, 36sp) - for hero content
    DisplayLarge,
    DisplayMedium,
    DisplaySmall,

    // Headline styles (32sp, 28sp, 24sp) - for app bar text
    HeadlineLarge,
    HeadlineMedium,
    HeadlineSmall,

    // Title styles (22sp, 16sp, 14sp) - for section headings
    TitleLarge,
    TitleMedium,
    TitleSmall,

    // Body styles (16sp, 14sp, 12sp) - for main content
    BodyLarge,
    BodyMedium,
    BodySmall,

    // Label styles (14sp, 12sp, 11sp) - for secondary info
    LabelLarge,
    LabelMedium,
    LabelSmall
};

enum class LabelColorVariant {
    OnSurface,        
    OnSurfaceVariant, 
    Primary,          
    OnPrimary,        
    Secondary,        
    OnSecondary,      
    Error,            
    OnError,          
    InverseSurface,   
    InverseOnSurface  
};

class CF_UI_EXPORT Label : public QLabel {
    Q_OBJECT
    Q_PROPERTY(TypographyStyle typographyStyle READ typographyStyle WRITE setTypographyStyle)
    Q_PROPERTY(LabelColorVariant colorVariant READ colorVariant WRITE setColorVariant)
    Q_PROPERTY(bool autoHiding READ autoHiding WRITE setAutoHiding)

  public:
    explicit Label(const QString& text = QString(),
                   TypographyStyle style = TypographyStyle::BodyMedium, QWidget* parent = nullptr);

    ~Label() override;

    TypographyStyle typographyStyle() const;

    void setTypographyStyle(TypographyStyle style);

    LabelColorVariant colorVariant() const;

    void setColorVariant(LabelColorVariant variant);

    bool autoHiding() const;

    void setAutoHiding(bool enabled);

    QSize sizeHint() const override;

    QSize minimumSizeHint() const override;

  protected:
    void paintEvent(QPaintEvent* event) override;

    void changeEvent(QEvent* event) override;

  private:
    void updateAppearance();

    CFColor textColor() const;

    QFont typographyFont() const;

    static const char* typographyTokenName(TypographyStyle style);

    TypographyStyle typographyStyle_;
    LabelColorVariant colorVariant_;
    bool autoHiding_;
    mutable CFColor cachedColor_;      
    mutable bool colorCacheValid_;     
};

} // namespace cf::ui::widget::material

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