From be488ac73837c9a741d900617840ee5c4ed74d61 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 29 Oct 2019 02:00:17 +0100 Subject: Draw scrollbar on top of scrollable content --- wgpu/src/renderer/scrollable.rs | 51 +++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'wgpu/src/renderer') diff --git a/wgpu/src/renderer/scrollable.rs b/wgpu/src/renderer/scrollable.rs index 5b93a765..43dddeed 100644 --- a/wgpu/src/renderer/scrollable.rs +++ b/wgpu/src/renderer/scrollable.rs @@ -34,34 +34,31 @@ impl scrollable::Renderer for Renderer { }; ( - Primitive::Group { - primitives: if is_mouse_over - && content_bounds.height > bounds.height - { - let ratio = bounds.height / content_bounds.height; - let scrollbar_height = bounds.height * ratio; - let y_offset = offset as f32 * ratio; + if is_mouse_over && content_bounds.height > bounds.height { + let ratio = bounds.height / content_bounds.height; + let scrollbar_height = bounds.height * ratio; + let y_offset = offset as f32 * ratio; - let scrollbar = Primitive::Quad { - bounds: Rectangle { - x: bounds.x + bounds.width - 12.0, - y: bounds.y + y_offset, - width: 10.0, - height: scrollbar_height, - }, - background: Background::Color(Color { - r: 0.0, - g: 0.0, - b: 0.0, - a: 0.5, - }), - border_radius: 5, - }; - - vec![primitive, scrollbar] - } else { - vec![primitive] - }, + let scrollbar = Primitive::Quad { + bounds: Rectangle { + x: bounds.x + bounds.width - 12.0, + y: bounds.y + y_offset, + width: 10.0, + height: scrollbar_height, + }, + background: Background::Color(Color { + r: 0.0, + g: 0.0, + b: 0.0, + a: 0.7, + }), + border_radius: 5, + }; + Primitive::Group { + primitives: vec![primitive, scrollbar], + } + } else { + primitive }, mouse_cursor, ) -- cgit