Skip to content

Commit 70e5201

Browse files
author
Stephan Dilly
committed
allow all draw calls to mutate self
1 parent 434c793 commit 70e5201

File tree

10 files changed

+55
-57
lines changed

10 files changed

+55
-57
lines changed

src/app.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ impl App {
8686
if self.tab == 0 {
8787
self.status_tab.draw(f, chunks_main[1]);
8888
} else {
89-
self.revlog.prepare_draw(chunks_main[1]);
9089
self.revlog.draw(f, chunks_main[1]);
9190
}
9291

@@ -311,7 +310,7 @@ impl App {
311310
|| self.msg.is_visible()
312311
}
313312

314-
fn draw_popups<B: Backend>(&self, f: &mut Frame<B>) {
313+
fn draw_popups<B: Backend>(&mut self, f: &mut Frame<B>) {
315314
let size = f.size();
316315

317316
self.commit.draw(f, size);

src/components/changes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl ChangesComponent {
255255
}
256256

257257
impl DrawableComponent for ChangesComponent {
258-
fn draw<B: Backend>(&self, f: &mut Frame<B>, r: Rect) {
258+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, r: Rect) {
259259
let selection_offset =
260260
self.tree.tree.items().iter().enumerate().fold(
261261
0,

src/components/commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct CommitComponent {
2727
}
2828

2929
impl DrawableComponent for CommitComponent {
30-
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
30+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
3131
if self.visible {
3232
let txt = if self.msg.is_empty() {
3333
[Text::Styled(

src/components/diff.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ impl DiffComponent {
104104
}
105105
ScrollType::Home => self.scroll = 0,
106106
ScrollType::End => self.scroll = scroll_max,
107-
//TODO:
108-
_ => (),
107+
ScrollType::PageDown => (),
108+
ScrollType::PageUp => (),
109109
}
110110

111111
if old != self.scroll {
@@ -296,7 +296,7 @@ impl DiffComponent {
296296
}
297297

298298
impl DrawableComponent for DiffComponent {
299-
fn draw<B: Backend>(&self, f: &mut Frame<B>, r: Rect) {
299+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, r: Rect) {
300300
let mut style_border = Style::default().fg(Color::DarkGray);
301301
let mut style_title = Style::default();
302302
if self.focused {

src/components/help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct HelpComponent {
2525
}
2626

2727
impl DrawableComponent for HelpComponent {
28-
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
28+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
2929
if self.visible {
3030
let (txt, selected_line) = self.get_text();
3131

src/components/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn visibility_blocking<T: Component>(
8282
///
8383
pub trait DrawableComponent {
8484
///
85-
fn draw<B: Backend>(&self, f: &mut Frame<B>, rect: Rect);
85+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, rect: Rect);
8686
}
8787

8888
/// base component trait

src/components/msg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct MsgComponent {
2020
}
2121

2222
impl DrawableComponent for MsgComponent {
23-
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
23+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
2424
if self.visible {
2525
let txt = vec![Text::Raw(Cow::from(self.msg.as_str()))];
2626

src/components/reset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct ResetComponent {
2626
}
2727

2828
impl DrawableComponent for ResetComponent {
29-
fn draw<B: Backend>(&self, f: &mut Frame<B>, _rect: Rect) {
29+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
3030
if self.visible {
3131
let mut txt = Vec::new();
3232
txt.push(Text::Styled(

src/tabs/revlog/mod.rs

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ mod utils;
22

33
use crate::{
44
components::{
5-
CommandBlocking, CommandInfo, Component, ScrollType,
5+
CommandBlocking, CommandInfo, Component, DrawableComponent,
6+
ScrollType,
67
},
78
keys,
89
strings::commands,
@@ -72,50 +73,6 @@ impl Revlog {
7273
}
7374
}
7475

75-
///
76-
pub fn prepare_draw(&mut self, area: Rect) {
77-
self.current_height = area.height.saturating_sub(2);
78-
}
79-
80-
///
81-
pub fn draw<B: Backend>(&self, f: &mut Frame<B>, area: Rect) {
82-
let height = area.height as usize;
83-
let selection =
84-
self.selection.saturating_sub(self.items.index_offset);
85-
let height_d2 = height as usize / 2;
86-
let min = selection.saturating_sub(height_d2);
87-
88-
let mut txt = Vec::new();
89-
for (idx, e) in self.items.items.iter().enumerate() {
90-
let tag = if let Some(tag_name) = self.tags.get(&e.hash) {
91-
tag_name.as_str()
92-
} else {
93-
""
94-
};
95-
Self::add_entry(e, idx == selection, &mut txt, tag);
96-
}
97-
98-
let title = format!(
99-
"commit {}/{}",
100-
self.selection, self.selection_max
101-
);
102-
103-
f.render_widget(
104-
Paragraph::new(
105-
txt.iter()
106-
.skip(min * ELEMENTS_PER_LINE)
107-
.take(height * ELEMENTS_PER_LINE),
108-
)
109-
.block(
110-
Block::default()
111-
.borders(Borders::ALL)
112-
.title(title.as_str()),
113-
)
114-
.alignment(Alignment::Left),
115-
area,
116-
);
117-
}
118-
11976
///
12077
pub fn any_work_pending(&self) -> bool {
12178
self.git_log.is_pending()
@@ -273,6 +230,48 @@ impl Revlog {
273230
}
274231
}
275232

233+
impl DrawableComponent for Revlog {
234+
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, area: Rect) {
235+
self.current_height = area.height.saturating_sub(2);
236+
237+
let height = area.height as usize;
238+
let selection =
239+
self.selection.saturating_sub(self.items.index_offset);
240+
let height_d2 = height as usize / 2;
241+
let min = selection.saturating_sub(height_d2);
242+
243+
let mut txt = Vec::new();
244+
for (idx, e) in self.items.items.iter().enumerate() {
245+
let tag = if let Some(tag_name) = self.tags.get(&e.hash) {
246+
tag_name.as_str()
247+
} else {
248+
""
249+
};
250+
Self::add_entry(e, idx == selection, &mut txt, tag);
251+
}
252+
253+
let title = format!(
254+
"commit {}/{}",
255+
self.selection, self.selection_max
256+
);
257+
258+
f.render_widget(
259+
Paragraph::new(
260+
txt.iter()
261+
.skip(min * ELEMENTS_PER_LINE)
262+
.take(height * ELEMENTS_PER_LINE),
263+
)
264+
.block(
265+
Block::default()
266+
.borders(Borders::ALL)
267+
.title(title.as_str()),
268+
)
269+
.alignment(Alignment::Left),
270+
area,
271+
);
272+
}
273+
}
274+
276275
impl Component for Revlog {
277276
fn event(&mut self, ev: Event) -> bool {
278277
if self.visible {

src/tabs/status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct Status {
4646

4747
impl DrawableComponent for Status {
4848
fn draw<B: tui::backend::Backend>(
49-
&self,
49+
&mut self,
5050
f: &mut tui::Frame<B>,
5151
rect: tui::layout::Rect,
5252
) {

0 commit comments

Comments
 (0)