-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
dda2b26
84007ae
dce688b
25daf95
8866ba5
87817b3
279209e
e0f9e6c
bb78971
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
TextWrapMode::Wrap | ||
} else { | ||
TextWrapMode::Extend | ||
}); | ||
let wrap_width = if ui.layout().horizontal_justify() { | ||
available_width | ||
} else { | ||
|
@@ -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 | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is now only run for the |
||
LayoutJob::simple(text, font_id_clone.clone(), text_color, wrap_width) | ||
} else { | ||
LayoutJob::simple_singleline(text, font_id_clone.clone(), text_color) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think single-line text-edits should always use |
||
}; | ||
painter.galley(rect.min, galley, hint_text_color); | ||
} | ||
|
There was a problem hiding this comment.
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 wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 withsingleline()
andmultiline()
, 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.