mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
allow all draw calls to mutate self
This commit is contained in:
parent
434c793d1c
commit
70e5201956
10 changed files with 55 additions and 57 deletions
|
|
@ -86,7 +86,6 @@ impl App {
|
||||||
if self.tab == 0 {
|
if self.tab == 0 {
|
||||||
self.status_tab.draw(f, chunks_main[1]);
|
self.status_tab.draw(f, chunks_main[1]);
|
||||||
} else {
|
} else {
|
||||||
self.revlog.prepare_draw(chunks_main[1]);
|
|
||||||
self.revlog.draw(f, chunks_main[1]);
|
self.revlog.draw(f, chunks_main[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,7 +310,7 @@ impl App {
|
||||||
|| self.msg.is_visible()
|
|| self.msg.is_visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_popups<B: Backend>(&self, f: &mut Frame<B>) {
|
fn draw_popups<B: Backend>(&mut self, f: &mut Frame<B>) {
|
||||||
let size = f.size();
|
let size = f.size();
|
||||||
|
|
||||||
self.commit.draw(f, size);
|
self.commit.draw(f, size);
|
||||||
|
|
|
||||||
|
|
@ -255,7 +255,7 @@ impl ChangesComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for ChangesComponent {
|
impl DrawableComponent for ChangesComponent {
|
||||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, r: Rect) {
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, r: Rect) {
|
||||||
let selection_offset =
|
let selection_offset =
|
||||||
self.tree.tree.items().iter().enumerate().fold(
|
self.tree.tree.items().iter().enumerate().fold(
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub struct CommitComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for CommitComponent {
|
impl DrawableComponent for CommitComponent {
|
||||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
|
||||||
if self.visible {
|
if self.visible {
|
||||||
let txt = if self.msg.is_empty() {
|
let txt = if self.msg.is_empty() {
|
||||||
[Text::Styled(
|
[Text::Styled(
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,8 @@ impl DiffComponent {
|
||||||
}
|
}
|
||||||
ScrollType::Home => self.scroll = 0,
|
ScrollType::Home => self.scroll = 0,
|
||||||
ScrollType::End => self.scroll = scroll_max,
|
ScrollType::End => self.scroll = scroll_max,
|
||||||
//TODO:
|
ScrollType::PageDown => (),
|
||||||
_ => (),
|
ScrollType::PageUp => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
if old != self.scroll {
|
if old != self.scroll {
|
||||||
|
|
@ -296,7 +296,7 @@ impl DiffComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for DiffComponent {
|
impl DrawableComponent for DiffComponent {
|
||||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, r: Rect) {
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, r: Rect) {
|
||||||
let mut style_border = Style::default().fg(Color::DarkGray);
|
let mut style_border = Style::default().fg(Color::DarkGray);
|
||||||
let mut style_title = Style::default();
|
let mut style_title = Style::default();
|
||||||
if self.focused {
|
if self.focused {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ pub struct HelpComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for HelpComponent {
|
impl DrawableComponent for HelpComponent {
|
||||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
|
||||||
if self.visible {
|
if self.visible {
|
||||||
let (txt, selected_line) = self.get_text();
|
let (txt, selected_line) = self.get_text();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ pub fn visibility_blocking<T: Component>(
|
||||||
///
|
///
|
||||||
pub trait DrawableComponent {
|
pub trait DrawableComponent {
|
||||||
///
|
///
|
||||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, rect: Rect);
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, rect: Rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// base component trait
|
/// base component trait
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ pub struct MsgComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for MsgComponent {
|
impl DrawableComponent for MsgComponent {
|
||||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
|
||||||
if self.visible {
|
if self.visible {
|
||||||
let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))];
|
let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub struct ResetComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for ResetComponent {
|
impl DrawableComponent for ResetComponent {
|
||||||
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
|
||||||
if self.visible {
|
if self.visible {
|
||||||
let mut txt = Vec::new();
|
let mut txt = Vec::new();
|
||||||
txt.push(Text::Styled(
|
txt.push(Text::Styled(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ mod utils;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::{
|
||||||
CommandBlocking, CommandInfo, Component, ScrollType,
|
CommandBlocking, CommandInfo, Component, DrawableComponent,
|
||||||
|
ScrollType,
|
||||||
},
|
},
|
||||||
keys,
|
keys,
|
||||||
strings::commands,
|
strings::commands,
|
||||||
|
|
@ -72,50 +73,6 @@ impl Revlog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
pub fn prepare_draw(&mut self, area: Rect) {
|
|
||||||
self.current_height = area.height.saturating_sub(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
pub fn draw<B: Backend>(&self, f: &mut Frame<B>, area: Rect) {
|
|
||||||
let height = area.height as usize;
|
|
||||||
let selection =
|
|
||||||
self.selection.saturating_sub(self.items.index_offset);
|
|
||||||
let height_d2 = height as usize / 2;
|
|
||||||
let min = selection.saturating_sub(height_d2);
|
|
||||||
|
|
||||||
let mut txt = Vec::new();
|
|
||||||
for (idx, e) in self.items.items.iter().enumerate() {
|
|
||||||
let tag = if let Some(tag_name) = self.tags.get(&e.hash) {
|
|
||||||
tag_name.as_str()
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
Self::add_entry(e, idx == selection, &mut txt, tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
let title = format!(
|
|
||||||
"commit {}/{}",
|
|
||||||
self.selection, self.selection_max
|
|
||||||
);
|
|
||||||
|
|
||||||
f.render_widget(
|
|
||||||
Paragraph::new(
|
|
||||||
txt.iter()
|
|
||||||
.skip(min * ELEMENTS_PER_LINE)
|
|
||||||
.take(height * ELEMENTS_PER_LINE),
|
|
||||||
)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.title(title.as_str()),
|
|
||||||
)
|
|
||||||
.alignment(Alignment::Left),
|
|
||||||
area,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
pub fn any_work_pending(&self) -> bool {
|
pub fn any_work_pending(&self) -> bool {
|
||||||
self.git_log.is_pending()
|
self.git_log.is_pending()
|
||||||
|
|
@ -273,6 +230,48 @@ impl Revlog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DrawableComponent for Revlog {
|
||||||
|
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect) {
|
||||||
|
self.current_height = area.height.saturating_sub(2);
|
||||||
|
|
||||||
|
let height = area.height as usize;
|
||||||
|
let selection =
|
||||||
|
self.selection.saturating_sub(self.items.index_offset);
|
||||||
|
let height_d2 = height as usize / 2;
|
||||||
|
let min = selection.saturating_sub(height_d2);
|
||||||
|
|
||||||
|
let mut txt = Vec::new();
|
||||||
|
for (idx, e) in self.items.items.iter().enumerate() {
|
||||||
|
let tag = if let Some(tag_name) = self.tags.get(&e.hash) {
|
||||||
|
tag_name.as_str()
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
Self::add_entry(e, idx == selection, &mut txt, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
let title = format!(
|
||||||
|
"commit {}/{}",
|
||||||
|
self.selection, self.selection_max
|
||||||
|
);
|
||||||
|
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(
|
||||||
|
txt.iter()
|
||||||
|
.skip(min * ELEMENTS_PER_LINE)
|
||||||
|
.take(height * ELEMENTS_PER_LINE),
|
||||||
|
)
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title(title.as_str()),
|
||||||
|
)
|
||||||
|
.alignment(Alignment::Left),
|
||||||
|
area,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Component for Revlog {
|
impl Component for Revlog {
|
||||||
fn event(&mut self, ev: Event) -> bool {
|
fn event(&mut self, ev: Event) -> bool {
|
||||||
if self.visible {
|
if self.visible {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ pub struct Status {
|
||||||
|
|
||||||
impl DrawableComponent for Status {
|
impl DrawableComponent for Status {
|
||||||
fn draw<B: tui::backend::Backend>(
|
fn draw<B: tui::backend::Backend>(
|
||||||
&self,
|
&mut self,
|
||||||
f: &mut tui::Frame<B>,
|
f: &mut tui::Frame<B>,
|
||||||
rect: tui::layout::Rect,
|
rect: tui::layout::Rect,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue