refactor(tab): use borderless instead of selectable where appropriate (#672)

* next pane position => next terminal position

* borderless

* update comment

* style(fmt): make rustfmt happy
This commit is contained in:
Aram Drevekenin 2021-08-30 16:43:26 +02:00 committed by GitHub
parent 3e6fcffb27
commit faaa425b7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 23 deletions

View file

@ -27,6 +27,7 @@ pub(crate) struct PluginPane {
pub pane_title: String,
frame: bool,
frame_color: Option<PaletteColor>,
borderless: bool,
}
impl PluginPane {
@ -48,6 +49,7 @@ impl PluginPane {
frame_color: None,
content_offset: Offset::default(),
pane_title: title,
borderless: false,
}
}
}
@ -279,4 +281,10 @@ impl Pane for PluginPane {
self.frame_color = color;
self.set_should_render(true);
}
fn set_borderless(&mut self, borderless: bool) {
self.borderless = borderless;
}
fn borderless(&self) -> bool {
self.borderless
}
}

View file

@ -44,6 +44,7 @@ pub struct TerminalPane {
pane_title: String,
frame: Option<PaneFrame>,
frame_color: Option<PaletteColor>,
borderless: bool,
}
impl Pane for TerminalPane {
@ -390,6 +391,12 @@ impl Pane for TerminalPane {
self.frame_color = color;
self.set_should_render(true);
}
fn set_borderless(&mut self, borderless: bool) {
self.borderless = borderless;
}
fn borderless(&self) -> bool {
self.borderless
}
}
impl TerminalPane {
@ -419,6 +426,7 @@ impl TerminalPane {
colors: palette,
selection_scrolled_at: time::Instant::now(),
pane_title: initial_pane_title,
borderless: false,
}
}
pub fn get_x(&self) -> usize {

View file

@ -102,7 +102,7 @@ pub(crate) struct Tab {
panes_to_hide: HashSet<PaneId>,
active_terminal: Option<PaneId>,
max_panes: Option<usize>,
viewport: Viewport, // includes all selectable panes
viewport: Viewport, // includes all non-UI panes
display_area: Size, // includes all panes (including eg. the status bar and tab bar in the default layout)
fullscreen_is_active: bool,
os_api: Box<dyn ServerOsApi>,
@ -245,6 +245,8 @@ pub trait Pane {
position_on_screen.relative_to(self.get_content_y(), self.get_content_x())
}
fn set_boundary_color(&mut self, _color: Option<PaletteColor>) {}
fn set_borderless(&mut self, borderless: bool);
fn borderless(&self) -> bool;
}
impl Tab {
@ -327,12 +329,13 @@ impl Tab {
.unwrap();
let pid = pid_rx.recv().unwrap();
let title = String::from(plugin.as_path().as_os_str().to_string_lossy());
let new_plugin = PluginPane::new(
let mut new_plugin = PluginPane::new(
pid,
*position_and_size,
self.senders.to_plugin.as_ref().unwrap().clone(),
title,
);
new_plugin.set_borderless(layout.borderless);
self.panes.insert(PaneId::Plugin(pid), Box::new(new_plugin));
// Send an initial mode update to the newly loaded plugin only!
self.senders
@ -344,13 +347,14 @@ impl Tab {
} else {
// there are still panes left to fill, use the pids we received in this method
let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
let next_selectable_pane_position = self.get_next_selectable_pane_position();
let new_pane = TerminalPane::new(
let next_terminal_position = self.get_next_terminal_position();
let mut new_pane = TerminalPane::new(
*pid,
*position_and_size,
self.colors,
next_selectable_pane_position,
next_terminal_position,
);
new_pane.set_borderless(layout.borderless);
self.panes
.insert(PaneId::Terminal(*pid), Box::new(new_pane));
}
@ -418,7 +422,7 @@ impl Tab {
return; // likely no terminal large enough to split
}
let terminal_id_to_split = terminal_id_to_split.unwrap();
let next_selectable_pane_position = self.get_next_selectable_pane_position();
let next_terminal_position = self.get_next_terminal_position();
let terminal_to_split = self.panes.get_mut(&terminal_id_to_split).unwrap();
let terminal_ws = terminal_to_split.position_and_size();
if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.cols()
@ -432,7 +436,7 @@ impl Tab {
term_pid,
bottom_winsize,
self.colors,
next_selectable_pane_position,
next_terminal_position,
);
terminal_to_split.set_geom(top_winsize);
self.panes.insert(pid, Box::new(new_terminal));
@ -448,7 +452,7 @@ impl Tab {
term_pid,
right_winsize,
self.colors,
next_selectable_pane_position,
next_terminal_position,
);
terminal_to_split.set_geom(left_winsize);
self.panes.insert(pid, Box::new(new_terminal));
@ -465,7 +469,7 @@ impl Tab {
self.toggle_active_pane_fullscreen();
}
if let PaneId::Terminal(term_pid) = pid {
let next_selectable_pane_position = self.get_next_selectable_pane_position();
let next_terminal_position = self.get_next_terminal_position();
let active_pane_id = &self.get_active_pane_id().unwrap();
let active_pane = self.panes.get_mut(active_pane_id).unwrap();
if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 {
@ -481,7 +485,7 @@ impl Tab {
term_pid,
bottom_winsize,
self.colors,
next_selectable_pane_position,
next_terminal_position,
);
active_pane.set_geom(top_winsize);
self.panes.insert(pid, Box::new(new_terminal));
@ -498,7 +502,7 @@ impl Tab {
}
if let PaneId::Terminal(term_pid) = pid {
// TODO: check minimum size of active terminal
let next_selectable_pane_position = self.get_next_selectable_pane_position();
let next_terminal_position = self.get_next_terminal_position();
let active_pane_id = &self.get_active_pane_id().unwrap();
let active_pane = self.panes.get_mut(active_pane_id).unwrap();
if active_pane.cols() < MIN_TERMINAL_WIDTH * 2 {
@ -509,12 +513,8 @@ impl Tab {
}
let terminal_ws = active_pane.position_and_size();
if let Some((left_winsize, right_winsize)) = split(Direction::Vertical, &terminal_ws) {
let new_terminal = TerminalPane::new(
term_pid,
right_winsize,
self.colors,
next_selectable_pane_position,
);
let new_terminal =
TerminalPane::new(term_pid, right_winsize, self.colors, next_terminal_position);
active_pane.set_geom(left_winsize);
self.panes.insert(pid, Box::new(new_terminal));
}
@ -693,10 +693,12 @@ impl Tab {
pane_content_offset(&position_and_size, &self.viewport);
pane.set_content_offset(Offset::shift(pane_rows_offset, pane_columns_offset));
}
// FIXME: The selectable thing is a massive Hack! Decouple borders from selectability
if !pane.selectable() {
// FIXME: this should also override the above logic
if pane.borderless() {
pane.set_content_offset(Offset::default());
}
// FIXME: This, and all other `set_terminal_size_using_fd` calls, would be best in
// `TerminalPane::reflow_lines`
if let PaneId::Terminal(pid) = pane_id {
@ -799,7 +801,7 @@ impl Tab {
fn get_selectable_panes(&self) -> impl Iterator<Item = (&PaneId, &Box<dyn Pane>)> {
self.panes.iter().filter(|(_, p)| p.selectable())
}
fn get_next_selectable_pane_position(&self) -> usize {
fn get_next_terminal_position(&self) -> usize {
self.panes
.iter()
.filter(|(k, _)| match k {
@ -2107,9 +2109,6 @@ impl Tab {
self.active_terminal = self.next_active_pane(&self.get_pane_ids())
}
}
// FIXME: This is a super, super nasty hack while borderless-ness is still tied to
// selectability. Delete this once those are decoupled
self.set_pane_frames(self.draw_pane_frames);
self.render();
}
pub fn close_pane(&mut self, id: PaneId) {