From 2dac313f75abb7d46f336a7b7983074846650ca1 Mon Sep 17 00:00:00 2001 From: Elham Aryanpur Date: Tue, 26 Mar 2024 11:35:57 +0300 Subject: [PATCH] feat: show functions now return InnerResponse (#36) --- src/lib.rs | 13 ++++++++++--- src/parsers/comrak.rs | 4 ++-- src/parsers/pulldown.rs | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 39b8ad1..f33fc95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, @@ -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`]. diff --git a/src/parsers/comrak.rs b/src/parsers/comrak.rs index 70c4220..60aaa39 100644 --- a/src/parsers/comrak.rs +++ b/src/parsers/comrak.rs @@ -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); @@ -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... diff --git a/src/parsers/pulldown.rs b/src/parsers/pulldown.rs index 0c12a3e..ea0988c 100644 --- a/src/parsers/pulldown.rs +++ b/src/parsers/pulldown.rs @@ -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); @@ -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(