当为单个元素应用 Flex::SpaceBetween 时, Constraint::Length 不能正常工作
Description
When creating a Layout for an area with a hard length comprising of a single item and applying flex::spacebetween does not properly render the item with fixed length, instead it expands the item to fill the remaining space. Example: let [item] = Layout::horizontal([Constraint::Length(50)]) .flex(Flex::SpaceBetween) .areas(area); =================== Expected behavior ==================== <------------------------------------80 px-------------------------------------> ┌──────50 px───────┐ │ Length(50) │ └──────────────── ┘ ======================Actual behavior ========================= <------------------------------------80 px-------------------------------------> ┌────────────────80 px──────────────────────────┐ │ Length(50) │ └───────────────────────────────────────────── ┘
To Reproduce
Minimal code repo : https://GitHub.com/kb019/ratatui_flex_between
Expected behavior
=================== Expected behavior ==================== <------------------------------------80 px-------------------------------------> ┌──────50 px───────┐ │ Length(50) │ └──────────────── ┘
Screenshots
## Are you willing to contribute a fix?Yes i am willing to contribute to the fix
- I am willing to open a PR for this bug.
- I can try to investigate, but I will need guidance.
- I am not able to work on a fix right now.
Environment
- OS: Windows
- Terminal Emulator: VS Code Integrated Terminal
- Font:
- Crate version: 0.30.2
- Backend: crossterm
Additional context
Test Case expected to pass
#[test]
fn space_between_single_length_preserves_constraint() {
let area = Rect::new(0, 0, 80, 1);
let [item] = Layout::horizontal([Constraint::Length(50)])
.flex(Flex::SpaceBetween)
.areas(area);
assert_eq!(item,
…
内容来源: ratatui/ratatui