Skip to content
Snippets Groups Projects
Commit e7c76a74 authored by MrGVSV's avatar MrGVSV
Browse files

Cleaned up TextBox styles

This also seems to have fixed a bug that caused the textbox to jump when
focused (?)
parent 058f8a18
No related branches found
No related tags found
No related merge requests found
use crate::core::{ use crate::core::{
render_command::RenderCommand, render_command::RenderCommand,
rsx, rsx,
styles::{Style, StyleProp, Units}, styles::{Style, Units},
widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps, widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps,
}; };
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
...@@ -79,30 +79,32 @@ pub fn TextBox(props: TextBoxProps) { ...@@ -79,30 +79,32 @@ pub fn TextBox(props: TextBoxProps) {
value, value,
.. ..
} = props.clone(); } = props.clone();
let current_styles = props.styles.clone().unwrap_or_default();
props.styles = Some(Style { props.styles = Some(
render_command: StyleProp::Value(RenderCommand::Layout), Style::default()
height: StyleProp::Value(Units::Pixels(26.0)), // Required styles
top: if matches!(current_styles.top, StyleProp::Value { .. }) { .with_style(Style {
current_styles.top.clone() render_command: RenderCommand::Layout.into(),
} else { ..Default::default()
StyleProp::Value(Units::Pixels(0.0)) })
}, // Apply any prop-given styles
bottom: if matches!(current_styles.bottom, StyleProp::Value { .. }) { .with_style(props.styles)
current_styles.top.clone() // If not set by props, apply these styles
} else { .with_style(Style {
StyleProp::Value(Units::Pixels(0.0)) top: Units::Pixels(0.0).into(),
}, bottom: Units::Pixels(0.0).into(),
..current_styles height: Units::Pixels(26.0).into(),
}); ..Default::default()
})
);
let background_styles = Style { let background_styles = Style {
background_color: StyleProp::Value(Color::new(0.176, 0.196, 0.215, 1.0)), background_color: Color::new(0.176, 0.196, 0.215, 1.0).into(),
border_radius: StyleProp::Value((5.0, 5.0, 5.0, 5.0)), border_radius: (5.0, 5.0, 5.0, 5.0).into(),
height: StyleProp::Value(Units::Pixels(26.0)), height: Units::Pixels(26.0).into(),
padding_left: StyleProp::Value(Units::Pixels(5.0)), padding_left: Units::Pixels(5.0).into(),
padding_right: StyleProp::Value(Units::Pixels(5.0)), padding_right: Units::Pixels(5.0).into(),
..props.styles.clone().unwrap_or_default() ..Default::default()
}; };
let has_focus = context.create_state(Focus(false)).unwrap(); let has_focus = context.create_state(Focus(false)).unwrap();
...@@ -138,14 +140,11 @@ pub fn TextBox(props: TextBoxProps) { ...@@ -138,14 +140,11 @@ pub fn TextBox(props: TextBoxProps) {
let text_styles = if value.is_empty() || (has_focus.get().0 && value.is_empty()) { let text_styles = if value.is_empty() || (has_focus.get().0 && value.is_empty()) {
Style { Style {
color: StyleProp::Value(Color::new(0.5, 0.5, 0.5, 1.0)), color: Color::new(0.5, 0.5, 0.5, 1.0).into(),
..Style::default() ..Style::default()
} }
} else { } else {
Style { Style::default()
color: props.styles.clone().unwrap_or_default().color,
..Style::default()
}
}; };
let value = if value.is_empty() { let value = if value.is_empty() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment