Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/screen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::StyleConfig;
use crate::style::Style;
use crate::ui::layout::{LayoutTree, opts};
use crate::ui::{UiItem, UiTree, layout_span};
use crate::ui::{UiTree, layout_span};
use crate::{item_data::ItemData, ui};
use itertools::Itertools;

Expand Down Expand Up @@ -308,9 +308,9 @@ impl Screen {
highlighted: false,
};
layout_item(&mut layout, self, false, view);
layout.compute([self.size.0, self.size.1]);

layout
.compute([self.size.0, self.size.1])
.iter()
.map(|item| item.pos[1] + item.size[1])
.max()
Expand Down Expand Up @@ -551,7 +551,7 @@ struct ItemView {
}

pub(crate) fn layout_screen<'a>(layout: &mut UiTree<'a>, screen: &'a Screen, hide_cursor: bool) {
layout.vertical(None, opts().fill_x(), |layout| {
layout.col(opts().fill_x(), |layout| {
for view in screen.item_views(screen.size) {
layout_item(layout, screen, hide_cursor, view);
}
Expand All @@ -566,7 +566,7 @@ fn layout_item<'a>(layout: &mut UiTree<'a>, screen: &'a Screen, hide_cursor: boo
let line_sel = line_selection_highlight(style, &line, is_line_sel);
let bg = area_sel.patch(line_sel);

layout.horizontal(Some(UiItem::Style(bg)), opts().fill_x(), |layout| {
layout.row_with(bg, opts().fill_x(), |layout| {
let gutter_char = if !hide_cursor && line.highlighted {
gutter_char(style, is_line_sel, bg)
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/tests/snapshots/gitu__tests__rebase__rebase_menu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ expression: ctx.redact_buffer()
Recent commits |
b66a0bf other-branch origin/main add initial-file Author Name __ |
|
|
|
|
|
|
────────────────────────────────────────────────────────────────────────────────|
Rebase Arguments |
a abort -a Autosquash (--autosquash) |
Expand All @@ -17,9 +22,4 @@ expression: ctx.redact_buffer()
-k Keep empty commits (--keep-empty) |
-h Disable hooks (--no-verify) |
-p Preserve merges (--preserve-merges) |
|
|
|
|
|
styles_hash: 814db1ed750863dd
styles_hash: 448a0978f1550760
45 changes: 18 additions & 27 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::screen;
use crate::style::{Color, Modifier, Style};
use crate::term::TermBackend;
use crate::text_input::Status;
use crate::ui::layout::{LayoutItem, Measure};
use crate::ui::layout::{LayoutItem, Measure, Payload};
use itertools::Itertools;
use layout::LayoutTree;
use layout::opts;
Expand All @@ -25,36 +25,28 @@ const DASHES: &str = "───────────────────
const BLANKS: &str = " ";

#[derive(Debug, Clone)]
pub(crate) enum UiItem<'a> {
Span(Cow<'a, str>, Style),
Style(Style),
}
pub(crate) type UiTree<'a> = LayoutTree<UiItem<'a>>;
pub(crate) struct Span<'a>(pub(crate) Cow<'a, str>, pub(crate) Style);
pub(crate) type UiTree<'a> = LayoutTree<Span<'a>, Style>;

impl Measure for UiItem<'_> {
impl Measure for Span<'_> {
type Unit = u16;

fn measure(&self) -> [u16; 2] {
match self {
UiItem::Span(text, _style) => [UnicodeWidthStr::width(text.as_ref()) as u16, 1],
// Styles are only ever attached to containers, which are sized by
// their children, so this is never the size of anything drawn.
UiItem::Style(_style) => [1, 1],
}
[UnicodeWidthStr::width(self.0.as_ref()) as u16, 1]
}
}

pub(crate) fn ui(term: &mut TermBackend, state: &mut State) -> Res<()> {
let size = term.size().unwrap();
let mut layout = UiTree::new();

layout.vertical(None, opts(), |layout| {
layout.vertical(None, opts().fill_xy(), |layout| {
layout.col(opts(), |layout| {
layout.col(opts().fill_xy(), |layout| {
let hide_cursor = state.picker.is_some();
screen::layout_screen(layout, state.screens.last().unwrap(), hide_cursor);
});

layout.vertical(None, opts(), |layout| {
layout.col(opts(), |layout| {
menu::layout_menu(layout, state, size.0 as usize);
cmd_log::layout_cmd_log(
layout,
Expand All @@ -76,15 +68,14 @@ pub(crate) fn ui(term: &mut TermBackend, state: &mut State) -> Res<()> {
});
});

layout.compute([size.0, size.1]);
let computed = layout.compute([size.0, size.1]);

let mut items = layout.iter().collect::<Vec<_>>();
let mut items = computed.iter().collect::<Vec<_>>();
items.sort_by_key(|item| [item.pos[1], item.pos[0]]);

clear_blanks(term, size, items)?;

term.flush().map_err(Error::Term)?;
layout.clear();

state.screens.last_mut().unwrap().size = size;

Expand All @@ -106,7 +97,7 @@ fn layout_prompt<'a>(layout: &mut UiTree<'a>, state: &'a State, width: usize) {
let prompt_style = Style::from(&state.config.style.prompt);

repeat_chars(layout, width, DASHES, separator_style);
layout.horizontal(None, opts(), |layout| {
layout.row(opts(), |layout| {
layout_span(
layout,
(
Expand Down Expand Up @@ -157,7 +148,7 @@ fn layout_picker<'a>(layout: &mut UiTree<'a>, state: &'a State, width: usize) {

/// Lays out `content` as a single row of its own.
pub(crate) fn layout_line<'a>(layout: &mut UiTree<'a>, content: Cow<'a, str>, style: Style) {
layout.horizontal(None, opts(), |layout| {
layout.row(opts(), |layout| {
layout_span(layout, (content, style));
});
}
Expand All @@ -166,12 +157,12 @@ pub(crate) fn layout_span<'a>(layout: &mut UiTree<'a>, span: (Cow<'a, str>, Styl
match span.0 {
Cow::Borrowed(s) => {
for word in words(s) {
layout.leaf(UiItem::Span(Cow::Borrowed(word), span.1));
layout.leaf(Span(Cow::Borrowed(word), span.1));
}
}
Cow::Owned(s) => {
for word in words(&s) {
layout.leaf(UiItem::Span(Cow::Owned(word.into()), span.1));
layout.leaf(Span(Cow::Owned(word.into()), span.1));
}
}
}
Expand All @@ -190,7 +181,7 @@ pub(crate) fn repeat_chars(layout: &mut UiTree, count: usize, chars: &'static st
let full = count / grapheme_count;
let partial = count % grapheme_count;

layout.horizontal(None, opts(), |layout| {
layout.row(opts(), |layout| {
for _ in 0..full {
layout_span(layout, (chars.into(), style));
}
Expand All @@ -212,7 +203,7 @@ pub(crate) fn repeat_chars(layout: &mut UiTree, count: usize, chars: &'static st
fn clear_blanks(
term: &mut TermBackend,
size: (u16, u16),
items: Vec<LayoutItem<&UiItem<'_>, u16>>,
items: Vec<LayoutItem<Payload<'_, Span<'_>, Style>, u16>>,
) -> Result<(), Error> {
let mut at = [0, 0];
let mut bg = Style::new();
Expand All @@ -227,14 +218,14 @@ fn clear_blanks(
blank_until(term, &mut at, [0, pos[1]], size.0, bg, bg_end)?;

match data {
UiItem::Span(text, style) => {
Payload::Leaf(Span(text, style)) => {
blank_until(term, &mut at, pos, size.0, bg, bg_end)?;
term.queue_move_cursor(pos[0], pos[1])?;
term.queue_print(text, style)?;

at[0] = pos[0].saturating_add(item_size[0]);
}
UiItem::Style(style) => {
Payload::Container(style) => {
bg = *style;
bg_end = pos[1].saturating_add(item_size[1]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/cmd_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn layout_cmd_log<'a>(

repeat_chars(layout, width, DASHES, Style::from(&config.style.separator));

layout.vertical(None, opts(), |layout| {
layout.col(opts(), |layout| {
for entry in &log.entries {
layout_entry(layout, entry, config);
}
Expand All @@ -30,7 +30,7 @@ pub(crate) fn layout_cmd_log<'a>(
fn layout_entry<'a>(layout: &mut UiTree<'a>, entry: &Arc<RwLock<CmdLogEntry>>, config: &Config) {
match &*entry.read().unwrap() {
CmdLogEntry::Cmd { args, out } => {
layout.horizontal(None, opts(), |layout| {
layout.row(opts(), |layout| {
layout_span(
layout,
(
Expand Down
2 changes: 1 addition & 1 deletion src/ui/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) fn layout_item<'a>(
),
);

layout.horizontal(None, opts().fill_x(), |layout| {
layout.row(opts().fill_x(), |layout| {
for reference in associated_references {
layout_span(layout, (" ".into(), base));
layout_reference(layout, reference, config, base);
Expand Down
7 changes: 7 additions & 0 deletions src/ui/layout/direction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ impl Direction {
Direction::Vertical => Vec2(U::ZERO, U::ONE),
}
}

pub(crate) fn flip(&self) -> Self {
match self {
Direction::Horizontal => Direction::Vertical,
Direction::Vertical => Direction::Horizontal,
}
}
}
Loading