Rename TextEdit::enabled to TextEdit::interactive.

This commit is contained in:
Emil Ernerfeldt 2021-10-17 22:12:27 +02:00
parent fe76382141
commit 8a47019c1a
2 changed files with 21 additions and 13 deletions

View file

@ -27,6 +27,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* Smaller and nicer color picker. * Smaller and nicer color picker.
* `ScrollArea` will auto-shrink to content size unless told otherwise using `ScollArea::auto_shrink`. * `ScrollArea` will auto-shrink to content size unless told otherwise using `ScollArea::auto_shrink`.
* By default, `Slider`'s `clamp_to_range` is set to true. * By default, `Slider`'s `clamp_to_range` is set to true.
* Rename `TextEdit::enabled` to `TextEdit::interactive`.
### Fixed 🐛 ### Fixed 🐛
* Fix wrongly sized multiline `TextEdit` in justified layouts. * Fix wrongly sized multiline `TextEdit` in justified layouts.

View file

@ -264,7 +264,7 @@ pub struct TextEdit<'t> {
password: bool, password: bool,
frame: bool, frame: bool,
multiline: bool, multiline: bool,
enabled: bool, interactive: bool,
desired_width: Option<f32>, desired_width: Option<f32>,
desired_height_rows: usize, desired_height_rows: usize,
lock_focus: bool, lock_focus: bool,
@ -294,7 +294,7 @@ impl<'t> TextEdit<'t> {
password: false, password: false,
frame: true, frame: true,
multiline: true, multiline: true,
enabled: true, interactive: true,
desired_width: None, desired_width: None,
desired_height_rows: 4, desired_height_rows: 4,
lock_focus: false, lock_focus: false,
@ -378,12 +378,19 @@ impl<'t> TextEdit<'t> {
self self
} }
/// Default is `true`. If set to `false` then you cannot edit the text. /// Default is `true`. If set to `false` then you cannot interact with the text (neither edit or select it).
pub fn enabled(mut self, enabled: bool) -> Self { ///
self.enabled = enabled; /// Consider using [`Ui::add_enabled`] instead to also give the `TextEdit` a greyed out look.
pub fn interactive(mut self, interactive: bool) -> Self {
self.interactive = interactive;
self self
} }
#[deprecated = "Use TextEdit::interactive or ui.add_enabled instead"]
pub fn enabled(self, enabled: bool) -> Self {
self.interactive(enabled)
}
/// Default is `true`. If set to `false` there will be no frame showing that this is editable text! /// Default is `true`. If set to `false` there will be no frame showing that this is editable text!
pub fn frame(mut self, frame: bool) -> Self { pub fn frame(mut self, frame: bool) -> Self {
self.frame = frame; self.frame = frame;
@ -437,7 +444,7 @@ impl<'t> Widget for TextEdit<'t> {
fn ui(self, ui: &mut Ui) -> Response { fn ui(self, ui: &mut Ui) -> Response {
let is_mutable = self.text.is_mutable(); let is_mutable = self.text.is_mutable();
let frame = self.frame; let frame = self.frame;
let enabled = self.enabled; let interactive = self.interactive;
let where_to_put_background = ui.painter().add(Shape::Noop); let where_to_put_background = ui.painter().add(Shape::Noop);
let margin = Vec2::new(4.0, 2.0); let margin = Vec2::new(4.0, 2.0);
@ -447,7 +454,7 @@ impl<'t> Widget for TextEdit<'t> {
let id = response.id; let id = response.id;
let frame_rect = response.rect.expand2(margin); let frame_rect = response.rect.expand2(margin);
ui.allocate_space(frame_rect.size()); ui.allocate_space(frame_rect.size());
if enabled { if interactive {
response |= ui.interact(frame_rect, id, Sense::click()) response |= ui.interact(frame_rect, id, Sense::click())
} }
if response.clicked() && !response.lost_focus() { if response.clicked() && !response.lost_focus() {
@ -520,7 +527,7 @@ impl<'t> TextEdit<'t> {
password, password,
frame: _, frame: _,
multiline, multiline,
enabled, interactive,
desired_width, desired_width,
desired_height_rows, desired_height_rows,
lock_focus, lock_focus,
@ -584,7 +591,7 @@ impl<'t> TextEdit<'t> {
}); });
let mut state = ui.memory().id_data.get_or_default::<State>(id).clone(); let mut state = ui.memory().id_data.get_or_default::<State>(id).clone();
let sense = if enabled { let sense = if interactive {
Sense::click_and_drag() Sense::click_and_drag()
} else { } else {
Sense::hover() Sense::hover()
@ -592,7 +599,7 @@ impl<'t> TextEdit<'t> {
let mut response = ui.interact(rect, id, sense); let mut response = ui.interact(rect, id, sense);
let painter = ui.painter_at(rect); let painter = ui.painter_at(rect);
if enabled { if interactive {
if let Some(pointer_pos) = ui.input().pointer.interact_pos() { if let Some(pointer_pos) = ui.input().pointer.interact_pos() {
// TODO: triple-click to select whole paragraph // TODO: triple-click to select whole paragraph
// TODO: drag selected text to either move or clone (ctrl on windows, alt on mac) // TODO: drag selected text to either move or clone (ctrl on windows, alt on mac)
@ -642,13 +649,13 @@ impl<'t> TextEdit<'t> {
} }
} }
if response.hovered() && enabled { if response.hovered() && interactive {
ui.output().cursor_icon = CursorIcon::Text; ui.output().cursor_icon = CursorIcon::Text;
} }
let mut text_cursor = None; let mut text_cursor = None;
let prev_text_cursor = state.cursorp; let prev_text_cursor = state.cursorp;
if ui.memory().has_focus(id) && enabled { if ui.memory().has_focus(id) && interactive {
ui.memory().lock_focus(id, lock_focus); ui.memory().lock_focus(id, lock_focus);
let mut cursorp = state let mut cursorp = state
@ -888,7 +895,7 @@ impl<'t> TextEdit<'t> {
&cursorp.primary, &cursorp.primary,
); );
if enabled { if interactive {
ui.ctx().output().text_cursor_pos = Some( ui.ctx().output().text_cursor_pos = Some(
galley galley
.pos_from_cursor(&cursorp.primary) .pos_from_cursor(&cursorp.primary)