From 1eb7474bd737d44b7415f5a540f8600def62f461 Mon Sep 17 00:00:00 2001 From: MrGVSV <gino.valente.code@gmail.com> Date: Mon, 7 Feb 2022 00:22:28 -0800 Subject: [PATCH] Fixed some style issues in widgets --- src/widgets/button.rs | 35 ++++++++++++++------------- src/widgets/text_box.rs | 2 +- src/widgets/tooltip.rs | 52 +++++++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/widgets/button.rs b/src/widgets/button.rs index 3084e7e..ef4d0e3 100644 --- a/src/widgets/button.rs +++ b/src/widgets/button.rs @@ -38,24 +38,23 @@ impl WidgetProps for ButtonProps { #[widget] pub fn Button(props: ButtonProps) { - let base_styles = props.styles.clone().unwrap_or_default(); - props.styles = Some(Style { - render_command: StyleProp::Value(RenderCommand::Quad), - border_radius: StyleProp::Value((5.0, 5.0, 5.0, 5.0)), - height: if base_styles.height == StyleProp::Default { - StyleProp::Value(Units::Pixels(45.0)) - } else { - base_styles.height - }, - background_color: if matches!(base_styles.background_color, StyleProp::Default) { - StyleProp::Value(Color::new(0.0781, 0.0898, 0.101, 1.0)) - } else { - base_styles.background_color - }, - padding_left: StyleProp::Value(Units::Stretch(1.0)), - padding_right: StyleProp::Value(Units::Stretch(1.0)), - ..base_styles - }); + props.styles = Some( + Style::default() + .with_style(Style { + render_command: StyleProp::Value(RenderCommand::Quad), + ..Default::default() + }) + .with_style(&props.styles) + .with_style(Style { + background_color: StyleProp::Value(Color::new(0.0781, 0.0898, 0.101, 1.0)), + border_radius: StyleProp::Value((5.0, 5.0, 5.0, 5.0)), + height: StyleProp::Value(Units::Pixels(45.0)), + padding_left: StyleProp::Value(Units::Stretch(1.0)), + padding_right: StyleProp::Value(Units::Stretch(1.0)), + ..Default::default() + }) + ); + rsx! { <Fragment> {children} diff --git a/src/widgets/text_box.rs b/src/widgets/text_box.rs index 6bf94d5..881941c 100644 --- a/src/widgets/text_box.rs +++ b/src/widgets/text_box.rs @@ -88,7 +88,7 @@ pub fn TextBox(props: TextBoxProps) { ..Default::default() }) // Apply any prop-given styles - .with_style(props.styles) + .with_style(&props.styles) // If not set by props, apply these styles .with_style(Style { top: Units::Pixels(0.0).into(), diff --git a/src/widgets/tooltip.rs b/src/widgets/tooltip.rs index d5974ea..173de7f 100644 --- a/src/widgets/tooltip.rs +++ b/src/widgets/tooltip.rs @@ -99,22 +99,25 @@ pub fn TooltipProvider(props: TooltipProviderProps) { } = tooltip.get(); let tooltip_size = tooltip_size.unwrap_or((WIDTH, HEIGHT)); - props.styles = Some(Style { - left: StyleProp::Value(Units::Pixels(position.0)), - top: StyleProp::Value(Units::Pixels(position.1)), - width: StyleProp::Value(Units::Pixels(size.0)), - height: StyleProp::Value(Units::Pixels(size.1)), - ..props.styles.clone().unwrap_or_default() - }); + props.styles = Some( + Style::default() + .with_style(Style { + left: StyleProp::Value(Units::Pixels(position.0)), + top: StyleProp::Value(Units::Pixels(position.1)), + ..Default::default() + }) + .with_style(&props.styles) + .with_style(Style { + width: StyleProp::Value(Units::Pixels(size.0)), + height: StyleProp::Value(Units::Pixels(size.1)), + ..Default::default() + }) + ); let base_styles = props.styles.clone().unwrap(); let mut tooltip_styles = Style { position_type: StyleProp::Value(PositionType::SelfDirected), - background_color: if matches!(base_styles.background_color, StyleProp::Default) { - StyleProp::Value(Color::new(0.13, 0.15, 0.17, 0.85)) - } else { - base_styles.background_color - }, + background_color: StyleProp::select(&[&base_styles.background_color, &Color::new(0.13, 0.15, 0.17, 0.85).into()]).clone(), width: StyleProp::Value(Units::Pixels(tooltip_size.0)), height: StyleProp::Value(Units::Pixels(tooltip_size.1)), ..Style::default() @@ -137,11 +140,7 @@ pub fn TooltipProvider(props: TooltipProviderProps) { let text_styles = Style { width: StyleProp::Value(Units::Pixels(tooltip_size.0)), height: StyleProp::Value(Units::Pixels(tooltip_size.1)), - color: if matches!(base_styles.color, StyleProp::Default) { - StyleProp::Value(Color::WHITE) - } else { - base_styles.color - }, + color: StyleProp::select(&[&base_styles.color, &Color::WHITE.into()]).clone(), ..Style::default() }; @@ -196,12 +195,19 @@ pub fn TooltipConsumer(props: TooltipConsumerProps) { let TooltipConsumerProps { anchor, size, text, .. } = props.clone(); - props.styles = Some(Style { - render_command: StyleProp::Value(RenderCommand::Clip), - width: StyleProp::Value(Units::Auto), - height: StyleProp::Value(Units::Auto), - ..props.styles.clone().unwrap_or_default() - }); + props.styles = Some( + Style::default() + .with_style(Style { + render_command: StyleProp::Value(RenderCommand::Clip), + ..Default::default() + }) + .with_style(&props.styles) + .with_style(Style { + width: StyleProp::Value(Units::Auto), + height: StyleProp::Value(Units::Auto), + ..Default::default() + }) + ); let data = context .create_consumer::<TooltipData>() -- GitLab