Enable mouse scrolling in TabViews (#363)

* Forward events from a TabView to the selected Tab

* Forward mouse events to the front screen instead of the focused screen
This commit is contained in:
algon
2021-01-06 02:37:00 +09:00
committed by GitHub
parent ef6726f6f9
commit cb72870fc2
2 changed files with 10 additions and 2 deletions

View File

@@ -247,8 +247,7 @@ impl View for Layout {
}
if position.y < self.last_size.y.saturating_sub(2 + cmdline_height) {
if let Some(ref id) = self.focus {
let screen = self.views.get_mut(id).unwrap();
if let Some(screen) = self.get_current_screen_mut() {
screen.view.on_event(event);
}
} else if position.y < self.last_size.y - cmdline_height {

View File

@@ -2,6 +2,7 @@ use std::cmp::{max, min};
use std::collections::HashMap;
use cursive::align::HAlign;
use cursive::event::{Event, EventResult};
use cursive::theme::{ColorStyle, ColorType, PaletteColor};
use cursive::traits::View;
use cursive::{Cursive, Printer, Vec2};
@@ -100,6 +101,14 @@ impl View for TabView {
tab.view.layout(Vec2::new(size.x, size.y - 1));
}
}
fn on_event(&mut self, event: Event) -> EventResult {
if let Some(tab) = self.tabs.get_mut(self.selected) {
tab.view.on_event(event)
} else {
EventResult::Ignored
}
}
}
impl ViewExt for TabView {