patch-list: Simplify layout

This commit is contained in:
Erik Kundt
2024-01-03 15:35:51 +01:00
parent b98d673183
commit 52417a2eff
7 changed files with 42 additions and 19 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ impl ViewPage<Cid, Message> for ListPage {
fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, 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(
+2 -2
View File
@@ -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;
+4 -6
View File
@@ -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;
+1 -4
View File
@@ -129,10 +129,8 @@ impl ViewPage<Cid, Message> for ListView {
fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, 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<Cid, Message> 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<Cid, Message, NoUserEvent>) -> Result<()> {
+1 -1
View File
@@ -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"),
+2 -2
View File
@@ -132,7 +132,7 @@ impl ViewPage<Cid, Message> for ListView {
fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, 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<Cid, Message> for PatchView {
fn view(&mut self, app: &mut Application<Cid, Message, NoUserEvent>, 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(
+31 -3
View File
@@ -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<Rect> {
let margin_h = 1u16;
let content_h = area.height.saturating_sub(margin_h);