Add border styling to Container
This commit is contained in:
parent
8d6f86b317
commit
2116fbb3c2
@ -7,6 +7,8 @@ pub struct Style {
|
|||||||
pub text_color: Option<Color>,
|
pub text_color: Option<Color>,
|
||||||
pub background: Option<Background>,
|
pub background: Option<Background>,
|
||||||
pub border_radius: u16,
|
pub border_radius: u16,
|
||||||
|
pub border_width: u16,
|
||||||
|
pub border_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a container.
|
/// A set of rules that dictate the style of a container.
|
||||||
@ -23,6 +25,8 @@ impl StyleSheet for Default {
|
|||||||
text_color: None,
|
text_color: None,
|
||||||
background: None,
|
background: None,
|
||||||
border_radius: 0,
|
border_radius: 0,
|
||||||
|
border_width: 0,
|
||||||
|
border_color: Color::TRANSPARENT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{container, defaults, Defaults, Primitive, Renderer};
|
use crate::{container, defaults, Defaults, Primitive, Renderer};
|
||||||
use iced_native::{Color, Element, Layout, Point, Rectangle};
|
use iced_native::{Background, Color, Element, Layout, Point, Rectangle};
|
||||||
|
|
||||||
impl iced_native::container::Renderer for Renderer {
|
impl iced_native::container::Renderer for Renderer {
|
||||||
type Style = Box<dyn container::StyleSheet>;
|
type Style = Box<dyn container::StyleSheet>;
|
||||||
@ -25,14 +25,15 @@ impl iced_native::container::Renderer for Renderer {
|
|||||||
let (content, mouse_cursor) =
|
let (content, mouse_cursor) =
|
||||||
content.draw(self, &defaults, content_layout, cursor_position);
|
content.draw(self, &defaults, content_layout, cursor_position);
|
||||||
|
|
||||||
match style.background {
|
if style.background.is_some() || style.border_width > 0 {
|
||||||
Some(background) => {
|
|
||||||
let quad = Primitive::Quad {
|
let quad = Primitive::Quad {
|
||||||
bounds,
|
bounds,
|
||||||
background,
|
background: style
|
||||||
|
.background
|
||||||
|
.unwrap_or(Background::Color(Color::TRANSPARENT)),
|
||||||
border_radius: style.border_radius,
|
border_radius: style.border_radius,
|
||||||
border_width: 0,
|
border_width: style.border_width,
|
||||||
border_color: Color::TRANSPARENT,
|
border_color: style.border_color,
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -41,8 +42,8 @@ impl iced_native::container::Renderer for Renderer {
|
|||||||
},
|
},
|
||||||
mouse_cursor,
|
mouse_cursor,
|
||||||
)
|
)
|
||||||
}
|
} else {
|
||||||
None => (content, mouse_cursor),
|
(content, mouse_cursor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user