Skip to content

Commit

Permalink
tell response if textbox lost focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Feb 15, 2024
1 parent e8450e3 commit aa7deb9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/yakui-widgets/src/widgets/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ pub struct TextBoxWidget {
cursor: usize,
text_layout: Option<IgnoreDebug<Rc<RefCell<Layout>>>>,
activated: bool,
lost_focus: bool,
}

pub struct TextBoxResponse {
pub text: Option<String>,
/// Whether the user pressed "Enter" in this box
pub activated: bool,
/// Whether the box lost focus
pub lost_focus: bool,
}

impl Widget for TextBoxWidget {
Expand All @@ -78,6 +81,7 @@ impl Widget for TextBoxWidget {
cursor: 0,
text_layout: None,
activated: false,
lost_focus: false,
}
}

Expand Down Expand Up @@ -113,6 +117,7 @@ impl Widget for TextBoxWidget {
Self::Response {
text: self.updated_text.take(),
activated: mem::take(&mut self.activated),
lost_focus: mem::take(&mut self.lost_focus),
}
}

Expand Down Expand Up @@ -148,6 +153,9 @@ impl Widget for TextBoxWidget {
match event {
WidgetEvent::FocusChanged(focused) => {
self.selected = *focused;
if !*focused {
self.lost_focus = true;
}
EventResponse::Sink
}

Expand Down

0 comments on commit aa7deb9

Please sign in to comment.