Functions now support subelements
parent
847542a8cb
commit
a49e1f61bd
|
@ -14,11 +14,10 @@ pub fn build_radialbar_module(state_src: Rc<RefCell<UiState>>) -> Module {
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(
|
.set_into_module(
|
||||||
&mut module,
|
&mut module,
|
||||||
// TODO: fix ugly spaces
|
|
||||||
move |name: ImmutableString, stroke: f32, color: Color, rect: Rect| {
|
move |name: ImmutableString, stroke: f32, color: Color, rect: Rect| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
|
|
||||||
if ui_state.elements.contains_key(&name) {
|
if ui_state.contains_name(&name) {
|
||||||
error!("tried to make a radialbar using an existing name `{name}`");
|
error!("tried to make a radialbar using an existing name `{name}`");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -38,12 +37,23 @@ pub fn build_radialbar_module(state_src: Rc<RefCell<UiState>>) -> Module {
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString, val: f32| {
|
.set_into_module(&mut module, move |name: ImmutableString, val: f32| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::RadialBar(x)) => x.set_val(val),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::RadialBar(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `radialbar_set_val` on an invalid name `{name}`")
|
error!("called `radialbar::set_val` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::RadialBar(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `radialbar::set_val` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_val(val);
|
||||||
});
|
});
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn build_scrollbox_module(state_src: Rc<RefCell<UiState>>) -> Module {
|
||||||
.set_into_module(&mut module, move |name: ImmutableString, rect: Rect| {
|
.set_into_module(&mut module, move |name: ImmutableString, rect: Rect| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
|
|
||||||
if ui_state.elements.contains_key(&name) {
|
if ui_state.contains_name(&name) {
|
||||||
error!("tried to make a scrollbox using an existing name `{name}`");
|
error!("tried to make a scrollbox using an existing name `{name}`");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -30,44 +30,41 @@ pub fn build_scrollbox_module(state_src: Rc<RefCell<UiState>>) -> Module {
|
||||||
&mut module,
|
&mut module,
|
||||||
move |name: ImmutableString, target: ImmutableString| {
|
move |name: ImmutableString, target: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
|
|
||||||
|
// Make sure `name` is a scrollbox
|
||||||
match ui_state.get_mut_by_name(&name) {
|
match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Scrollbox(_)) => {
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Scrollbox(_) => {}
|
||||||
|
_ => {
|
||||||
|
error!("called `scrollbox::add_element` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Scrollbox(_)) => {}
|
||||||
|
_ => {
|
||||||
|
error!("called `scrollbox::add_element` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the target with a SubElement, without changing its position in the array.
|
||||||
match ui_state.get_mut_by_name(&target) {
|
match ui_state.get_mut_by_name(&target) {
|
||||||
Some(UiElement::Text(_)) | Some(UiElement::Sprite(_)) => {
|
Some(UiElement::Text(_)) | Some(UiElement::Sprite(_)) => {
|
||||||
let e = match ui_state.remove_element_incomplete(&target) {
|
let e = ui_state.get_mut_by_name(&target).unwrap();
|
||||||
Some(UiElement::Sprite(s)) => {
|
let new = (*e).clone();
|
||||||
Rc::new(RefCell::new(UiElement::Sprite(s)))
|
*e = UiElement::SubElement {
|
||||||
}
|
|
||||||
Some(UiElement::Text(t)) => {
|
|
||||||
Rc::new(RefCell::new(UiElement::Text(t)))
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add a subelement pointing to this sprite
|
|
||||||
ui_state.add_element(UiElement::SubElement {
|
|
||||||
parent: name.clone(),
|
parent: name.clone(),
|
||||||
element: e.clone(),
|
element: Box::new(new),
|
||||||
});
|
|
||||||
|
|
||||||
// Add this sprite to a scrollbox
|
|
||||||
match ui_state.get_mut_by_name(&name) {
|
|
||||||
Some(UiElement::Scrollbox(s)) => {
|
|
||||||
s.add_element(e);
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
error!("cannot add `{name}` to scrollbox `{name}`, invalid type.")
|
error!("cannot add `{name}` to scrollbox `{name}`, invalid type.")
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
error!("called `scrollbox::add_element` with a non-existing target `{target}`")
|
error!(
|
||||||
}
|
"called `scrollbox::add_element` with a non-existing target `{target}`"
|
||||||
}
|
)
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
error!("called `scrollbox::add_element` on an invalid name `{name}`")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui_state.elements.contains_key(&name) {
|
if ui_state.contains_name(&name) {
|
||||||
error!("tried to make a sprite using an existing name `{name}`");
|
error!("tried to make a sprite using an existing name `{name}`");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
if ui_state.elements.contains_key(&name) {
|
if ui_state.contains_name(&name) {
|
||||||
ui_state.remove_element(&name);
|
ui_state.remove_element(&name);
|
||||||
} else {
|
} else {
|
||||||
error!("called `sprite::remove` on an invalid name `{name}`")
|
error!("called `sprite::remove` on an invalid name `{name}`")
|
||||||
|
@ -96,12 +96,24 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
move |name: ImmutableString, edge_name: ImmutableString, duration: f32| {
|
move |name: ImmutableString, edge_name: ImmutableString, duration: f32| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
|
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Sprite(x)) => {
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
let sprite = x.anim.get_sprite();
|
UiElement::Sprite(x) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `sprite::jump_to` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
let edge =
|
Some(UiElement::Sprite(x)) => x,
|
||||||
resolve_edge_as_edge(&sprite.sections, edge_name.as_str(), duration);
|
_ => {
|
||||||
|
error!("called `sprite::jump_to` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let sprite = e.anim.get_sprite();
|
||||||
|
let edge = resolve_edge_as_edge(&sprite.sections, edge_name.as_str(), duration);
|
||||||
let edge = match edge {
|
let edge = match edge {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error!(
|
error!(
|
||||||
|
@ -113,12 +125,7 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
};
|
};
|
||||||
|
|
||||||
x.anim.jump_to(&edge);
|
e.anim.jump_to(&edge);
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
error!("called `sprite::jump_to` on an invalid name `{name}`")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -127,12 +134,22 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString, x: f32| {
|
.set_into_module(&mut module, move |name: ImmutableString, x: f32| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Sprite(s)) => s.set_angle(x),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Sprite(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `sprite::set_angle` on an invalid name `{name}`")
|
error!("called `sprite::set_angle` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Some(UiElement::Sprite(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `sprite::set_angle` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_angle(x)
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -140,12 +157,22 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString, x: Rect| {
|
.set_into_module(&mut module, move |name: ImmutableString, x: Rect| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Sprite(s)) => s.set_rect(x),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Sprite(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `sprite::set_rect` on an invalid name `{name}`")
|
error!("called `sprite::set_rect` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Some(UiElement::Sprite(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `sprite::set_rect` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_rect(x);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -153,12 +180,22 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString, x: Color| {
|
.set_into_module(&mut module, move |name: ImmutableString, x: Color| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Sprite(s)) => s.set_color(x),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Sprite(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `sprite::set_color` on an invalid name `{name}`")
|
error!("called `sprite::set_color` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Some(UiElement::Sprite(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `sprite::set_color` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_color(x);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -166,12 +203,46 @@ pub fn build_sprite_module(ct_src: Arc<Content>, state_src: Rc<RefCell<UiState>>
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString, x: bool| {
|
.set_into_module(&mut module, move |name: ImmutableString, x: bool| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Sprite(s)) => s.set_preserve_aspect(x),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Sprite(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `sprite::set_preserve_aspect` on an invalid name `{name}`")
|
error!("called `sprite::preserve_aspect` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Some(UiElement::Sprite(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `sprite::preserve_aspect` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_preserve_aspect(x);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let state = state_src.clone();
|
||||||
|
let _ = FuncRegistration::new("set_disable_events")
|
||||||
|
.with_namespace(FnNamespace::Internal)
|
||||||
|
.set_into_module(&mut module, move |name: ImmutableString, x: bool| {
|
||||||
|
let mut ui_state = state.borrow_mut();
|
||||||
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Sprite(x) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `sprite::set_disable_events` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some(UiElement::Sprite(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `sprite::set_disable_events` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_disable_events(x);
|
||||||
|
});
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub fn build_textbox_module(
|
||||||
color: Color| {
|
color: Color| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
|
|
||||||
if ui_state.elements.contains_key(&name) {
|
if ui_state.contains_name(&name) {
|
||||||
error!("tried to make a textbox using an existing name `{name}`");
|
error!("tried to make a textbox using an existing name `{name}`");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,24 @@ pub fn build_textbox_module(
|
||||||
&mut module,
|
&mut module,
|
||||||
move |name: ImmutableString, text: ImmutableString| {
|
move |name: ImmutableString, text: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
|
||||||
Some(UiElement::Text(x)) => x.set_text(&mut font.borrow_mut(), text.as_str()),
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::set_text` on an invalid name `{name}`")
|
error!("called `textbox::set_text` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::set_text` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_text(&mut font.borrow_mut(), text.as_str());
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -66,12 +78,24 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
|
||||||
Some(UiElement::Text(x)) => x.set_align(&mut font.borrow_mut(), Align::Left),
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::align_left` on an invalid name `{name}`")
|
error!("called `textbox::align_left` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::align_left` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_align(&mut font.borrow_mut(), Align::Left);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -80,12 +104,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_align(&mut font.borrow_mut(), Align::Right),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::align_right` on an invalid name `{name}`")
|
error!("called `textbox::align_right` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::align_right` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_align(&mut font.borrow_mut(), Align::Right);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -94,12 +129,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_align(&mut font.borrow_mut(), Align::Justified),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::align_justify` on an invalid name `{name}`")
|
error!("called `textbox::align_justify` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::align_justify` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_align(&mut font.borrow_mut(), Align::Justified);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -108,12 +154,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_align(&mut font.borrow_mut(), Align::Center),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::align_center` on an invalid name `{name}`")
|
error!("called `textbox::align_center` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::align_center` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_align(&mut font.borrow_mut(), Align::Center);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -122,12 +179,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_weight(&mut font.borrow_mut(), Weight::BOLD),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::weight_bold` on an invalid name `{name}`")
|
error!("called `textbox::weight_bold` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::weight_bold` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_weight(&mut font.borrow_mut(), Weight::BOLD);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -136,12 +204,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_weight(&mut font.borrow_mut(), Weight::NORMAL),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::weight_normal` on an invalid name `{name}`")
|
error!("called `textbox::weight_normal` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::weight_normal` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_weight(&mut font.borrow_mut(), Weight::NORMAL);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -150,12 +229,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_font(&mut font.borrow_mut(), FamilyOwned::Serif),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::font_serif` on an invalid name `{name}`")
|
error!("called `textbox::font_serif` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::font_serif` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_font(&mut font.borrow_mut(), FamilyOwned::Serif);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -164,14 +254,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => {
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
x.set_font(&mut font.borrow_mut(), FamilyOwned::SansSerif)
|
UiElement::Text(x) => x,
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::font_sans` on an invalid name `{name}`")
|
error!("called `textbox::font_sans` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::font_sans` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_font(&mut font.borrow_mut(), FamilyOwned::SansSerif);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -180,14 +279,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => {
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
x.set_font(&mut font.borrow_mut(), FamilyOwned::Monospace)
|
UiElement::Text(x) => x,
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::font_mono` on an invalid name `{name}`")
|
error!("called `textbox::font_mono` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::font_mono` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_font(&mut font.borrow_mut(), FamilyOwned::Monospace);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -196,12 +304,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_style(&mut font.borrow_mut(), Style::Normal),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::style_normal` on an invalid name `{name}`")
|
error!("called `textbox::style_normal` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::style_normal` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_style(&mut font.borrow_mut(), Style::Normal);
|
||||||
});
|
});
|
||||||
|
|
||||||
let state = state_src.clone();
|
let state = state_src.clone();
|
||||||
|
@ -210,12 +329,23 @@ pub fn build_textbox_module(
|
||||||
.with_namespace(FnNamespace::Internal)
|
.with_namespace(FnNamespace::Internal)
|
||||||
.set_into_module(&mut module, move |name: ImmutableString| {
|
.set_into_module(&mut module, move |name: ImmutableString| {
|
||||||
let mut ui_state = state.borrow_mut();
|
let mut ui_state = state.borrow_mut();
|
||||||
match ui_state.get_mut_by_name(&name) {
|
let e = match ui_state.get_mut_by_name(&name) {
|
||||||
Some(UiElement::Text(x)) => x.set_style(&mut font.borrow_mut(), Style::Italic),
|
Some(UiElement::SubElement { element, .. }) => match &mut **element {
|
||||||
|
UiElement::Text(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
error!("called `textbox::style_italic` on an invalid name `{name}`")
|
error!("called `textbox::style_italic` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
Some(UiElement::Text(x)) => x,
|
||||||
|
_ => {
|
||||||
|
error!("called `textbox::style_italic` on an invalid name `{name}`");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
e.set_style(&mut font.borrow_mut(), Style::Italic);
|
||||||
});
|
});
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
|
|
Loading…
Reference in New Issue