mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix menubar mouse behaviour
This commit is contained in:
parent
0a35a31e1b
commit
1ba00032a1
@ -416,6 +416,8 @@ impl Cursive {
|
|||||||
|
|
||||||
fn layout(&mut self) {
|
fn layout(&mut self) {
|
||||||
let size = self.screen_size();
|
let size = self.screen_size();
|
||||||
|
let offset = if self.menubar.autohide { 0 } else { 1 };
|
||||||
|
let size = size.saturating_sub((0, offset));
|
||||||
self.screen_mut().layout(size);
|
self.screen_mut().layout(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,7 +433,6 @@ impl Cursive {
|
|||||||
|
|
||||||
// Draw the currently active screen
|
// Draw the currently active screen
|
||||||
// If the menubar is active, nothing else can be.
|
// If the menubar is active, nothing else can be.
|
||||||
let offset = if self.menubar.autohide { 0 } else { 1 };
|
|
||||||
// Draw the menubar?
|
// Draw the menubar?
|
||||||
if self.menubar.visible() {
|
if self.menubar.visible() {
|
||||||
let printer = printer.sub_printer(
|
let printer = printer.sub_printer(
|
||||||
@ -444,8 +445,8 @@ impl Cursive {
|
|||||||
|
|
||||||
let selected = self.menubar.receive_events();
|
let selected = self.menubar.receive_events();
|
||||||
|
|
||||||
let printer =
|
let offset = if self.menubar.autohide { 0 } else { 1 };
|
||||||
printer.sub_printer(Vec2::new(0, offset), printer.size, !selected);
|
let printer = printer.offset((0, offset), !selected);
|
||||||
let id = self.active_screen;
|
let id = self.active_screen;
|
||||||
self.screens[id].draw(&printer);
|
self.screens[id].draw(&printer);
|
||||||
}
|
}
|
||||||
@ -511,6 +512,20 @@ impl Cursive {
|
|||||||
self.clear();
|
self.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Event::Mouse {
|
||||||
|
event,
|
||||||
|
position,
|
||||||
|
offset: _,
|
||||||
|
} = event
|
||||||
|
{
|
||||||
|
if event.grabs_focus() && !self.menubar.autohide
|
||||||
|
&& !self.menubar.has_submenu()
|
||||||
|
&& position.y == 0
|
||||||
|
{
|
||||||
|
self.select_menubar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Event dispatch order:
|
// Event dispatch order:
|
||||||
// * Focused element:
|
// * Focused element:
|
||||||
// * Menubar (if active)
|
// * Menubar (if active)
|
||||||
@ -519,7 +534,8 @@ impl Cursive {
|
|||||||
if self.menubar.receive_events() {
|
if self.menubar.receive_events() {
|
||||||
self.menubar.on_event(event).process(self);
|
self.menubar.on_event(event).process(self);
|
||||||
} else {
|
} else {
|
||||||
match self.screen_mut().on_event(event.clone()) {
|
let offset = if self.menubar.autohide { 0 } else { 1 };
|
||||||
|
match self.screen_mut().on_event(event.relativized((0, offset))) {
|
||||||
// If the event was ignored,
|
// If the event was ignored,
|
||||||
// it is our turn to play with it.
|
// it is our turn to play with it.
|
||||||
EventResult::Ignored => self.on_event(event),
|
EventResult::Ignored => self.on_event(event),
|
||||||
|
@ -66,6 +66,11 @@ impl Menubar {
|
|||||||
self.state == State::Selected
|
self.state == State::Selected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True if some submenus are visible.
|
||||||
|
pub fn has_submenu(&self) -> bool {
|
||||||
|
self.state == State::Submenu
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if we should be drawn.
|
/// Returns `true` if we should be drawn.
|
||||||
pub fn visible(&self) -> bool {
|
pub fn visible(&self) -> bool {
|
||||||
!self.autohide || self.state != State::Inactive
|
!self.autohide || self.state != State::Inactive
|
||||||
@ -232,7 +237,7 @@ impl View for Menubar {
|
|||||||
|
|
||||||
fn on_event(&mut self, event: Event) -> EventResult {
|
fn on_event(&mut self, event: Event) -> EventResult {
|
||||||
match event {
|
match event {
|
||||||
Event::Key(Key::Esc) if self.autohide => {
|
Event::Key(Key::Esc) => {
|
||||||
self.hide();
|
self.hide();
|
||||||
return EventResult::with_cb(|s| s.clear());
|
return EventResult::with_cb(|s| s.clear());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user