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::clip_text is being ignored for singleline text #5511

Open
Barugon opened this issue Dec 22, 2024 · 2 comments
Open

TextEdit::clip_text is being ignored for singleline text #5511

Barugon opened this issue Dec 22, 2024 · 2 comments
Labels
bug Something is broken

Comments

@Barugon
Copy link
Contributor

Barugon commented Dec 22, 2024

Describe the bug
TextEdit::clip_text is being ignored for singleline text. With clip_text set to true, the TextEdit widget expands when the text gets too long.

Here are a couple screenshots showing the behavior.

Before adding text:
Screenshot From 2024-12-22 00-17-11

Pasting in some long text:
Screenshot From 2024-12-22 00-17-53

If I maximize the window (also odd behavior since I have window resizing disabled) then you can see the full size of the TextEdit:
Screenshot From 2024-12-22 00-18-24

This behavior started with v0.30 and still exists in the main branch.

[edit] This may be related to #5500.

@Barugon Barugon added the bug Something is broken label Dec 22, 2024
@emabee
Copy link

emabee commented Jan 13, 2025

Another example of likely the same issue is here:

grafik

The code is here:

use anyhow::{anyhow, Result};
use eframe::{run_native, App, Frame, NativeOptions};
use egui::{CentralPanel, Context, ScrollArea, TextEdit, TopBottomPanel, ViewportBuilder};
use egui_extras::install_image_loaders;
use std::process::ExitCode;

fn main() -> ExitCode {
    match run() {
        Ok(()) => ExitCode::SUCCESS,
        Err(e) => {
            println!("{e:?}");
            ExitCode::FAILURE
        }
    }
}

fn run() -> Result<()> {
    match run_native(
        "repro_textedit_issue",
        NativeOptions {
            // viewport = native OS window
            viewport: ViewportBuilder::default()
                .with_inner_size([650.0, 300.0])
                .with_min_inner_size([650.0, 300.0]),
            ..Default::default()
        },
        Box::new(|cc| {
            install_image_loaders(&cc.egui_ctx);
            Ok(Box::new(UiApp::new()))
        }),
    ) {
        Ok(()) => Ok(()),
        Err(e) => Err(anyhow!("Couldn't start GUI, caused by {e}")),
    }
}

pub struct UiApp {
    data: Vec<(String, String)>,
}
impl UiApp {
    pub fn new() -> Self {
        UiApp {
            data: vec![
                (
                    "1_short".to_string(), //
                    "a_short".to_string(),
                ),
                (
                    "2_short".to_string(),
                    "b_longlonglonglonglonglonglonglonglong".to_string(),
                ),
                (
                    "3_longlonglonglonglonglonglonglong".to_string(),
                    "c_short".to_string(),
                ),
                (
                    "4_longlonglonglonglonglonglonglong".to_string(),
                    "d_longlonglonglonglonglonglonglonglonglonglonglong".to_string(),
                ),
            ],
        }
    }

    fn add_textedits(&mut self, ui: &mut egui::Ui, hide: bool) {
        ui.label(format!(
            "All four lines should have the same indentations as the first. This is {} password().",
            if hide { "with" } else { "without" },
        ));
        for dat in &mut self.data {
            ui.horizontal(|ui| {
                ui.add(
                    TextEdit::singleline(&mut dat.0)
                        .desired_width(100.)
                        .clip_text(true),
                );

                ui.add(
                    TextEdit::singleline(&mut dat.1)
                        .desired_width(100.)
                        .clip_text(true)
                        .password(hide),
                );
                ui.label("end of line");
            });
        }
    }
}

impl App for UiApp {
    fn update(&mut self, ctx: &Context, _frame: &mut Frame) {
        TopBottomPanel::top("top").show(ctx, |ui| {
            ui.label("the top");
        });
        TopBottomPanel::bottom("bottom").show(ctx, |ui| {
            ui.label("the bottom");
        });

        CentralPanel::default().show(ctx, |ui| {
            ScrollArea::both().show(ui, |ui| {
                self.add_textedits(ui, false);
                ui.add_space(20.);
                self.add_textedits(ui, true);
            });
        });
    }
}

@MetaflameDragon
Copy link

Dealt with similar issues in a modal (just a single-line TextEdit placed directly into a modal)

Looks like it's a duplicate of #5500

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