Skip to content

Commit

Permalink
fix: remove utilities to convert data structure into layout (matrix)
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Feb 5, 2024
1 parent 6f1bcb4 commit e644dc4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
20 changes: 7 additions & 13 deletions src/core/menu/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ pub struct Renderer {
pub lines: Option<usize>,
}

impl Renderer {
fn selectbox_to_layout(&self) -> Vec<Graphemes> {
self.menu
impl Renderable for Renderer {
fn make_pane(&self, width: u16) -> Pane {
let matrix = self
.menu
.content()
.iter()
.enumerate()
Expand All @@ -41,17 +42,10 @@ impl Renderer {
)
}
})
.collect()
}
}
.collect::<Vec<Graphemes>>();

let trimed = matrix.iter().map(|row| trim(width as usize, row)).collect();

impl Renderable for Renderer {
fn make_pane(&self, width: u16) -> Pane {
let trimed = self
.selectbox_to_layout()
.iter()
.map(|row| trim(width as usize, row))
.collect();
Pane::new(trimed, self.menu.position, self.lines)
}

Expand Down
22 changes: 10 additions & 12 deletions src/core/text_editor/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,23 @@ pub struct Renderer {
pub lines: Option<usize>,
}

impl Renderer {
fn texteditor_to_graphemes(&self) -> Graphemes {
let text = match self.mask {
Some(mask) => self.texteditor.masking(mask),
None => self.texteditor.content(),
};
Graphemes::new_with_style(text, self.style)
.stylize(self.texteditor.position, self.cursor_style)
}
}

impl Renderable for Renderer {
fn make_pane(&self, width: u16) -> Pane {
let mut buf = Graphemes::default();
buf.append(&mut Graphemes::new_with_style(
&self.prefix,
self.prefix_style,
));
buf.append(&mut self.texteditor_to_graphemes());

let text = match self.mask {
Some(mask) => self.texteditor.masking(mask),
None => self.texteditor.content(),
};

let mut styled = Graphemes::new_with_style(text, self.style)
.stylize(self.texteditor.position, self.cursor_style);

buf.append(&mut styled);

Pane::new(
matrixify(width as usize, &buf),
Expand Down
19 changes: 6 additions & 13 deletions src/core/tree/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ pub struct Renderer {
pub lines: Option<usize>,
}

impl Renderer {
fn tree_to_layout(&self) -> Vec<Graphemes> {
self.tree
impl Renderable for Renderer {
fn make_pane(&self, width: u16) -> crate::pane::Pane {
let matrix = self
.tree
.content()
.iter()
.enumerate()
Expand All @@ -45,17 +46,9 @@ impl Renderer {
)
}
})
.collect()
}
}
.collect::<Vec<Graphemes>>();

impl Renderable for Renderer {
fn make_pane(&self, width: u16) -> crate::pane::Pane {
let trimed = self
.tree_to_layout()
.iter()
.map(|row| trim(width as usize, row))
.collect();
let trimed = matrix.iter().map(|row| trim(width as usize, row)).collect();
Pane::new(trimed, self.tree.position, self.lines)
}

Expand Down

0 comments on commit e644dc4

Please sign in to comment.