Skip to content

Commit

Permalink
feat: show functions now return InnerResponse (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElhamAryanpur authored Mar 26, 2024
1 parent b6c4642 commit 2dac313
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,16 @@ impl CommonMarkViewer {
}

/// Shows rendered markdown
pub fn show(self, ui: &mut egui::Ui, cache: &mut CommonMarkCache, text: &str) {
pub fn show(
self,
ui: &mut egui::Ui,
cache: &mut CommonMarkCache,
text: &str,
) -> egui::InnerResponse<()> {
cache.prepare_show(ui.ctx());

#[cfg(feature = "pulldown_cmark")]
parsers::pulldown::CommonMarkViewerInternal::new(self.source_id).show(
let response = parsers::pulldown::CommonMarkViewerInternal::new(self.source_id).show(
ui,
cache,
&self.options,
Expand All @@ -408,12 +413,14 @@ impl CommonMarkViewer {
);

#[cfg(feature = "comrak")]
parsers::comrak::CommonMarkViewerInternal::new(self.source_id).show(
let response = parsers::comrak::CommonMarkViewerInternal::new(self.source_id).show(
ui,
cache,
&self.options,
text,
);

response
}

/// Shows markdown inside a [`ScrollArea`].
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/comrak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CommonMarkViewerInternal {
cache: &mut CommonMarkCache,
options: &CommonMarkOptions,
text: &str,
) {
) -> egui::InnerResponse<()> {
let max_width = options.max_width(ui);
let layout = egui::Layout::left_to_right(egui::Align::BOTTOM).with_main_wrap(true);

Expand All @@ -59,7 +59,7 @@ impl CommonMarkViewerInternal {
let root = parse_document(&arena, text, &parse_opt);

self.render(ui, cache, options, max_width, root);
});
})
}

// FIXME: recursion limit...
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/pulldown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl CommonMarkViewerInternal {
options: &CommonMarkOptions,
text: &str,
populate_split_points: bool,
) {
) -> egui::InnerResponse<()> {
let max_width = options.max_width(ui);
let layout = egui::Layout::left_to_right(egui::Align::BOTTOM).with_main_wrap(true);

Expand Down Expand Up @@ -240,7 +240,7 @@ impl CommonMarkViewerInternal {
}

cache.scroll(&self.source_id).page_size = Some(ui.next_widget_position().to_vec2());
});
})
}

pub(crate) fn show_scrollable(
Expand Down

0 comments on commit 2dac313

Please sign in to comment.