Skip to content
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

Regression: TextEdit claims full width even with smaller desired_width #5500

Open
crumblingstatue opened this issue Dec 17, 2024 · 5 comments
Labels
bug Something is broken

Comments

@crumblingstatue
Copy link
Contributor

crumblingstatue commented Dec 17, 2024

#5266 makes TextEdit have an "intrinsic" size, which I'm guessing makes containers expand to the size it reports as intrinsic size.
EDIT: #3660 is the cause, see #5500 (comment)
The problem is that it seems to claim the full width of the text, even when desired_width is smaller.
This causes things like side panels to expand way too far for long text, and possibly flicker a lot if the text width changes.

Here is an example of a SidePanel::right expanding way too far (due to very long floating point number displayed in the text edit)
desired_width is set to 100.0 in this example case.
image

@crumblingstatue crumblingstatue added the bug Something is broken label Dec 17, 2024
@crumblingstatue
Copy link
Contributor Author

If this is intended behavior, then there should be some kind of way to set a max "default width" for a SidePanel that it won't automatically expand beyond, unless the user explicitly resizes. Otherwise I don't know how to avoid the flickering without limiting the max width, which also prevents the user from being able to resize beyond the set limit, which I want to allow.

@lucasmerlin
Copy link
Collaborator

Egui currently does absolutely nothing with the intrinsic size, it's just set so it can be read e.g. in egui_flex, for advanced layouting. So this issue must be something else. Can you try to make a minimal reproduction?

@UnknownSuperficialNight

I made a discussion about this thinking it was intended but after testing I figured I don't think it is.

Egui currently does absolutely nothing with the intrinsic size, it's just set so it can be read e.g. in egui_flex, for advanced layouting. So this issue must be something else. Can you try to make a minimal reproduction?

Here is my discussion it has a small example including a video.

@crumblingstatue
Copy link
Contributor Author

Can you try to make a minimal reproduction?

Here is a minimal reproduction

use eframe::{NativeOptions, egui};

fn main() {
    let mut strbuf = String::from(
        "Once upon a time there was a very very long string that went out to the store to get some chocolate milk",
    );
    eframe::run_simple_native("footest", NativeOptions::default(), move |ctx, _frame| {
        egui::SidePanel::right("right_panel").show(ctx, |ui| {
            ui.text_edit_singleline(&mut strbuf);
        });
    })
    .unwrap();
}

eframe 0.29
image

eframe 0.30
image

@crumblingstatue
Copy link
Contributor Author

I did a bisect, and it turns out the cause is #3660 , so I apologize for blaming the wrong pull request.
In particular, it seems like this part is responsible:

@@ -720,6 +721,16 @@ impl<'t> TextEdit<'t> {
                 }
             }

+            // Allocate additional space if edits were made this frame that changed the size. This is important so that,
+            // if there's a ScrollArea, it can properly scroll to the cursor.
+            let extra_size = galley.size() - rect.size();
+            if extra_size.x > 0.0 || extra_size.y > 0.0 {
+                ui.allocate_rect(
+                    Rect::from_min_size(outer_rect.max, extra_size),
+                    Sense::hover(),
+                );
+            }
+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

3 participants