Skip to content

Make Grid take full width when Self::num_columns is Some #5870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zanciks
Copy link

@zanciks zanciks commented Apr 1, 2025

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!

Copy link

github-actions bot commented Apr 8, 2025

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.

@lucasmerlin lucasmerlin changed the title egui::Grid takes up full width when Self::num_rows is some. Make Grid take full width when Self::num_columns is Some Apr 8, 2025
@emilk
Copy link
Owner

emilk commented Apr 8, 2025

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
Copy link
Owner

emilk commented Apr 8, 2025

You can see the what broke in the snapshot test:

Normal

Normal new

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.

2 participants