From 6165d659770e33070ad4538bcc90122527a042bf Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Tue, 9 Apr 2024 17:46:06 -0400 Subject: [PATCH] Make the review tree scrollable --- otg/core/src/view_models/game_review.rs | 4 ++++ otg/gtk/src/components/review_tree.rs | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/otg/core/src/view_models/game_review.rs b/otg/core/src/view_models/game_review.rs index 46f2675..7cdf068 100644 --- a/otg/core/src/view_models/game_review.rs +++ b/otg/core/src/view_models/game_review.rs @@ -87,6 +87,10 @@ impl GameReviewViewModel { } } + pub fn tree_max_depth(&self) -> usize { + self.imp.read().unwrap().review_tree.max_depth() + } + pub fn move_forward(&self) { unimplemented!() } diff --git a/otg/gtk/src/components/review_tree.rs b/otg/gtk/src/components/review_tree.rs index 420dcdc..dbd76d9 100644 --- a/otg/gtk/src/components/review_tree.rs +++ b/otg/gtk/src/components/review_tree.rs @@ -23,21 +23,27 @@ const HEIGHT: i32 = 800; #[derive(Clone)] pub struct ReviewTree { - widget: gtk::DrawingArea, + widget: gtk::ScrolledWindow, + drawing_area: gtk::DrawingArea, view: GameReviewViewModel, } impl ReviewTree { pub fn new(view: GameReviewViewModel) -> ReviewTree { - let widget = gtk::DrawingArea::new(); + let drawing_area = gtk::DrawingArea::new(); + let widget = gtk::ScrolledWindow::builder() + .child(&drawing_area) + .build(); widget.set_width_request(WIDTH); widget.set_height_request(HEIGHT); - let s = Self { widget, view }; + drawing_area.set_height_request(view.tree_max_depth() as i32 * 20 + 40); - s.widget.set_draw_func({ + let s = Self { widget, drawing_area, view }; + + s.drawing_area.set_draw_func({ let s = s.clone(); move |_, ctx, width, height| { s.redraw(ctx, width, height);