egui icon indicating copy to clipboard operation
egui copied to clipboard

Make `Grid` take full width when `Self::num_columns` is `Some`

Open zanciks opened this issue 8 months ago • 3 comments

Hello! This is a PR to address ticket #3928. This PR would close the issue. I've made grid stripes take up the full width available to the Grid when Grid::num_rows is_some(). This change is being made to match the documentation, which states that: Setting this will allow the last column to expand to take up the rest of the space of the parent (Link to comment)

    fn paint_row(&self, cursor: &Rect, painter: &Painter) {
        // ...
-       let rect = rect.expand2(2.0 * Vec2::X); // HACK: just looks better with some spacing on the sides
+       let mut rect = rect.expand2(2.0 * Vec2::X); // HACK: just looks better with some spacing on the sides
+
+       if self.num_columns.is_some() {
+          rect.set_width(cursor.width())
+       }

        painter.rect_filled(rect, 2.0, row_color);
    }

image

I'm a first time contributor to this repo, and I'm honestly not too familiar with how it works, so if there are any issues with this, please let me know and I'll investigate it ASAP!

zanciks avatar Apr 01 '25 17:04 zanciks

Preview available at https://egui-pr-preview.github.io/pr/5870-fulllengthgridstripes Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

github-actions[bot] avatar Apr 08 '25 07:04 github-actions[bot]

Setting this will allow the last column to expand to take up the rest of the space of the parent

I think the keyword here is allow. It should not always expand to the full width, but only do so if there is content in the last column that is wide enough.

You have failing snapshot tests btw

emilk avatar Apr 08 '25 09:04 emilk

You can see the what broke in the snapshot test:

Normal

Normal new

emilk avatar Apr 08 '25 09:04 emilk

Sorry - forgot about this PR. I'll go ahead and close this since I misunderstood the docs, per previous comments. Thanks :)

zanciks avatar Jun 30 '25 17:06 zanciks