@@ -20,8 +20,11 @@ namespace {
2020
2121} // namespace
2222
23- DesktopLabelWidget::DesktopLabelWidget (std::string title, std::string description, ColorSpec color, bool shadow)
24- : m_title(std::move(title)), m_description(std::move(description)), m_color(color), m_shadow(shadow) {}
23+ DesktopLabelWidget::DesktopLabelWidget (
24+ std::string title, std::string description, ColorSpec color, float opacity, bool shadow
25+ )
26+ : m_title(std::move(title)), m_description(std::move(description)), m_color(color),
27+ m_opacity(std::clamp(opacity, 0 .0f , 1 .0f )), m_shadow(shadow) {}
2528
2629void DesktopLabelWidget::create () {
2730 auto rootNode = std::make_unique<Node>();
@@ -49,6 +52,7 @@ void DesktopLabelWidget::create() {
4952 rootNode->addChild (std::move (descriptionLabel));
5053
5154 setRoot (std::move (rootNode));
55+ applyLabelColors ();
5256 applyShadow ();
5357}
5458
@@ -81,17 +85,27 @@ bool DesktopLabelWidget::applySetting(
8185 if (key == " color" ) {
8286 if (const auto * v = std::get_if<std::string>(&value)) {
8387 m_color = colorSpecFromConfigString (*v, key);
84- if (m_titleLabel != nullptr ) {
85- m_titleLabel->setColor (m_color);
86- }
87- if (m_descriptionLabel != nullptr ) {
88- m_descriptionLabel->setColor (m_color);
89- }
88+ applyLabelColors ();
9089 requestLayout ();
9190 return true ;
9291 }
9392 return false ;
9493 }
94+ if (key == " opacity" ) {
95+ if (const auto * v = std::get_if<double >(&value)) {
96+ m_opacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
97+ applyLabelColors ();
98+ applyShadow ();
99+ return true ;
100+ }
101+ if (const auto * v = std::get_if<std::int64_t >(&value)) {
102+ m_opacity = std::clamp (static_cast <float >(*v), 0 .0f , 1 .0f );
103+ applyLabelColors ();
104+ applyShadow ();
105+ return true ;
106+ }
107+ return false ;
108+ }
95109 if (key == " shadow" ) {
96110 if (const auto * v = std::get_if<bool >(&value)) {
97111 m_shadow = *v;
@@ -142,12 +156,24 @@ void DesktopLabelWidget::doLayout(Renderer& renderer) {
142156
143157 m_titleLabel->setPosition (0 .0f , 0 .0f );
144158 root ()->setSize (width, height);
159+ applyLabelColors ();
145160 applyShadow ();
146161}
147162
163+ void DesktopLabelWidget::applyLabelColors () {
164+ ColorSpec effective = m_color;
165+ effective.alpha *= m_opacity;
166+ if (m_titleLabel != nullptr ) {
167+ m_titleLabel->setColor (effective);
168+ }
169+ if (m_descriptionLabel != nullptr ) {
170+ m_descriptionLabel->setColor (effective);
171+ }
172+ }
173+
148174void DesktopLabelWidget::applyShadow () {
149175 const float offset = kShadowOffset * contentScale ();
150- const Color shadowColor (0 .0f , 0 .0f , 0 .0f , kShadowAlpha );
176+ const Color shadowColor (0 .0f , 0 .0f , 0 .0f , kShadowAlpha * m_opacity );
151177
152178 auto applyTo = [this , offset, shadowColor](Label* label) {
153179 if (label == nullptr ) {
0 commit comments