Skip to content

Commit

Permalink
Get rid of has_widget_info and push events directly where it makes …
Browse files Browse the repository at this point in the history
…sense.
  • Loading branch information
ndarilek committed May 19, 2021
1 parent ea79d59 commit 87bd38d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
3 changes: 1 addition & 2 deletions egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ impl CtxRef {
drag_released: false,
is_pointer_button_down_on: false,
interact_pointer_pos: None,
changed: false, // must be set by the widget itself
has_widget_info: false, // must be set by the widget itself
changed: false, // must be set by the widget itself
};

if !enabled || !sense.focusable || !layer_id.allow_interaction() {
Expand Down
12 changes: 0 additions & 12 deletions egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub struct Response {
/// e.g. the slider was dragged, text was entered in a `TextEdit` etc.
/// Always `false` for something like a `Button`.
pub(crate) changed: bool,
/// Has a `WidgetInfo` but isn't covered by some other case (E.g. `changed`, `clicked`.)
pub(crate) has_widget_info: bool,
}

impl std::fmt::Debug for Response {
Expand All @@ -86,7 +84,6 @@ impl std::fmt::Debug for Response {
is_pointer_button_down_on,
interact_pointer_pos,
changed,
has_widget_info,
} = self;
f.debug_struct("Response")
.field("layer_id", layer_id)
Expand All @@ -102,7 +99,6 @@ impl std::fmt::Debug for Response {
.field("is_pointer_button_down_on", is_pointer_button_down_on)
.field("interact_pointer_pos", interact_pointer_pos)
.field("changed", changed)
.field("has_widget_info", has_widget_info)
.finish()
}
}
Expand Down Expand Up @@ -441,13 +437,6 @@ impl Response {
Some(OutputEvent::FocusGained(make_info()))
} else if self.changed {
Some(OutputEvent::ValueChanged(make_info()))
} else if self.has_widget_info {
let info = make_info();
if info.primary_cursor.is_some() && info.secondary_cursor.is_some() {
Some(OutputEvent::TextSelectionChanged(info))
} else {
None
}
} else {
None
};
Expand Down Expand Up @@ -490,7 +479,6 @@ impl Response {
|| other.is_pointer_button_down_on,
interact_pointer_pos: self.interact_pointer_pos.or(other.interact_pointer_pos),
changed: self.changed || other.changed,
has_widget_info: self.has_widget_info || other.has_widget_info,
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions egui/src/widgets/text_edit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{util::undoer::Undoer, *};
use crate::{output::OutputEvent, util::undoer::Undoer, *};
use epaint::{text::cursor::*, *};

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -505,7 +505,6 @@ impl<'t> TextEdit<'t> {
&& text_to_insert != "\r"
{
let mut ccursor = delete_selected(text, &mut prev_text, &cursorp);

insert_text(&mut ccursor, text, &mut prev_text, text_to_insert);
Some(CCursorPair::one(ccursor))
} else {
Expand Down Expand Up @@ -664,14 +663,16 @@ impl<'t> TextEdit<'t> {
if response.changed {
response.widget_info(|| WidgetInfo::text_edit(&*text, &*prev_text));
} else if let Some(text_cursor) = text_cursor {
response.has_widget_info = true;
response.widget_info(|| {
WidgetInfo::text_selection_changed(
text_cursor.primary.ccursor.index,
text_cursor.secondary.ccursor.index,
&*text,
)
});
let info = WidgetInfo::text_selection_changed(
text_cursor.primary.ccursor.index,
text_cursor.secondary.ccursor.index,
&*text,
);
response
.ctx
.output()
.events
.push(OutputEvent::TextSelectionChanged(info));
}
response
}
Expand Down

0 comments on commit 87bd38d

Please sign in to comment.