summaryrefslogtreecommitdiff
path: root/src/options.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.dev>2025-02-22 23:48:19 +0100
committerpml68 <contact@pml68.dev>2025-02-22 23:48:19 +0100
commit09cd0fe9f2d5d775cd1b645300ac56bc203a20cd (patch)
treefdbac1602752c780c7ed704a49dc7a03c8087d7c /src/options.rs
parentfeat: update to Rust 2024 (diff)
downloadiced-builder-09cd0fe9f2d5d775cd1b645300ac56bc203a20cd.tar.gz
feat: start working on options backend (`ApplyOptions` trait)
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
+ }
+}