diff --git a/src/widgets/button.rs b/src/widgets/button.rs index 3084e7e0c534e94b0d12cc0c13f6d5d5e3a1e5ac..ef4d0e385ab7c4cd90d568085374c3e9f88448fc 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 6bf94d51e7579f65be8d331c7ca2a74934e942ac..881941ca25bf5dcea15beed67d4de10a03c8b305 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 d5974eabee0428a78c76d8c7a17264a29022b250..173de7f2be52b1d1ecb9bea0330c1e099635f4e8 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>()