From 52417a2eff126855dc3235312a33cdabcbbda376 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 3 Jan 2024 15:35:51 +0100 Subject: [PATCH] patch-list: Simplify layout --- bin/commands/issue/suite/page.rs | 2 +- bin/commands/patch.rs | 4 ++-- bin/commands/patch/list.rs | 10 ++++------ bin/commands/patch/list/page.rs | 5 +---- bin/commands/patch/list/ui.rs | 2 +- bin/commands/patch/suite/page.rs | 4 ++-- src/ui/layout.rs | 34 +++++++++++++++++++++++++++++--- 7 files changed, 42 insertions(+), 19 deletions(-) diff --git a/bin/commands/issue/suite/page.rs b/bin/commands/issue/suite/page.rs index cf8d18fa..924add86 100644 --- a/bin/commands/issue/suite/page.rs +++ b/bin/commands/issue/suite/page.rs @@ -163,7 +163,7 @@ impl ViewPage for ListPage { fn view(&mut self, app: &mut Application, frame: &mut Frame) { let area = frame.size(); let shortcuts_h = 1u16; - let layout = layout::default_page(area, shortcuts_h); + let layout = layout::full_page(area, shortcuts_h); app.view(&Cid::List(ListCid::Header), frame, layout.navigation); app.view( diff --git a/bin/commands/patch.rs b/bin/commands/patch.rs index bea7b98a..4782e562 100644 --- a/bin/commands/patch.rs +++ b/bin/commands/patch.rs @@ -1,7 +1,7 @@ -#[path = "patch/suite.rs"] -mod suite; #[path = "patch/list.rs"] mod list; +#[path = "patch/suite.rs"] +mod suite; use std::ffi::OsString; diff --git a/bin/commands/patch/list.rs b/bin/commands/patch/list.rs index b4dd1907..1691e7c3 100644 --- a/bin/commands/patch/list.rs +++ b/bin/commands/patch/list.rs @@ -11,17 +11,15 @@ use anyhow::Result; use radicle::cob::patch::PatchId; -use tui::Exit; use tuirealm::application::PollStrategy; use tuirealm::{Application, Frame, NoUserEvent, Sub, SubClause}; use radicle_tui as tui; -use radicle_tui::context::Context; -use radicle_tui::ui::subscription; -use radicle_tui::ui::theme::{self, Theme}; -use radicle_tui::PageStack; -use radicle_tui::Tui; +use tui::context::Context; +use tui::ui::subscription; +use tui::ui::theme::{self, Theme}; +use tui::{Exit, PageStack, Tui}; use page::ListView; diff --git a/bin/commands/patch/list/page.rs b/bin/commands/patch/list/page.rs index 3db4eb55..a8a3beec 100644 --- a/bin/commands/patch/list/page.rs +++ b/bin/commands/patch/list/page.rs @@ -129,10 +129,8 @@ impl ViewPage for ListView { fn view(&mut self, app: &mut Application, frame: &mut Frame) { let area = frame.size(); - let shortcuts_h = 1u16; - let layout = layout::default_page(area, shortcuts_h); + let layout = layout::default_page(area); - app.view(&Cid::List(ListCid::Header), frame, layout.navigation); app.view( &Cid::List(self.active_component.clone()), frame, @@ -140,7 +138,6 @@ impl ViewPage for ListView { ); app.view(&Cid::List(ListCid::Context), frame, layout.context); - app.view(&Cid::List(ListCid::Shortcuts), frame, layout.shortcuts); } fn subscribe(&self, app: &mut Application) -> Result<()> { diff --git a/bin/commands/patch/list/ui.rs b/bin/commands/patch/list/ui.rs index f0625f19..e24711d5 100644 --- a/bin/commands/patch/list/ui.rs +++ b/bin/commands/patch/list/ui.rs @@ -131,7 +131,7 @@ pub fn browse_context(context: &Context, theme: &Theme, progress: Progress) -> W tui::ui::widget::context::bar( theme, - "Browse", + "Patches", "", "", &format!("{draft} draft | {open} open | {archived} archived | {merged} merged"), diff --git a/bin/commands/patch/suite/page.rs b/bin/commands/patch/suite/page.rs index 2a39fe68..d4e54355 100644 --- a/bin/commands/patch/suite/page.rs +++ b/bin/commands/patch/suite/page.rs @@ -132,7 +132,7 @@ impl ViewPage for ListView { fn view(&mut self, app: &mut Application, frame: &mut Frame) { let area = frame.size(); let shortcuts_h = 1u16; - let layout = layout::default_page(area, shortcuts_h); + let layout = layout::full_page(area, shortcuts_h); app.view(&Cid::List(ListCid::Header), frame, layout.navigation); app.view( @@ -284,7 +284,7 @@ impl ViewPage for PatchView { fn view(&mut self, app: &mut Application, frame: &mut Frame) { let area = frame.size(); let shortcuts_h = 1u16; - let layout = layout::default_page(area, shortcuts_h); + let layout = layout::full_page(area, shortcuts_h); app.view(&Cid::Patch(PatchCid::Header), frame, layout.navigation); app.view( diff --git a/src/ui/layout.rs b/src/ui/layout.rs index 681cac76..6c7a096f 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -8,13 +8,18 @@ pub struct AppHeader { pub line: Rect, } -pub struct DefaultPage { +pub struct FullPage { pub navigation: Rect, pub component: Rect, pub context: Rect, pub shortcuts: Rect, } +pub struct DefaultPage { + pub component: Rect, + pub context: Rect, +} + pub struct IssuePage { pub header: Rect, pub left: Rect, @@ -91,7 +96,7 @@ pub fn app_header(area: Rect, info_w: u16) -> AppHeader { } } -pub fn default_page(area: Rect, shortcuts_h: u16) -> DefaultPage { +pub fn full_page(area: Rect, shortcuts_h: u16) -> FullPage { let nav_h = 3u16; let context_h = 1u16; let margin_h = 1u16; @@ -113,7 +118,7 @@ pub fn default_page(area: Rect, shortcuts_h: u16) -> DefaultPage { ) .split(area); - DefaultPage { + FullPage { navigation: layout[0], component: layout[1], context: layout[2], @@ -121,6 +126,29 @@ pub fn default_page(area: Rect, shortcuts_h: u16) -> DefaultPage { } } +pub fn default_page(area: Rect) -> DefaultPage { + let context_h = 1u16; + let margin_h = 1u16; + let component_h = area.height.saturating_sub(context_h); + + let layout = Layout::default() + .direction(Direction::Vertical) + .horizontal_margin(margin_h) + .constraints( + [ + Constraint::Length(component_h), + Constraint::Length(context_h), + ] + .as_ref(), + ) + .split(area); + + DefaultPage { + component: layout[0], + context: layout[1], + } +} + pub fn headerless_page(area: Rect) -> Vec { let margin_h = 1u16; let content_h = area.height.saturating_sub(margin_h);