Add option to draw background for themer widget

This commit is contained in:
Héctor Ramón Jiménez 2024-02-27 11:49:35 +01:00
parent b5235d7ff8
commit df666502f5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -1,3 +1,4 @@
use crate::container;
use crate::core::event::{self, Event};
use crate::core::layout;
use crate::core::mouse;
@ -6,8 +7,8 @@ use crate::core::renderer;
use crate::core::widget::tree::{self, Tree};
use crate::core::widget::Operation;
use crate::core::{
Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Size, Vector,
Widget,
Background, Clipboard, Element, Layout, Length, Point, Rectangle, Shell,
Size, Vector, Widget,
};
use crate::style::application;
@ -24,6 +25,7 @@ where
content: Element<'a, Message, Theme, Renderer>,
theme: Theme,
style: Theme::Style,
show_background: bool,
}
impl<'a, Message, Theme, Renderer> Themer<'a, Message, Theme, Renderer>
@ -41,8 +43,15 @@ where
content: content.into(),
theme,
style: Theme::Style::default(),
show_background: false,
}
}
/// Sets whether to draw the background color of the `Theme`.
pub fn background(mut self, background: bool) -> Self {
self.show_background = background;
self
}
}
impl<'a, AnyTheme, Message, Theme, Renderer> Widget<Message, AnyTheme, Renderer>
@ -133,6 +142,19 @@ where
) {
let appearance = self.theme.appearance(&self.style);
if self.show_background {
container::draw_background(
renderer,
&container::Appearance {
background: Some(Background::Color(
appearance.background_color,
)),
..container::Appearance::default()
},
layout.bounds(),
);
}
self.content.as_widget().draw(
tree,
renderer,