#2710·ratatui

Constraint::Length does not work properly when Flex::SpaceBetween is applied for single element

Author: kb019Created Aug 14, 2026Updated Aug 24, 2026
LabelsType: Bug

Description

When creating a Layout for a 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 remaning 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

Image

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, Rect::new(0, 0, 50, 1));
}