From 824893c33dabc93f17b925f2dd366d3e73e39c8b Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 16 Mar 2022 01:38:35 +0100 Subject: [PATCH] Fix iced ParamSlider fill overlapping with border --- nih_plug_iced/src/widgets/param_slider.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nih_plug_iced/src/widgets/param_slider.rs b/nih_plug_iced/src/widgets/param_slider.rs index c60594da..07c43128 100644 --- a/nih_plug_iced/src/widgets/param_slider.rs +++ b/nih_plug_iced/src/widgets/param_slider.rs @@ -439,6 +439,13 @@ impl<'a, P: Param> Widget for ParamSlider<'a, P> { _viewport: &Rectangle, ) { let bounds = layout.bounds(); + // I'm sure there's some philosophical meaning behind this + let bounds_without_borders = Rectangle { + x: bounds.x + BORDER_WIDTH, + y: bounds.y + BORDER_WIDTH, + width: bounds.width - (BORDER_WIDTH * 2.0), + height: bounds.height - (BORDER_WIDTH * 2.0), + }; let is_mouse_over = bounds.contains(cursor_position); // The bar itself, show a different background color when the value is being edited or when @@ -477,21 +484,20 @@ impl<'a, P: Param> Widget for ParamSlider<'a, P> { // For discrete alawys fill the bar from the left because it otherwise looks a bit // jarring when any any value after the first one is the defautl let fill_start_x = util::remap_rect_x_t( - &bounds, + &bounds_without_borders, if self.param.step_count().is_some() { 0.0 } else { self.setter.default_normalized_param_value(self.param) }, ); - let fill_end_x = util::remap_rect_x_t(&bounds, current_value); + let fill_end_x = util::remap_rect_x_t(&bounds_without_borders, current_value); let fill_color = Color::from_rgb8(196, 196, 196); let fill_rect = Rectangle { x: fill_start_x.min(fill_end_x), - y: bounds.y + BORDER_WIDTH, width: (fill_end_x - fill_start_x).abs(), - height: bounds.height - BORDER_WIDTH * 2.0, + ..bounds_without_borders }; renderer.fill_quad( renderer::Quad {