diff --git a/examples/phase_meter/src/main.rs b/examples/phase_meter/src/main.rs index 3de937e..09e88fe 100644 --- a/examples/phase_meter/src/main.rs +++ b/examples/phase_meter/src/main.rs @@ -3,9 +3,7 @@ use iced::{ Row, Settings, Subscription, Text, }; -use iced_audio::{ - knob, FloatRange, Knob, phase_meter, PhaseMeter, -}; +use iced_audio::{knob, phase_meter, FloatRange, Knob, PhaseMeter}; use std::time::Instant; @@ -111,13 +109,15 @@ impl Application for PhaseMeterApp { fn view(&mut self) -> Element { let phase_knob = Knob::new(&mut self.phase_knob_state, Message::ParamMoved); - - let phase_meter_default = PhaseMeter::new(&mut self.phase_meter_default_state); - let phase_meter_custom = PhaseMeter::new(&mut self.phase_meter_custom_state) - .orientation(phase_meter::Orientation::Vertical) - .style(CustomPhaseMeterStyle) - .width(Length::from(Length::Units(14))); + let phase_meter_default = + PhaseMeter::new(&mut self.phase_meter_default_state); + + let phase_meter_custom = + PhaseMeter::new(&mut self.phase_meter_custom_state) + .orientation(phase_meter::Orientation::Vertical) + .style(CustomPhaseMeterStyle) + .width(Length::from(Length::Units(14))); let row = Row::new() .width(Length::Fill) @@ -240,4 +240,4 @@ impl phase_meter::StyleSheet for CustomPhaseMeterStyle { center_line_color: Color::WHITE, } } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 790f5d8..0ea9365 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,16 +246,15 @@ pub use crate::core::*; mod platform { #[doc(no_inline)] pub use crate::wgpu::{ - db_meter, h_slider, knob, mod_range_input, ramp, reduction_meter, - v_slider, xy_pad, phase_meter, + db_meter, h_slider, knob, mod_range_input, phase_meter, ramp, + reduction_meter, v_slider, xy_pad, }; #[doc(no_inline)] pub use { db_meter::DBMeter, h_slider::HSlider, knob::Knob, - mod_range_input::ModRangeInput, ramp::Ramp, + mod_range_input::ModRangeInput, phase_meter::PhaseMeter, ramp::Ramp, reduction_meter::ReductionMeter, v_slider::VSlider, xy_pad::XYPad, - phase_meter::PhaseMeter, }; } diff --git a/src/native/phase_meter.rs b/src/native/phase_meter.rs index 47da360..c5ab64e 100644 --- a/src/native/phase_meter.rs +++ b/src/native/phase_meter.rs @@ -149,10 +149,7 @@ impl State { /// * `tier_positions` - The positions where each tier of color starts. /// /// [`PhaseMeter`]: struct.PhaseMeter.html - pub fn new( - normal: Normal, - tier_positions: TierPositions, - ) -> Self { + pub fn new(normal: Normal, tier_positions: TierPositions) -> Self { Self { normal, tier_positions, @@ -169,7 +166,8 @@ impl Default for State { } } -impl<'a, Message, Renderer> Widget for PhaseMeter<'a, Renderer> +impl<'a, Message, Renderer> Widget + for PhaseMeter<'a, Renderer> where Renderer: self::Renderer, { @@ -267,7 +265,9 @@ where Renderer: 'a + self::Renderer, Message: 'a, { - fn from(phase_meter: PhaseMeter<'a, Renderer>) -> Element<'a, Message, Renderer> { + fn from( + phase_meter: PhaseMeter<'a, Renderer>, + ) -> Element<'a, Message, Renderer> { Element::new(phase_meter) } } diff --git a/src/style/default_colors.rs b/src/style/default_colors.rs index 34472a5..64fa158 100644 --- a/src/style/default_colors.rs +++ b/src/style/default_colors.rs @@ -106,4 +106,4 @@ pub static DB_METER_TICK_TIER_3: Color = Color { b: 0.56, a: 0.63, }; -pub static PHASE_METER_CENTER_LINE: Color = Color::from_rgb(0.92, 0.92, 0.92); \ No newline at end of file +pub static PHASE_METER_CENTER_LINE: Color = Color::from_rgb(0.92, 0.92, 0.92); diff --git a/src/style/phase_meter.rs b/src/style/phase_meter.rs index c3a5c48..b8e8356 100644 --- a/src/style/phase_meter.rs +++ b/src/style/phase_meter.rs @@ -72,4 +72,4 @@ where fn from(style: T) -> Self { Box::new(style) } -} \ No newline at end of file +} diff --git a/src/wgpu/phase_meter.rs b/src/wgpu/phase_meter.rs index e6889b8..c8f914b 100644 --- a/src/wgpu/phase_meter.rs +++ b/src/wgpu/phase_meter.rs @@ -7,12 +7,8 @@ use crate::native::phase_meter; use iced_native::{Background, Color, MouseCursor, Rectangle}; use iced_wgpu::{Primitive, Renderer}; -pub use crate::native::phase_meter::{ - Orientation, State, TierPositions, -}; -pub use crate::style::phase_meter::{ - Style, StyleSheet, -}; +pub use crate::native::phase_meter::{Orientation, State, TierPositions}; +pub use crate::style::phase_meter::{Style, StyleSheet}; /// This is an alias of a `crate::native` [`PhaseMeter`] with an /// `iced_wgpu::Renderer`. @@ -28,7 +24,10 @@ enum PhaseTier { Good, } -fn tier(normal: Normal, tier_positions: phase_meter::TierPositions) -> PhaseTier { +fn tier( + normal: Normal, + tier_positions: phase_meter::TierPositions, +) -> PhaseTier { let value = normal.value(); if value >= (0.5 + (tier_positions.good.value() / 2.0)) { @@ -87,7 +86,8 @@ impl phase_meter::Renderer for Renderer { let center_line = Primitive::Quad { bounds: Rectangle { - x: (bounds_x + h_center - (center_line_width / 2.0)).round(), + x: (bounds_x + h_center - (center_line_width / 2.0)) + .round(), y: bar_y, width: center_line_width, height: bar_height, @@ -102,8 +102,12 @@ impl phase_meter::Renderer for Renderer { let meter_span = bounds_width - (border_width * 2.0); let normal_offset = (normal.value() * meter_span).round(); - let poor_offset = (meter_span * (tier_positions.poor.value() / 2.0)).round(); - let good_offset = (meter_span * (0.5 + (tier_positions.good.value() / 2.0))).round(); + let poor_offset = (meter_span + * (tier_positions.poor.value() / 2.0)) + .round(); + let good_offset = (meter_span + * (0.5 + (tier_positions.good.value() / 2.0))) + .round(); let normal_tier = tier(normal, tier_positions); @@ -136,13 +140,17 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, bad_bar, poor_bar, center_line], + primitives: vec![ + back, + bad_bar, + poor_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } PhaseTier::Poor => { - let poor_bar = Primitive::Quad { bounds: Rectangle { x: bounds_x + normal_offset + border_width, @@ -158,11 +166,15 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, poor_bar, center_line], + primitives: vec![ + back, + poor_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } PhaseTier::Okay => { let okay_bar = Primitive::Quad { bounds: Rectangle { @@ -179,11 +191,15 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, okay_bar, center_line], + primitives: vec![ + back, + okay_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } PhaseTier::Good => { let okay_bar = Primitive::Quad { bounds: Rectangle { @@ -212,11 +228,16 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, okay_bar, good_bar, center_line], + primitives: vec![ + back, + okay_bar, + good_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } } } else { ( @@ -226,7 +247,7 @@ impl phase_meter::Renderer for Renderer { MouseCursor::default(), ) } - }, + } Orientation::Vertical => { let v_center = (bounds_height / 2.0).round(); @@ -236,7 +257,8 @@ impl phase_meter::Renderer for Renderer { let center_line = Primitive::Quad { bounds: Rectangle { x: bar_x, - y: (bounds_y + v_center - (center_line_width / 2.0)).round(), + y: (bounds_y + v_center - (center_line_width / 2.0)) + .round(), width: bar_width, height: center_line_width, }, @@ -249,9 +271,14 @@ impl phase_meter::Renderer for Renderer { if normal.value() < 0.499 || normal.value() > 0.501 { let meter_span = bounds_height - (border_width * 2.0); - let normal_offset = ((1.0 - normal.value()) * meter_span).round(); - let poor_offset = (meter_span * (1.0 - (tier_positions.poor.value() / 2.0))).round(); - let good_offset = (meter_span * (1.0 - (0.5 + (tier_positions.good.value() / 2.0)))).round(); + let normal_offset = + ((1.0 - normal.value()) * meter_span).round(); + let poor_offset = (meter_span + * (1.0 - (tier_positions.poor.value() / 2.0))) + .round(); + let good_offset = (meter_span + * (1.0 - (0.5 + (tier_positions.good.value() / 2.0)))) + .round(); let normal_tier = tier(normal, tier_positions); @@ -262,7 +289,8 @@ impl phase_meter::Renderer for Renderer { x: bar_x, y: bounds_y + v_center, width: bar_width, - height: poor_offset - v_center + border_width, + height: poor_offset - v_center + + border_width, }, background: Background::Color(style.poor_color), border_radius: 0, @@ -274,7 +302,8 @@ impl phase_meter::Renderer for Renderer { x: bar_x, y: bounds_y + poor_offset, width: bar_width, - height: normal_offset - poor_offset + border_width, + height: normal_offset - poor_offset + + border_width, }, background: Background::Color(style.bad_color), border_radius: 0, @@ -284,18 +313,24 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, poor_bar, bad_bar, center_line], + primitives: vec![ + back, + poor_bar, + bad_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } PhaseTier::Poor => { let poor_bar = Primitive::Quad { bounds: Rectangle { x: bar_x, y: bounds_y + v_center, width: bar_width, - height: normal_offset - v_center + border_width, + height: normal_offset - v_center + + border_width, }, background: Background::Color(style.poor_color), border_radius: 0, @@ -305,11 +340,15 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, poor_bar, center_line], + primitives: vec![ + back, + poor_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } PhaseTier::Okay => { let okay_bar = Primitive::Quad { bounds: Rectangle { @@ -326,11 +365,15 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, okay_bar, center_line], + primitives: vec![ + back, + okay_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } PhaseTier::Good => { let good_bar = Primitive::Quad { bounds: Rectangle { @@ -359,11 +402,16 @@ impl phase_meter::Renderer for Renderer { ( Primitive::Group { - primitives: vec![back, okay_bar, good_bar, center_line], + primitives: vec![ + back, + okay_bar, + good_bar, + center_line, + ], }, MouseCursor::default(), ) - }, + } } } else { ( @@ -376,4 +424,4 @@ impl phase_meter::Renderer for Renderer { } } } -} \ No newline at end of file +}