Skip to content

Commit

Permalink
Merge pull request #236 from kas-gui/work
Browse files Browse the repository at this point in the history
More event-handling fixes
  • Loading branch information
dhardy authored Aug 9, 2021
2 parents 5b27ed0 + a5d483e commit 76b1815
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
cargo build --release --manifest-path examples/mandlebrot/Cargo.toml
- name: Prepare
run: |
strip target/release/examples/layout target/release/examples/gallery target/release/mandlebrot
mv target/release/mandlebrot target/release/examples/
strip target/release/examples/layout.exe target/release/examples/gallery.exe target/release/mandlebrot.exe
mv target/release/mandlebrot.exe target/release/examples/
xcopy res target\release\examples\res /e/k/c/i/y
- name: Upload
uses: actions/upload-artifact@v2
Expand Down
8 changes: 6 additions & 2 deletions crates/kas-core/src/event/manager/mgr_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ impl<'a> Manager<'a> {

if self.state.config.borrow().mouse_nav_focus() {
if let Some(w) = widget.find_leaf(start_id) {
self.set_nav_focus(w.id(), false);
if w.key_nav() {
self.set_nav_focus(w.id(), false);
}
}
}
}
Expand All @@ -608,7 +610,9 @@ impl<'a> Manager<'a> {

if self.state.config.borrow().touch_nav_focus() {
if let Some(w) = widget.find_leaf(start_id) {
self.set_nav_focus(w.id(), false);
if w.key_nav() {
self.set_nav_focus(w.id(), false);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/kas-widgets/src/editbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,11 @@ impl<G: EditGuard + 'static> event::Handler for EditField<G> {
Response::None
}
TextInputAction::Cursor(coord, anchor, clear, repeats) => {
self.set_edit_pos_from_coord(mgr, coord);
if self.has_key_focus || mgr.request_sel_focus(self.id()) {
request_focus(self, mgr);
if self.has_key_focus {
self.set_edit_pos_from_coord(mgr, coord);
if anchor {
self.selection.set_anchor();
request_focus(self, mgr);
}
if clear {
self.selection.set_empty();
Expand Down
17 changes: 11 additions & 6 deletions crates/kas-widgets/src/menu/menubar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct MenuBar<W: Menu, D: Directional = kas::dir::Right> {
core: CoreData,
#[widget]
pub bar: List<D, SubMenu<D::Flipped, W>>,
ideal: Size,
// Open mode. Used to close with click on root only when previously open.
opening: bool,
delayed_open: Option<WidgetId>,
Expand All @@ -46,6 +47,7 @@ impl<W: Menu, D: Directional> MenuBar<W, D> {
MenuBar {
core: Default::default(),
bar: List::new_with_direction(direction, menus),
ideal: Size::ZERO,
opening: false,
delayed_open: None,
}
Expand All @@ -55,11 +57,16 @@ impl<W: Menu, D: Directional> MenuBar<W, D> {
// NOTE: we could use layout(single) except for alignment
impl<W: Menu, D: Directional> Layout for MenuBar<W, D> {
fn size_rules(&mut self, size_handle: &mut dyn SizeHandle, axis: AxisInfo) -> SizeRules {
self.bar.size_rules(size_handle, axis)
let rules = self.bar.size_rules(size_handle, axis);
self.ideal.set_component(axis, rules.ideal_size());
rules
}

fn set_rect(&mut self, mgr: &mut Manager, rect: Rect, _: AlignHints) {
fn set_rect(&mut self, mgr: &mut Manager, rect: Rect, align: AlignHints) {
self.core_data_mut().rect = rect;
let rect = align
.complete(Align::Default, Align::Default)
.aligned_rect(self.ideal, rect);
let align = AlignHints::new(Some(Align::Default), Some(Align::Default));
self.bar.set_rect(mgr, rect, align);
}
Expand Down Expand Up @@ -99,8 +106,6 @@ impl<W: Menu<Msg = M>, D: Directional, M> event::Handler for MenuBar<W, D> {
&& mgr.request_grab(self.id(), source, coord, GrabMode::Grab, None)
{
mgr.set_grab_depress(source, Some(start_id));
self.find_leaf(start_id)
.map(|w| mgr.next_nav_focus(w, false, false));
self.opening = false;
let delay = mgr.config().menu_delay();
if self.rect().contains(coord) {
Expand Down Expand Up @@ -129,13 +134,13 @@ impl<W: Menu<Msg = M>, D: Directional, M> event::Handler for MenuBar<W, D> {
} => {
mgr.set_grab_depress(source, cur_id);
if let Some(id) = cur_id {
if self.is_ancestor_of(id) {
mgr.set_nav_focus(id, false);
if id != self.id() && self.is_ancestor_of(id) {
// We instantly open a sub-menu on motion over the bar,
// but delay when over a sub-menu (most intuitive?)
if self.rect().contains(coord) {
self.set_menu_path(mgr, Some(id));
} else {
mgr.set_nav_focus(id, false);
self.delayed_open = Some(id);
let delay = mgr.config().menu_delay();
mgr.update_on_timer(delay, self.id(), 0);
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-widgets/src/scroll_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ impl<T: FormattableText + 'static> event::Handler for ScrollLabel<T> {
delta => Response::Pan(delta),
},
TextInputAction::Cursor(coord, anchor, clear, repeats) => {
self.set_edit_pos_from_coord(mgr, coord);
if mgr.request_sel_focus(self.id()) {
if (clear && repeats <= 1) || mgr.request_sel_focus(self.id()) {
self.set_edit_pos_from_coord(mgr, coord);
if anchor {
self.selection.set_anchor();
}
Expand Down

0 comments on commit 76b1815

Please sign in to comment.