From 82a3e4f9002ffd549c20353f13d5c40d97c43134 Mon Sep 17 00:00:00 2001 From: "Tom A. Wagner" Date: Tue, 23 Nov 2021 17:09:46 +0100 Subject: [PATCH] graphview: draw background automatically This removes the manual painting of the background via cairo and adds the correct color to CSS instead, which should hopefully improve performance as we do less cpu painting like this. --- src/style.css | 5 ++++- src/view/graph_view.rs | 18 ++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/style.css b/src/style.css index d970e86..7e82cfd 100644 --- a/src/style.css +++ b/src/style.css @@ -2,7 +2,6 @@ @define-color video rgb(200,200,0); @define-color midi rgb(200,0,50); @define-color graphview-link #808080; -@define-color graphview-grid @text_view_bg; .audio { background: @audio; @@ -17,4 +16,8 @@ .midi { background: @midi; color: black; +} + +graphview { + background: @text_view_bg; } \ No newline at end of file diff --git a/src/view/graph_view.rs b/src/view/graph_view.rs index c2962a9..0135dbd 100644 --- a/src/view/graph_view.rs +++ b/src/view/graph_view.rs @@ -54,6 +54,7 @@ mod imp { fn class_init(klass: &mut Self::Class) { // The layout manager determines how child widgets are laid out. klass.set_layout_manager_type::(); + klass.set_css_name("graphview"); } } @@ -123,24 +124,13 @@ mod imp { Try to use relative units (em) and colours from the theme as much as possible. */ let alloc = widget.allocation(); + let widget_bounds = + graphene::Rect::new(0.0, 0.0, alloc.width as f32, alloc.height as f32); let background_cr = snapshot - .append_cairo(&graphene::Rect::new( - 0.0, - 0.0, - alloc.width as f32, - alloc.height as f32, - )) + .append_cairo(&widget_bounds) .expect("Failed to get cairo context"); - // Try to replace the background color with a darker one from the theme. - if let Some(rgba) = widget.style_context().lookup_color("graphview-grid") { - background_cr.set_source_rgb(rgba.red.into(), rgba.green.into(), rgba.blue.into()); - if let Err(e) = background_cr.paint() { - warn!("Failed to paint graphview background: {}", e); - }; - } // TODO: else log colour not found - // Draw a nice grid on the background. background_cr.set_source_rgb(0.18, 0.18, 0.18); background_cr.set_line_width(0.2); // TODO: Set to 1px