refactor(tui): fold the keys overlay onto LogView and dedupe the pane lookups
The keys overlay scrolled with its own counter, a fixed page of ten and a usize::MAX sentinel that the renderer clamped back; it now reads through the same LogView as the chat and room logs, so the page is the window it last drew and the half-page keys work there too. One pane_area lookup and one page_of helper replace the pane-to-area match that page_size, highlighted_name_end and the mouse hit test each repeated, and list_jump takes its page as a usize so the callers stop converting. The pane number keys are one range arm over FocusedPane::ALL, whose index is the declaration order. The row layout carries each pane's weight beside it instead of re-matching with an unreachable arm, and the help columns are measured from the lines already built rather than built again for their width. The shortcut legend borrows its static keys instead of allocating three strings per entry per frame.
This commit is contained in:
@@ -41,15 +41,12 @@ pub enum FocusedPane {
|
||||
|
||||
impl FocusedPane {
|
||||
/// Every focusable pane, in the order `Tab` walks them: the number each
|
||||
/// carries in its legend.
|
||||
/// carries in its legend, which is also declaration order.
|
||||
pub const ALL: [Self; 3] = [Self::Searches, Self::Results, Self::Downloads];
|
||||
|
||||
/// Its position in [`Self::ALL`].
|
||||
const fn index(self) -> usize {
|
||||
match self {
|
||||
Self::Searches => 0,
|
||||
Self::Results => 1,
|
||||
Self::Downloads => 2,
|
||||
}
|
||||
self as usize
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +55,7 @@ impl FocusedPane {
|
||||
/// panes while zoomed reads as switching windows.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct PaneLayout {
|
||||
hidden: [bool; 3],
|
||||
hidden: [bool; FocusedPane::ALL.len()],
|
||||
pub zoomed: bool,
|
||||
}
|
||||
|
||||
@@ -238,9 +235,9 @@ pub struct AppState {
|
||||
pub layout: PaneLayout,
|
||||
/// The keys overlay (`?`) is open.
|
||||
pub show_help: bool,
|
||||
/// Rows the keys overlay is scrolled down, for a terminal too short to
|
||||
/// show it whole. The renderer clamps it to what there is to scroll.
|
||||
pub help_scroll: usize,
|
||||
/// Where the keys overlay is being read, for a terminal too short to
|
||||
/// show it whole.
|
||||
pub help_view: LogView,
|
||||
pub should_exit: bool,
|
||||
pub command_bar_active: bool,
|
||||
pub command_bar_input: String,
|
||||
@@ -322,7 +319,7 @@ impl AppState {
|
||||
focused_pane: FocusedPane::Searches,
|
||||
layout: PaneLayout::default(),
|
||||
show_help: false,
|
||||
help_scroll: 0,
|
||||
help_view: LogView::default(),
|
||||
should_exit: false,
|
||||
command_bar_active: false,
|
||||
command_bar_input: String::new(),
|
||||
@@ -365,6 +362,16 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where `pane` was last drawn; `None` while it is hidden.
|
||||
#[must_use]
|
||||
pub const fn pane_area(&self, pane: FocusedPane) -> Option<Rect> {
|
||||
match pane {
|
||||
FocusedPane::Searches => self.searches_pane_area,
|
||||
FocusedPane::Results => self.results_pane_area,
|
||||
FocusedPane::Downloads => self.downloads_pane_area,
|
||||
}
|
||||
}
|
||||
|
||||
/// Put the focus on `pane`, bringing it back on screen if it was hidden:
|
||||
/// pressing a pane's number is also how it comes back.
|
||||
pub const fn focus_pane(&mut self, pane: FocusedPane) {
|
||||
|
||||
Reference in New Issue
Block a user