Skip to content

Commit

Permalink
chore: revert new on Scrollable
Browse files Browse the repository at this point in the history
but due to limitation of rustc
rust-lang/rust#20400
we can't have two new functions based on non-overlapping associated types
  • Loading branch information
zjp-CN committed Feb 1, 2024
1 parent d1a9437 commit c7b5c1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/bin/ui/scrollable/markdown/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::Scrollable;
use crate::Result;
use ratatui::layout::Rect;
use std::{fmt, ops::Deref};
use term_rustdoc::tree::Text as StyledText;
Expand Down Expand Up @@ -44,3 +45,14 @@ impl StyledLines {
parse::md(doc)
}
}

impl ScrollText {
pub fn new_text(doc: &str, area: Rect) -> Result<Self> {
// TODO:max_windth and text wrap for markdown
Ok(Scrollable {
lines: StyledLines::new(doc),
area,
..Default::default()
})
}
}
15 changes: 6 additions & 9 deletions src/bin/ui/scrollable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,22 @@ impl<Lines: Default> Default for Scrollable<Lines> {
}
}

impl<Lines: Deref<Target = [TreeLine]>> Scrollable<Lines> {
pub fn new(lines: Lines, full: Rect) -> Result<Self> {
impl<Lines: Default + Deref<Target = [TreeLine]>> Scrollable<Lines> {
pub fn new(lines: Lines, area: Rect) -> Result<Self> {
let w = lines.as_ref().iter().map(TreeLine::width).max();
let max_windth = w.ok_or_else(|| err!("The documentation is empty with no items."))?;
if full.width < max_windth {
if area.width < max_windth {
warn!(
full.width,
area.width,
max_windth, "Outline width exceeds the area width, so lines may be truncated."
);
}

let (start, cursor, select) = Default::default();
Ok(Self {
lines,
max_windth,
area: full,
start,
cursor,
select,
area,
..Default::default()
})
}
}
Expand Down

0 comments on commit c7b5c1a

Please sign in to comment.