From 39fbafec248000c40a640f71bae3ba6b380c9c57 Mon Sep 17 00:00:00 2001 From: "Pedro M. de Echanove Pasquin" Date: Mon, 11 May 2026 12:20:28 +0200 Subject: [PATCH] =?UTF-8?q?container:=20generalise=20`background`=20from?= =?UTF-8?q?=20`Color`=20to=20`Paint`=20`Container::background`=20now=20sto?= =?UTF-8?q?res=20`Option`=20instead=20of=20`Option`,=20and?= =?UTF-8?q?=20the=20builder=20accepts=20`impl=20Into`=20so=20caller?= =?UTF-8?q?s=20can=20pass=20a=20plain=20`Color`=20(auto-wrapped=20in=20`Pa?= =?UTF-8?q?int::Solid`=20via=20the=20trait=20impl)=20or=20an=20explicit=20?= =?UTF-8?q?`LinearGradient`=20/=20`RadialGradient`.=20`layout=5Fand=5Fdraw?= =?UTF-8?q?`=20switches=20from=20`canvas.fill=5Frect(=20rect,=20bg,=20corn?= =?UTF-8?q?ers=20)`=20to=20`canvas.fill=5Fpaint=5Frect(=20rect,=20&bg,=20c?= =?UTF-8?q?orners=20)`=20to=20consume=20the=20wider=20type.=20No=20behavio?= =?UTF-8?q?ur=20change=20for=20existing=20call=20sites=20=E2=80=94=20solid?= =?UTF-8?q?-colour=20containers=20keep=20working=20unchanged=20thanks=20to?= =?UTF-8?q?=20the=20`Into`=20for=20`Color`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/draw/layout.rs | 4 ++-- src/widget/container.rs | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/draw/layout.rs b/src/draw/layout.rs index bb1cf9a..cf90cc5 100644 --- a/src/draw/layout.rs +++ b/src/draw/layout.rs @@ -164,9 +164,9 @@ pub( crate ) fn layout_and_draw( }; if !painted { - if let Some( bg ) = c.background + if let Some( ref bg ) = c.background { - canvas.fill_rect( rect, bg, c.corners ); + canvas.fill_paint_rect( rect, bg, c.corners ); } } if let Some( ( color, width ) ) = c.border diff --git a/src/widget/container.rs b/src/widget/container.rs index d376e6d..e9295c1 100644 --- a/src/widget/container.rs +++ b/src/widget/container.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-2.1-only // Copyright (C) 2026 Liberux Labs, S. L. +use crate::theme::Paint; use crate::types::{ Color, Corners }; use crate::render::Canvas; use super::Element; @@ -50,7 +51,11 @@ use super::Element; pub struct Container { pub child: Box>, - pub background: Option, + /// Optional background paint — flat colour, linear or radial + /// gradient. Constructed via [`Container::background`], which + /// accepts anything `Into` (a plain [`Color`] gets + /// promoted to [`Paint::Solid`] via the trait impl). + pub background: Option, /// Slot id of a themed surface (resolved via /// [`crate::theme::resolve_surface`]). When set, takes precedence /// over `background` and paints the full Glass stack instead of a @@ -109,12 +114,15 @@ impl Container self } - /// Set the background fill color. Ignored at paint time if a + /// Set the background fill. Accepts anything convertible to + /// [`Paint`] — a plain [`Color`] (auto-wrapped in + /// [`Paint::Solid`]) or an explicit [`crate::theme::LinearGradient`] + /// / [`crate::theme::RadialGradient`]. Ignored at paint time if a /// themed [`surface`](Self::surface) is set and resolves against /// the active theme. - pub fn background( mut self, color: Color ) -> Self + pub fn background( mut self, paint: impl Into ) -> Self { - self.background = Some( color ); + self.background = Some( paint.into() ); self }