Get rid of has_widget_info
and push events directly where it makes sense.
This commit is contained in:
parent
fa18727933
commit
131525536b
3 changed files with 12 additions and 24 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{util::undoer::Undoer, *};
|
||||
use crate::{output::OutputEvent, util::undoer::Undoer, *};
|
||||
use epaint::{text::cursor::*, *};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue