container: generalise background from Color to Paint
`Container::background` now stores `Option<Paint>` instead of `Option<Color>`, and the builder accepts `impl Into<Paint>` so callers can pass a plain `Color` (auto-wrapped in `Paint::Solid` via the trait impl) or an explicit `LinearGradient` / `RadialGradient`. `layout_and_draw` switches from `canvas.fill_rect( rect, bg, corners )` to `canvas.fill_paint_rect( rect, &bg, corners )` to consume the wider type. No behaviour change for existing call sites — solid-colour containers keep working unchanged thanks to the `Into<Paint>` for `Color`.
This commit is contained in:
@@ -164,9 +164,9 @@ pub( crate ) fn layout_and_draw<Msg: Clone>(
|
|||||||
};
|
};
|
||||||
if !painted
|
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
|
if let Some( ( color, width ) ) = c.border
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: LGPL-2.1-only
|
// SPDX-License-Identifier: LGPL-2.1-only
|
||||||
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>
|
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>
|
||||||
|
|
||||||
|
use crate::theme::Paint;
|
||||||
use crate::types::{ Color, Corners };
|
use crate::types::{ Color, Corners };
|
||||||
use crate::render::Canvas;
|
use crate::render::Canvas;
|
||||||
use super::Element;
|
use super::Element;
|
||||||
@@ -50,7 +51,11 @@ use super::Element;
|
|||||||
pub struct Container<Msg: Clone>
|
pub struct Container<Msg: Clone>
|
||||||
{
|
{
|
||||||
pub child: Box<Element<Msg>>,
|
pub child: Box<Element<Msg>>,
|
||||||
pub background: Option<Color>,
|
/// Optional background paint — flat colour, linear or radial
|
||||||
|
/// gradient. Constructed via [`Container::background`], which
|
||||||
|
/// accepts anything `Into<Paint>` (a plain [`Color`] gets
|
||||||
|
/// promoted to [`Paint::Solid`] via the trait impl).
|
||||||
|
pub background: Option<Paint>,
|
||||||
/// Slot id of a themed surface (resolved via
|
/// Slot id of a themed surface (resolved via
|
||||||
/// [`crate::theme::resolve_surface`]). When set, takes precedence
|
/// [`crate::theme::resolve_surface`]). When set, takes precedence
|
||||||
/// over `background` and paints the full Glass stack instead of a
|
/// over `background` and paints the full Glass stack instead of a
|
||||||
@@ -109,12 +114,15 @@ impl<Msg: Clone> Container<Msg>
|
|||||||
self
|
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
|
/// themed [`surface`](Self::surface) is set and resolves against
|
||||||
/// the active theme.
|
/// the active theme.
|
||||||
pub fn background( mut self, color: Color ) -> Self
|
pub fn background( mut self, paint: impl Into<Paint> ) -> Self
|
||||||
{
|
{
|
||||||
self.background = Some( color );
|
self.background = Some( paint.into() );
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user