summaryrefslogtreecommitdiffstats
path: root/style
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-10 02:58:40 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-10 10:01:50 +0100
commit81ecc4a67f7982c6300a4d5e8ec4e8aac8cbd881 (patch)
treef3fb8851b62008f8349036ec2aae50a7fc303257 /style
parenta79b2adf5c3e345667341451a4aaaa14fc9bfe80 (diff)
downloadiced-81ecc4a67f7982c6300a4d5e8ec4e8aac8cbd881.tar.gz
iced-81ecc4a67f7982c6300a4d5e8ec4e8aac8cbd881.tar.bz2
iced-81ecc4a67f7982c6300a4d5e8ec4e8aac8cbd881.zip
Add basic controls to `layout` example
Diffstat (limited to 'style')
-rw-r--r--style/src/container.rs26
-rw-r--r--style/src/theme.rs6
2 files changed, 31 insertions, 1 deletions
diff --git a/style/src/container.rs b/style/src/container.rs
index ec543ae4..490a9dab 100644
--- a/style/src/container.rs
+++ b/style/src/container.rs
@@ -1,5 +1,5 @@
//! Change the appearance of a container.
-use iced_core::{Background, BorderRadius, Color};
+use crate::core::{Background, BorderRadius, Color, Pixels};
/// The appearance of a container.
#[derive(Debug, Clone, Copy)]
@@ -16,6 +16,30 @@ pub struct Appearance {
pub border_color: Color,
}
+impl Appearance {
+ /// Derives a new [`Appearance`] with a border of the given [`Color`] and
+ /// `width`.
+ pub fn with_border(
+ self,
+ color: impl Into<Color>,
+ width: impl Into<Pixels>,
+ ) -> Self {
+ Self {
+ border_color: color.into(),
+ border_width: width.into().0,
+ ..self
+ }
+ }
+
+ /// Derives a new [`Appearance`] with the given [`Background`].
+ pub fn with_background(self, background: impl Into<Background>) -> Self {
+ Self {
+ background: Some(background.into()),
+ ..self
+ }
+ }
+}
+
impl std::default::Default for Appearance {
fn default() -> Self {
Self {
diff --git a/style/src/theme.rs b/style/src/theme.rs
index 47010728..eafb0b47 100644
--- a/style/src/theme.rs
+++ b/style/src/theme.rs
@@ -383,6 +383,12 @@ pub enum Container {
Custom(Box<dyn container::StyleSheet<Style = Theme>>),
}
+impl From<container::Appearance> for Container {
+ fn from(appearance: container::Appearance) -> Self {
+ Self::Custom(Box::new(move |_: &_| appearance))
+ }
+}
+
impl<T: Fn(&Theme) -> container::Appearance + 'static> From<T> for Container {
fn from(f: T) -> Self {
Self::Custom(Box::new(f))