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

TextEdit adds extra spacing in nested layouts #3709

Closed
valadaptive opened this issue Dec 16, 2023 · 2 comments
Closed

TextEdit adds extra spacing in nested layouts #3709

valadaptive opened this issue Dec 16, 2023 · 2 comments
Labels
bug Something is broken

Comments

@valadaptive
Copy link
Contributor

valadaptive commented Dec 16, 2023

Describe the bug
I often nest left-to-right and right-to-left layouts inside each other in order to place elements along the ends.

When a TextEdit is the last element in such a layout, it adds extra padding that isn't present when it neighbors another widget directly:

image

I've set the item_spacing to 0 to make the effect more clear.

In the top layout, the button on the right is placed first, using a right-to-left layout to make it the rightmost element. Then a left-to-right layout takes up the remaining space, and the label and textbox are placed inside it. This makes the textbox the last element within that nested layout, and there's thus a space between it and the button.

In the one below it, the label, textbox, and button are all part of the same left-to-right layout. This results in there being no extra spacing between them, as intended.

This nesting of layouts seems to be the only way to robustly handle resizing, so it's important for my use case:

Peek 2023-12-16 02-44

To Reproduce

Demo snippet
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
    let _ = ui.button("Button");

    ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
        ui.label("Label");
        let mut buf = String::from("This is some text");
        let _ = ui.text_edit_singleline(&mut buf);
    });
});

ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
    ui.label("Label");
    let mut buf = String::from("This is some text");
    let _ = ui.text_edit_singleline(&mut buf);
    let _ = ui.button("Button");
});

Expected behavior
Both layouts should have the same spacing.

Screenshots
See above

Additional context
I've traced this problem back to this commit, which subtracts off a margin from the TextEdit's size.

@valadaptive valadaptive added the bug Something is broken label Dec 16, 2023
@toymil
Copy link

toymil commented Feb 2, 2024

This happens when a TextEdit is last in a Grid cell too, you can actually see this directly in the egui online demo:

Snipaste_2024-02-02_21-44-05

@toymil
Copy link

toymil commented Feb 22, 2024

This is fixed in #4005 (v0.26.1)

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

2 participants