Unverified Commit 44d9cbda authored by Florian Blasius's avatar Florian Blasius 🤘 Committed by GitHub

Merge pull request #426 from tysonstewart/support-alignment-in-style

Support Alignment in theme files
parents a1f33950 8f4d0662
......@@ -488,6 +488,8 @@ impl<'a> WidgetContainer<'a> {
self.update_value::<Thickness, Value>(&key, Value(value));
} else if self.is::<String>(&key) {
self.update_value::<String, Value>(&key, Value(value));
} else if self.is::<Alignment>(&key) {
self.update_value::<Alignment, Value>(&key, Value(value));
}
}
}
......
use crate::Value;
/// Used to align a widget vertical or horizontal.
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Alignment {
......@@ -57,6 +59,19 @@ impl From<&str> for Alignment {
}
}
impl From<String> for Alignment {
fn from(s: String) -> Alignment {
Self::from(&s[..])
}
}
impl From<Value> for Alignment {
fn from(v: Value) -> Self {
let value = v.get::<String>();
Alignment::from(value)
}
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
......@@ -121,9 +136,15 @@ mod tests {
);
}
macro_rules! value {
( $e:expr ) => {
Value(ron::Value::String(($e).to_string()))
};
}
#[test]
fn test_into() {
let alignment: Alignment = "start".into();
let alignment: Alignment = "Start".into();
assert_eq!(alignment, Alignment::Start);
let alignment: Alignment = "start".into();
......@@ -135,7 +156,7 @@ mod tests {
let alignment: Alignment = "center".into();
assert_eq!(alignment, Alignment::Center);
let alignment: Alignment = "end".into();
let alignment: Alignment = "End".into();
assert_eq!(alignment, Alignment::End);
let alignment: Alignment = "end".into();
......@@ -149,5 +170,32 @@ mod tests {
let alignment: Alignment = "other".into();
assert_eq!(alignment, Alignment::Stretch);
let alignment: Alignment = value!("Start").into();
assert_eq!(alignment, Alignment::Start);
let alignment: Alignment = value!("start").into();
assert_eq!(alignment, Alignment::Start);
let alignment: Alignment = value!("Center").into();
assert_eq!(alignment, Alignment::Center);
let alignment: Alignment = value!("center").into();
assert_eq!(alignment, Alignment::Center);
let alignment: Alignment = value!("End").into();
assert_eq!(alignment, Alignment::End);
let alignment: Alignment = value!("end").into();
assert_eq!(alignment, Alignment::End);
let alignment: Alignment = value!("Stretch").into();
assert_eq!(alignment, Alignment::Stretch);
let alignment: Alignment = value!("stretch").into();
assert_eq!(alignment, Alignment::Stretch);
let alignment: Alignment = value!("other").into();
assert_eq!(alignment, Alignment::Stretch);
}
}
......@@ -112,14 +112,14 @@ use crate::prelude::*;
/// Lets look at some examples. The first one shows the
/// structure of an angled gradient
///
/// ```
/// ```text
/// [repeating-]linear-gradient({Gradient-angle}{deg|rad|turn}, ...) [{X Displacement}px {Y Displacement}px], {Color} [{Stop position}{%|px}]
/// ```
///
/// The next example shows the structure of a gradient that will be
/// rendered in a given direction
///
/// ```
/// ```text
/// [repeating-]linear-gradient({direction-identifier}, {initial color-name}, {terminating color-name}
/// ```
///
......
......@@ -6,9 +6,10 @@ use std::ops::{Add, Div, Mul, Neg};
///
/// # Examples
/// ```rust
/// # use orbtk_utils::Point;
/// let point = Point::new(10., 10.);
/// let other_point = Point::new(5., 7.);
/// let result = size - other_point;
/// let result = point - other_point;
///
/// assert_eq!(result.x(), 5.);
/// assert_eq!(result.y(), 3.);
......
......@@ -4,6 +4,7 @@ use crate::{Point, Size};
///
/// # Examples
/// ```rust
/// # use orbtk_utils::Rectangle;
/// let rectangle = Rectangle::new((0., 5.),(10., 7.));
///
/// assert_eq!(rectangle.x(), 0.);
......
......@@ -5,6 +5,7 @@ use std::ops::Div;
///
/// # Examples
/// ```rust
/// # use orbtk_utils::Size;
/// let size = Size::new(10., 10.);
/// let other_size = Size::new(5., 7.);
/// let result = size - other_size;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment