Skip to content

Commit

Permalink
Fix bugs with textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik committed Aug 13, 2022
1 parent 35ba460 commit 4911532
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
5 changes: 2 additions & 3 deletions crates/vizia_core/resources/themes/default_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ textbox:hover {
background-color: #f6f6f6;
}

textbox:focus {
textbox:checked {
border-color: #4c00ff;
}

textbox:focus .textbox_content {
textbox:checked .textbox_content {
caret-color: #ff0000;
selection-color: #6464c888;
}
Expand Down
7 changes: 2 additions & 5 deletions crates/vizia_core/src/context/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl<'a> BackendContext<'a> {
self.style().needs_restyle = true;
}

if matches!(*code, Code::Enter | Code::NumpadEnter | Code::Space) {
if matches!(*code, Code::Space) {
self.0.triggered = self.0.focused;
self.0.with_current(self.0.focused, |cx| {
cx.emit(WindowEvent::TriggerDown { mouse: false })
Expand All @@ -501,10 +501,7 @@ impl<'a> BackendContext<'a> {
self.0.event_queue.push_back(Event::new(event).target(self.0.focused));
}
WindowEvent::KeyUp(_, _) | WindowEvent::CharInput(_) => {
if matches!(
event,
WindowEvent::KeyUp(Code::Enter | Code::NumpadEnter | Code::Space, _)
) {
if matches!(event, WindowEvent::KeyUp(Code::Space, _)) {
self.0.with_current(self.0.triggered, |cx| {
cx.emit(WindowEvent::TriggerUp { mouse: false })
});
Expand Down
33 changes: 33 additions & 0 deletions crates/vizia_core/src/views/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,39 @@ where
}
}

WindowEvent::MouseDown(button) if *button == MouseButton::Left => {
if !cx.is_over() {
cx.emit(TextEvent::Submit(false));
if let Some(source) = cx.data::<L::Source>() {
let text = self.lens.view(source, |t| {
if let Some(t) = t {
t.to_string()
} else {
"".to_owned()
}
});

cx.emit(TextEvent::SelectAll);
cx.emit(TextEvent::InsertText(text));
};
cx.release();
cx.set_checked(false);

// Forward event to hovered
cx.event_queue.push_back(
Event::new(WindowEvent::MouseDown(*button)).target(cx.hovered()),
);
}
}

WindowEvent::FocusIn => {
cx.emit(TextEvent::StartEdit);
}

WindowEvent::FocusOut => {
cx.emit(TextEvent::EndEdit);
}

WindowEvent::TriggerUp { .. } => {
cx.unlock_cursor_icon();
}
Expand Down

0 comments on commit 4911532

Please sign in to comment.