Support more style properties
This commit is contained in:
parent
fa03c65f8a
commit
80e542daf1
|
@ -30,8 +30,13 @@ fn Editor(cx: Scope) -> Element {
|
|||
let selected_entity = use_state(cx, || Option::<Entity>::None);
|
||||
|
||||
render! {
|
||||
SceneTree { selected_entity: selected_entity }
|
||||
EntityInspector { selected_entity: selected_entity }
|
||||
div {
|
||||
width: "100vw",
|
||||
height: "100vh",
|
||||
justify_content: "space-between",
|
||||
SceneTree { selected_entity: selected_entity }
|
||||
EntityInspector { selected_entity: selected_entity }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,6 +58,7 @@ fn SceneTree<'a>(cx: Scope, selected_entity: &'a UseState<Option<Entity>>) -> El
|
|||
for (entity, name) in entities {
|
||||
div {
|
||||
onclick: move |_| selected_entity.set(Some(entity)),
|
||||
padding: "12",
|
||||
background_color: if Some(entity) == ***selected_entity { INDIGO_600 } else { NEUTRAL_800 },
|
||||
format!("{name:?}")
|
||||
}
|
||||
|
|
|
@ -257,9 +257,38 @@ fn set_style_attribute(
|
|||
("flex-direction", "column") => style.flex_direction = FlexDirection::Column,
|
||||
("background-color", hex) => {
|
||||
background_color.0 = Color::hex(hex).expect(&format!(
|
||||
"Encountered unsupported bevy_dioxus background-color `{hex}`."
|
||||
"Encountered unsupported bevy_dioxus hex Color `{hex}`."
|
||||
))
|
||||
}
|
||||
("padding", val) => style.padding = UiRect::all(parse_val(val)),
|
||||
("width", val) => style.width = parse_val(val),
|
||||
("height", val) => style.height = parse_val(val),
|
||||
("justify-content", "space-between") => {
|
||||
style.justify_content = JustifyContent::SpaceBetween;
|
||||
}
|
||||
("align-content", "space-between") => style.align_content = AlignContent::SpaceBetween,
|
||||
_ => panic!("Encountered unsupported bevy_dioxus attribute `{name}: {value}`."),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_val(val: &str) -> Val {
|
||||
if let Ok(val) = val.parse::<f32>() {
|
||||
return Val::Px(val);
|
||||
}
|
||||
if let Some((val, "")) = val.split_once("px") {
|
||||
if let Ok(val) = val.parse::<f32>() {
|
||||
return Val::Px(val);
|
||||
}
|
||||
}
|
||||
if let Some((val, "")) = val.split_once("vw") {
|
||||
if let Ok(val) = val.parse::<f32>() {
|
||||
return Val::Vw(val);
|
||||
}
|
||||
}
|
||||
if let Some((val, "")) = val.split_once("vh") {
|
||||
if let Ok(val) = val.parse::<f32>() {
|
||||
return Val::Vh(val);
|
||||
}
|
||||
}
|
||||
panic!("Encountered unsupported bevy_dioxus Val `{val}`.");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue