Implement theme styling for Container
This commit is contained in:
parent
2933ac7355
commit
97555e67af
24 changed files with 306 additions and 258 deletions
|
|
@ -15,13 +15,17 @@ use iced_native::{
|
|||
|
||||
use std::u32;
|
||||
|
||||
pub use iced_style::container::{Style, StyleSheet};
|
||||
pub use iced_style::container::{Appearance, StyleSheet};
|
||||
|
||||
/// An element decorating some content.
|
||||
///
|
||||
/// It is normally used for alignment purposes.
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct Container<'a, Message, Renderer> {
|
||||
pub struct Container<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer::Theme: container::StyleSheet,
|
||||
{
|
||||
padding: Padding,
|
||||
width: Length,
|
||||
height: Length,
|
||||
|
|
@ -29,13 +33,14 @@ pub struct Container<'a, Message, Renderer> {
|
|||
max_height: u32,
|
||||
horizontal_alignment: alignment::Horizontal,
|
||||
vertical_alignment: alignment::Vertical,
|
||||
style_sheet: Box<dyn StyleSheet + 'a>,
|
||||
style: <Renderer::Theme as StyleSheet>::Style,
|
||||
content: Element<'a, Message, Renderer>,
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> Container<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer::Theme: container::StyleSheet,
|
||||
{
|
||||
/// Creates an empty [`Container`].
|
||||
pub fn new<T>(content: T) -> Self
|
||||
|
|
@ -50,7 +55,7 @@ where
|
|||
max_height: u32::MAX,
|
||||
horizontal_alignment: alignment::Horizontal::Left,
|
||||
vertical_alignment: alignment::Vertical::Top,
|
||||
style_sheet: Default::default(),
|
||||
style: Default::default(),
|
||||
content: content.into(),
|
||||
}
|
||||
}
|
||||
|
|
@ -112,9 +117,9 @@ where
|
|||
/// Sets the style of the [`Container`].
|
||||
pub fn style(
|
||||
mut self,
|
||||
style_sheet: impl Into<Box<dyn StyleSheet + 'a>>,
|
||||
style: impl Into<<Renderer::Theme as StyleSheet>::Style>,
|
||||
) -> Self {
|
||||
self.style_sheet = style_sheet.into();
|
||||
self.style = style.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
@ -123,6 +128,7 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
|
|||
for Container<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: iced_native::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
fn children(&self) -> Vec<Tree> {
|
||||
vec![Tree::new(&self.content)]
|
||||
|
|
@ -207,7 +213,7 @@ where
|
|||
cursor_position: Point,
|
||||
viewport: &Rectangle,
|
||||
) {
|
||||
let style = self.style_sheet.style();
|
||||
let style = theme.appearance(self.style);
|
||||
|
||||
container::draw_background(renderer, &style, layout.bounds());
|
||||
|
||||
|
|
@ -243,8 +249,9 @@ where
|
|||
impl<'a, Message, Renderer> From<Container<'a, Message, Renderer>>
|
||||
for Element<'a, Message, Renderer>
|
||||
where
|
||||
Renderer: 'a + iced_native::Renderer,
|
||||
Message: 'a,
|
||||
Renderer: 'a + iced_native::Renderer,
|
||||
Renderer::Theme: StyleSheet,
|
||||
{
|
||||
fn from(
|
||||
column: Container<'a, Message, Renderer>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue