Closed skreborn closed 1 month ago
Thanks for the issue! I definitely want to add support for this, and probably very soon.
For now, I've gone ahead and pushed a fix to main for the negative margins issue, so now this will work consistently for the border title use-case:
use iocraft::prelude::*;
fn main() {
element! {
Box(
border_style: BorderStyle::Round,
border_color: Color::Blue,
flex_direction: FlexDirection::Column,
) {
Box(
margin_top: -1,
) {
Text(content: "Title")
}
Text(content: "Hello, world!")
}
}
.print();
}
╭Title────────╮
│Hello, world!│
╰─────────────╯
I'll cut the release with this in the next few days as well.
I just pushed out a minor release with the margin fix and with support for additional Box
properties: position
, inset
, top
, left
, right
, bottom
. Elements are also drawn in deterministic order now.
Stacking elements should be really easy now, and I've added an "overlap" example to demonstrate:
– https://github.com/ccbrown/iocraft/blob/main/examples/overlap.rs
Excellent work, much appreciated!
Stacked widgets are important to allow multiple components to be drawn on top of each other, including floating buttons, titles on borders, or popups.
It's fairly easy to implement stacks using grid layout - although the result is a little too verbose and error-prone.
However, since the instanced components are internally stored in unordered
HashMap
s, the render order is nondeterministic, and as such the stacked children are drawn in arbitrary orders. For example, the previous code can render either of the following two output variants.Other tricks that would allow drawing order the border of a parent include negative margins, but those seem to simply crash the application.