Skip to content

Column::remainder().clip(true) now shrinks when available width decreases#8048

Open
germ4n wants to merge 1 commit intoemilk:mainfrom
germ4n:fix-remainder-clip-shrink
Open

Column::remainder().clip(true) now shrinks when available width decreases#8048
germ4n wants to merge 1 commit intoemilk:mainfrom
germ4n:fix-remainder-clip-shrink

Conversation

@germ4n
Copy link
Copy Markdown

@germ4n germ4n commented Mar 29, 2026

Problem

Column::remainder().clip(true) grows correctly when the panel is made wider, but does not shrink when the panel is made narrower.

Root cause

There are two places in table.rs where the max_used_widths floor is applied to column widths. One correctly checks column.clip, the other doesn't.

Post-render path (already correct, line ~827):

if !column.clip {
    *column_width = column_width.at_least(max_used_widths[i]);
}

TableState::load pre-render path (the bug, line 647):

.at_least(column.width_range.min.max(*max_used))  // clip flag ignored

In TableState::load, .at_least(max_used) is applied to every column regardless of clip. For a Column::remainder(), max_used accumulates the historically widest rendered content. When the panel shrinks, this floor prevents the column from computing a smaller width, creating a cycle where it can never shrink.

Fix

Apply the same clip guard that already exists in the post-render path:

.at_least(if column.clip { column.width_range.min } else { column.width_range.min.max(*max_used) })

When clip = true, the floor is just width_range.min (0.0 by default), allowing the remainder column to shrink freely to the actual remaining space.

Minimal reproduction

use eframe::egui;
use egui_extras::{Column, TableBuilder};

fn main() -> eframe::Result {
    eframe::run_ui_native(
        "Column::remainder().clip(true) shrink test",
        Default::default(),
        |ui, _frame| {
            egui::Frame::central_panel(ui.style()).show(ui, |ui| {
                let mut text = String::from("some content");
                egui::ScrollArea::horizontal().show(ui, |ui| {
                    TableBuilder::new(ui)
                        .column(Column::auto())
                        .column(Column::remainder().clip(true))
                        .header(20.0, |mut header| {
                            header.col(|ui| { ui.strong("Auto"); });
                            header.col(|ui| { ui.strong("Remainder + clip"); });
                        })
                        .body(|mut body| {
                            body.row(18.0, |mut row| {
                                row.col(|ui| { ui.label("label"); });
                                row.col(|ui| {
                                    ui.add(
                                        egui::TextEdit::singleline(&mut text)
                                            .desired_width(f32::INFINITY),
                                    );
                                });
                            });
                        });
                });
            });
        },
    )
}

Without the fix: make the window wider (column grows ✓), then narrower — column does not shrink and a horizontal scrollbar appears ✗

fix-remainder-clip-shrink-before.mp4

With the fix: the column shrinks correctly and no scrollbar appears ✓

fix-remainder-clip-shrink-after.mp4

@github-actions
Copy link
Copy Markdown

Preview is being built...

Preview will be available at https://egui-pr-preview.github.io/pr/8048-fix-remainder-clip-shrink

View snapshot changes at kitdiff

@germ4n germ4n changed the title Column::remainder().clip(true) now shrinks when available width decreases Column::remainder().clip(true) now shrinks when available width decreases Mar 29, 2026
@germ4n germ4n marked this pull request as ready for review March 29, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant