Summary
Requires: #66
Add a .with() method to ElementBuilder that accepts a closure, enabling the modification of the builder after the element's ID has been established in .empty() or .children(), but before finalization.
Motivation
Currently, for example for buttons you need an extra wrapper when dealing with automatic IDs, since the automatic ID is only known after the building.
.with() allows custom builder logic that require the element's ID without redundant wrappers.
Proposed API
pub fn with(mut self, f: impl FnOnce(&mut Ui, ElementBuilder<'ply, WithId, T>) -> ElementBuilder<'ply, WithId, T> + 'static) -> Self
Usage:
ui.element()
.with(|ui, el| {
if ui.pressed() {
el.background_color(0x123456)
} else {
el
}
})
.empty();
Behavior
.with should register a closure to run right after the element's ID has been established in .empty() or .children()
- Inside the closure methods like ui.hovered() should refer to that element
- The
WithId ElementBuilder should be passed to and out of the closure
- You should be able to call
.with() multiple times to register multiple closures
Summary
Requires: #66
Add a
.with()method toElementBuilderthat accepts a closure, enabling the modification of the builder after the element's ID has been established in.empty()or.children(), but before finalization.Motivation
Currently, for example for buttons you need an extra wrapper when dealing with automatic IDs, since the automatic ID is only known after the building.
.with()allows custom builder logic that require the element's ID without redundant wrappers.Proposed API
Usage:
Behavior
.withshould register a closure to run right after the element's ID has been established in.empty()or.children()WithIdElementBuildershould be passed to and out of the closure.with()multiple times to register multiple closures