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

Apply TextWrapMode::Extend in TextEdit #4838

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ impl<'t> TextEdit<'t> {
const MIN_WIDTH: f32 = 24.0; // Never make a [`TextEdit`] more narrow than this.
let available_width = (ui.available_width() - margin.sum().x).at_least(MIN_WIDTH);
let desired_width = desired_width.unwrap_or_else(|| ui.spacing().text_edit_width);

let wrap_mode = ui.style().wrap_mode.unwrap_or(if multiline {
Copy link
Owner

Choose a reason for hiding this comment

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

Should we really use TextWrapMode::Truncate if set? I don't think that will work very well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TextWrapMode::Truncate

I made some changes, but I'm not sure if the changes will work everywhere.

I haven't reviewed the TextWrapMode::Truncate issue.
I'm not sure how TextWrapMode::Truncate is supposed to work with singleline() and multiline(), and what it's intended to do.
How about handling the TextWrapMode::Truncate issue in a new commit?

You can drop this and create a new one.

TextWrapMode::Wrap
} else {
TextWrapMode::Extend
});
let wrap_width = if ui.layout().horizontal_justify() {
available_width
} else {
Expand All @@ -491,6 +497,11 @@ impl<'t> TextEdit<'t> {
let mut default_layouter = move |ui: &Ui, text: &str, wrap_width: f32| {
let text = mask_if_password(password, text);
let layout_job = if multiline {
let wrap_width = if wrap_mode == TextWrapMode::Extend {
f32::INFINITY
} else {
wrap_width
};
Copy link
Owner

Choose a reason for hiding this comment

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

This logic is now only run for the default_layouter, while custom layouters gets the previous wrap_width which ignores wrap_mode.

LayoutJob::simple(text, font_id_clone.clone(), text_color, wrap_width)
} else {
LayoutJob::simple_singleline(text, font_id_clone.clone(), text_color)
Expand Down Expand Up @@ -670,17 +681,12 @@ impl<'t> TextEdit<'t> {
let galley = if multiline {
hint_text.into_galley(
ui,
Some(TextWrapMode::Wrap),
Some(wrap_mode),
desired_inner_size.x,
hint_text_font_id,
)
} else {
hint_text.into_galley(
ui,
Some(TextWrapMode::Extend),
f32::INFINITY,
hint_text_font_id,
)
hint_text.into_galley(ui, Some(wrap_mode), f32::INFINITY, hint_text_font_id)
Copy link
Owner

Choose a reason for hiding this comment

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

I think single-line text-edits should always use Extend, otherwise they are not single-line

};
painter.galley(rect.min, galley, hint_text_color);
}
Expand Down
Loading