summaryrefslogtreecommitdiff
path: root/src/options.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/options.rs')
-rw-r--r--src/options.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/options.rs b/src/options.rs
new file mode 100644
index 0000000..9514dcb
--- /dev/null
+++ b/src/options.rs
@@ -0,0 +1,44 @@
+use std::collections::BTreeMap;
+use std::str::FromStr;
+
+use iced::Padding;
+use iced::widget::{Button, Column, Container, Image, Row, Svg, Text};
+
+pub trait ApplyOptions {
+ fn apply_options(self, options: BTreeMap<String, Option<String>>) -> Self;
+}
+
+impl<'a, Message> ApplyOptions for Button<'a, 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();
+ button = button.padding(padding);
+ }
+
+ button
+ }
+}