8000 Fix `DragValue` expansion when editing by MStarha · Pull Request #5809 · emilk/egui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix DragValue expansion when editing #5809

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

Merged
merged 5 commits into from
Mar 20, 2025

Conversation

MStarha
Copy link
Contributor
@MStarha MStarha commented Mar 16, 2025
  • I have followed the instructions in the PR template

This PR fixes an issue, where DragValue would expand when it enters editing state. There were 3 contributing problems:

  • A workaround introduced in Make TextEdit an atomic widget #4276 caused the DragValue to report incorrect outer size.
  • The DragValue uses TextEdit internally and sets both min_size and desired_width to the same value - desired width is used before padding is applied - this is in contrast to Button (also used internally by DragValue), which only uses min_size. This caused the DragValue to expand horizontally by the size of button padding.
  • The height of the TextEdit is (among other things) determined by the height of the row, which was not present in Button. This caused a small vertical expansion, when the contents (including padding) were larger than the min_size.

egui_drag_value_expansion
Here the dimensions set in code are:

  • padding: 20 x 20 pt
  • interact size: 80 x 30 pt

Note: I do not know what's up with the tests. When I ran the check script, they were failing because of 3 UI missmatches, so I updated the snapshots. Now, the updated snapshots cause the same failure in CI, that appeared locally before the update. Now the locally run tests fail with The platform you're compiling for is not supported by winit and couple more following errors coming from the same source (winit 0.30.7).

Copy link

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

@MStarha MStarha marked this pull request as ready for review March 16, 2025 13:39
Copy link
Collaborator
@lucasmerlin lucasmerlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Seems to work well.

About the snapshots, could you try running the script I added in this PR to update your snapshots (by downloading / copying or merging that branch)?
#5816

Comment on lines -430 to +433
let mut output = self.show_content(ui);

// TODO(emilk): return full outer_rect in `TextEditOutput`.
// Can't do it now because this fix is ging into a patch release.
let outer_rect = output.response.rect;
let inner_rect = outer_rect - margin;
output.response.rect = inner_rect;
let output = self.show_content(ui);

if frame {
let visuals = ui.style().interact(&output.response);
let frame_rect = outer_rect.expand(visuals.expansion);
let frame_rect = output.response.rect.expand(visuals.expansion);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention this as a breaking change in the changelog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that something I should do? And where? CHANGELOG.md?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, I was just commenting this for myself, I'll update the title / description accordingly when merging the PR

@lucasmerlin lucasmerlin added bug Something is broken egui labels Mar 17, 2025
@MStarha MStarha force-pushed the drag-value-expansion branch from 7c0eea9 to 4a53f4c Compare March 17, 2025 16:14
@MStarha
Copy link
Contributor Author
MStarha commented Mar 17, 2025

Nice! Seems to work well.

About the snapshots, could you try running the script I added in this PR to update your snapshots (by downloading / copying or merging that branch)? #5816

After gh installation and configuration, this is the error I get:
no valid artifacts found to download

@lucasmerlin
Copy link
Collaborator

Hmm weird, but thanks for trying!

Comment on lines 227 to 229
let font_selection = FontSelection::default();
let font_id = font_selection.resolve(ui.style());
let row_height = ui.fonts(|f| f.row_height(&font_id));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think this could break though, if the RichText sets a different font?

There is RichText::font_height, I think you could use that instead 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text is the more generic WidgetText, but the font_height method is still there. Nevertheless, there seems to be a bug in the text layouter that results in different text heights, becase the font height reported by the WidgetText is different than the text height reported by the Galley, that is created from the WidgetText.

@MStarha MStarha requested a review from lucasmerlin March 19, 2025 18:42
Copy link
Collaborator
@lucasmerlin lucasmerlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MStarha MStarha deleted the drag-value-expansion branch March 20, 2025 19:20
lucasmerlin added a commit that referenced this pull request Apr 16, 2025
lucasmerlin added a commit that referenced this pull request Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken egui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0