summaryrefslogtreecommitdiff
path: root/src/options.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/options.rs30
1 files changed, 5 insertions, 25 deletions
diff --git a/src/options.rs b/src/options.rs
index 9514dcb..5a3e1fb 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -1,41 +1,21 @@
use std::collections::BTreeMap;
-use std::str::FromStr;
use iced::Padding;
+#[allow(unused_imports)]
use iced::widget::{Button, Column, Container, Image, Row, Svg, Text};
+use crate::values::ValueFromStr;
+
pub trait ApplyOptions {
fn apply_options(self, options: BTreeMap<String, Option<String>>) -> Self;
}
-impl<'a, Message> ApplyOptions for Button<'a, Message> {
+impl<Message> ApplyOptions for Button<'_, Message> {
fn apply_options(self, options: BTreeMap<String, Option<String>>) -> Self {
let mut button = self;
if let Some(padding) = options.get("padding").expect("padding key") {
- let padding: Padding = padding
- .strip_prefix('[')
- .and_then(|s| s.strip_suffix(']'))
- .and_then(|s| {
- Some(
- s.split(',')
- .map(|n| f32::from_str(n).unwrap())
- .collect::<Vec<_>>(),
- )
- })
- .and_then(|s| {
- if s.len() == 4 {
- Some(Padding {
- top: s[0],
- right: s[1],
- bottom: s[2],
- left: s[3],
- })
- } else {
- None
- }
- })
- .unwrap();
+ let padding: Padding = Padding::value_from_str(padding).unwrap();
button = button.padding(padding);
}