From fb58080059510de9293fddaad7c543a3089b3824 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 24 Feb 2025 22:31:58 +0100 Subject: feat: implement `ValueFromStr` for Rotation --- src/options.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'src/options.rs') diff --git a/src/options.rs b/src/options.rs index 5a3e1fb..c381294 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,12 +1,12 @@ use std::collections::BTreeMap; -use iced::Padding; #[allow(unused_imports)] use iced::widget::{Button, Column, Container, Image, Row, Svg, Text}; +use iced::{Padding, Rotation}; use crate::values::ValueFromStr; -pub trait ApplyOptions { +pub trait ApplyOptions: Sized { fn apply_options(self, options: BTreeMap>) -> Self; } @@ -15,10 +15,62 @@ impl ApplyOptions for Button<'_, Message> { let mut button = self; if let Some(padding) = options.get("padding").expect("padding key") { - let padding: Padding = Padding::value_from_str(padding).unwrap(); + let padding = Padding::value_from_str(padding).unwrap(); button = button.padding(padding); } button } } + +impl ApplyOptions for Column<'_, Message> { + fn apply_options(self, options: BTreeMap>) -> Self { + let mut column = self; + + if let Some(padding) = options.get("padding").expect("padding key") { + let padding = Padding::value_from_str(padding).unwrap(); + column = column.padding(padding); + } + + column + } +} + +impl ApplyOptions for Row<'_, Message> { + fn apply_options(self, options: BTreeMap>) -> Self { + let mut row = self; + + if let Some(padding) = options.get("padding").expect("padding key") { + let padding = Padding::value_from_str(padding).unwrap(); + row = row.padding(padding); + } + + row + } +} + +impl ApplyOptions for Image { + fn apply_options(self, options: BTreeMap>) -> Self { + let mut image = self; + + if let Some(rotation) = options.get("rotation").expect("rotation key") { + let rotation = Rotation::value_from_str(rotation).unwrap(); + image = image.rotation(rotation); + } + + image + } +} + +impl ApplyOptions for Svg<'_> { + fn apply_options(self, options: BTreeMap>) -> Self { + let mut svg = self; + + if let Some(rotation) = options.get("rotation").expect("rotation key") { + let rotation = Rotation::value_from_str(rotation).unwrap(); + svg = svg.rotation(rotation); + } + + svg + } +} -- cgit v1.2.3