Skip to content
18 changes: 8 additions & 10 deletions crates/kas-core/src/event/cx/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,14 @@ impl<'a> EventCx<'a> {
}
_ => (),
},
PointerEntered { kind, .. } => {
if kind == PointerKind::Mouse {
self.handle_pointer_entered()
}
}
PointerLeft { kind, .. } => {
if kind == PointerKind::Mouse {
self.handle_pointer_left(win.as_node(data))
}
}
PointerEntered {
kind: PointerKind::Mouse,
..
} => self.handle_pointer_entered(),
PointerLeft {
kind: PointerKind::Mouse,
..
} => self.handle_pointer_left(win.as_node(data)),
MouseWheel { delta, .. } => self.handle_mouse_wheel(win.as_node(data), delta),
PointerButton {
state,
Expand Down
29 changes: 14 additions & 15 deletions crates/kas-widgets/src/edit/edit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//! The [`EditBoxCore`] widget

use super::editor::{Component, EventAction};
use super::*;
use crate::edit::highlight::{Highlighter, Plain};
use kas::event::CursorIcon;
Expand Down Expand Up @@ -121,12 +122,12 @@ mod EditBoxCore {
impl Viewport for Self {
#[inline]
fn content_size(&self) -> Size {
self.editor.content_size()
self.editor.part().content_size()
}

#[inline]
fn draw_with_offset(&self, mut draw: DrawCx, rect: Rect, offset: Offset) {
self.editor.draw_with_offset(draw, rect, offset);
self.editor.part().draw_with_offset(draw, rect, offset);
}
}

Expand Down Expand Up @@ -173,34 +174,32 @@ mod EditBoxCore {
self.guard.update(&mut self.editor.0, cx, data);
}

self.editor.prepare(cx);
self.editor.prepare();
}

fn handle_event(&mut self, cx: &mut EventCx, data: &G::Data, event: Event) -> IsUsed {
let mut result = Used;
match self.editor.handle_event(cx, event) {
EventAction::Unused => Unused,
EventAction::Used | EventAction::Cursor => Used,
EventAction::Unused => return Unused,
EventAction::Used | EventAction::Cursor | EventAction::Preedit => return Used,
EventAction::FocusGained => {
self.guard.focus_gained(&mut self.editor.0, cx, data);
self.editor.prepare(cx);
Used
}
EventAction::FocusLost => {
self.guard.focus_lost(&mut self.editor.0, cx, data);
self.editor.prepare(cx);
Used
}
EventAction::Activate(code) => {
cx.depress_with_key(&self, code);
let result = self.guard.activate(&mut self.editor.0, cx, data);
self.editor.prepare(cx);
result
result = self.guard.activate(&mut self.editor.0, cx, data);
}
EventAction::Edit => {
self.call_guard_edit(cx, data);
Used
return Used;
}
}

self.editor.prepare_and_scroll(cx);
result
}

fn handle_messages(&mut self, cx: &mut EventCx, data: &G::Data) {
Expand Down Expand Up @@ -277,7 +276,7 @@ mod EditBoxCore {
#[inline]
pub fn call_guard_activate(&mut self, cx: &mut EventCx, data: &G::Data) {
self.guard.activate(&mut self.editor.0, cx, data);
self.editor.prepare(cx);
self.editor.prepare_and_scroll(cx);
}

/// Call the [`EditGuard`]'s `edit` method
Expand All @@ -287,7 +286,7 @@ mod EditBoxCore {
fn call_guard_edit(&mut self, cx: &mut EventCx, data: &G::Data) {
self.editor.clear_error();
self.guard.edit(&mut self.editor.0, cx, data);
self.editor.prepare(cx);
self.editor.prepare_and_scroll(cx);
}
}
}
Expand Down
Loading