Make the review tree scrollable
This commit is contained in:
parent
56d7ad074a
commit
c702ffcfab
|
@ -77,6 +77,10 @@ impl GameReviewViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tree_max_depth(&self) -> usize {
|
||||||
|
self.imp.read().unwrap().review_tree.max_depth()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn move_forward(&self) {
|
pub fn move_forward(&self) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License along with On
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use cairo::Context;
|
use cairo::Context;
|
||||||
use glib::Object;
|
use gtk::prelude::*;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
|
||||||
use otg_core::GameReviewViewModel;
|
use otg_core::GameReviewViewModel;
|
||||||
|
|
||||||
const WIDTH: i32 = 200;
|
const WIDTH: i32 = 200;
|
||||||
|
@ -24,21 +23,27 @@ const HEIGHT: i32 = 800;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ReviewTree {
|
pub struct ReviewTree {
|
||||||
widget: gtk::DrawingArea,
|
widget: gtk::ScrolledWindow,
|
||||||
|
drawing_area: gtk::DrawingArea,
|
||||||
|
|
||||||
view: GameReviewViewModel,
|
view: GameReviewViewModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReviewTree {
|
impl ReviewTree {
|
||||||
pub fn new(view: GameReviewViewModel) -> 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_width_request(WIDTH);
|
||||||
widget.set_height_request(HEIGHT);
|
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();
|
let s = s.clone();
|
||||||
move |_, ctx, width, height| {
|
move |_, ctx, width, height| {
|
||||||
s.redraw(ctx, width, height);
|
s.redraw(ctx, width, height);
|
||||||
|
@ -49,6 +54,7 @@ impl ReviewTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redraw(&self, ctx: &Context, _width: i32, _height: i32) {
|
fn redraw(&self, ctx: &Context, _width: i32, _height: i32) {
|
||||||
|
println!("redraw: {} {}", _width, _height);
|
||||||
self.view.map_tree(move |tree, node, current| {
|
self.view.map_tree(move |tree, node, current| {
|
||||||
ctx.set_source_rgb(0.7, 0.7, 0.7);
|
ctx.set_source_rgb(0.7, 0.7, 0.7);
|
||||||
let (row, column) = tree.position(node.id);
|
let (row, column) = tree.position(node.id);
|
||||||
|
|
Loading…
Reference in New Issue