summaryrefslogtreecommitdiffstats
path: root/graphics/src/widget/container.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/widget/container.rs')
-rw-r--r--graphics/src/widget/container.rs33
1 files changed, 21 insertions, 12 deletions
diff --git a/graphics/src/widget/container.rs b/graphics/src/widget/container.rs
index 070cb48b..576062d4 100644
--- a/graphics/src/widget/container.rs
+++ b/graphics/src/widget/container.rs
@@ -39,20 +39,10 @@ where
let (content, mouse_interaction) =
content.draw(self, &defaults, content_layout, cursor_position);
- if style.background.is_some() || style.border_width > 0 {
- let quad = Primitive::Quad {
- bounds,
- background: style
- .background
- .unwrap_or(Background::Color(Color::TRANSPARENT)),
- border_radius: style.border_radius,
- border_width: style.border_width,
- border_color: style.border_color,
- };
-
+ if let Some(background) = background(bounds, &style) {
(
Primitive::Group {
- primitives: vec![quad, content],
+ primitives: vec![background, content],
},
mouse_interaction,
)
@@ -61,3 +51,22 @@ where
}
}
}
+
+pub(crate) fn background(
+ bounds: Rectangle,
+ style: &container::Style,
+) -> Option<Primitive> {
+ if style.background.is_none() && style.border_width > 0 {
+ return None;
+ }
+
+ Some(Primitive::Quad {
+ bounds,
+ background: style
+ .background
+ .unwrap_or(Background::Color(Color::TRANSPARENT)),
+ border_radius: style.border_radius,
+ border_width: style.border_width,
+ border_color: style.border_color,
+ })
+}