Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions druid/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ use std::marker::PhantomData;
use std::ops::Deref;
use std::sync::Arc;

use crate::kurbo::RoundedRectRadii;
use crate::localization::L10nManager;
use crate::text::FontDescriptor;
use crate::{ArcStr, Color, Data, Insets, Point, Rect, RoundedRectRadii, Size};
use crate::{ArcStr, Color, Data, Insets, Point, Rect, Size};

/// An environment passed down through all widget traversals.
///
Expand Down Expand Up @@ -662,23 +663,21 @@ impl<T: ValueType> From<Key<T>> for KeyOrValue<T> {
}
}

impl From<f64> for KeyOrValue<Insets> {
fn from(src: f64) -> KeyOrValue<Insets> {
KeyOrValue::Concrete(src.into())
}
}

impl From<(f64, f64)> for KeyOrValue<Insets> {
fn from(src: (f64, f64)) -> KeyOrValue<Insets> {
KeyOrValue::Concrete(src.into())
}
macro_rules! key_or_value_from_concrete {
($from:ty => $to:ty) => {
impl From<$from> for KeyOrValue<$to> {
fn from(f: $from) -> KeyOrValue<$to> {
KeyOrValue::Concrete(f.into())
}
}
};
}

impl From<(f64, f64, f64, f64)> for KeyOrValue<Insets> {
fn from(src: (f64, f64, f64, f64)) -> KeyOrValue<Insets> {
KeyOrValue::Concrete(src.into())
}
}
key_or_value_from_concrete!(f64 => Insets);
key_or_value_from_concrete!((f64, f64) => Insets);
key_or_value_from_concrete!((f64, f64, f64, f64) => Insets);
key_or_value_from_concrete!(f64 => RoundedRectRadii);
key_or_value_from_concrete!((f64, f64, f64, f64) => RoundedRectRadii);

#[cfg(test)]
mod tests {
Expand Down
7 changes: 4 additions & 3 deletions druid/src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use super::BackgroundBrush;
use crate::debug_state::DebugState;
use crate::kurbo::RoundedRectRadii;
use crate::widget::prelude::*;
use crate::{Color, Data, KeyOrValue, Point, WidgetPod};
use tracing::{instrument, trace, trace_span};
Expand All @@ -29,7 +30,7 @@ struct BorderStyle {
pub struct Container<T> {
background: Option<BackgroundBrush<T>>,
border: Option<BorderStyle>,
corner_radius: KeyOrValue<f64>,
corner_radius: KeyOrValue<RoundedRectRadii>,

child: WidgetPod<T, Box<dyn Widget<T>>>,
}
Expand Down Expand Up @@ -119,13 +120,13 @@ impl<T: Data> Container<T> {
}

/// Builder style method for rounding off corners of this container by setting a corner radius
pub fn rounded(mut self, radius: impl Into<KeyOrValue<f64>>) -> Self {
pub fn rounded(mut self, radius: impl Into<KeyOrValue<RoundedRectRadii>>) -> Self {
self.set_rounded(radius);
self
}

/// Round off corners of this container by setting a corner radius
pub fn set_rounded(&mut self, radius: impl Into<KeyOrValue<f64>>) {
pub fn set_rounded(&mut self, radius: impl Into<KeyOrValue<RoundedRectRadii>>) {
self.corner_radius = radius.into();
}

Expand Down