Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyDM committed Jun 15, 2020
1 parent 9a6d33c commit affc12f
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 58 deletions.
20 changes: 10 additions & 10 deletions examples/phase_meter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -111,13 +109,15 @@ impl Application for PhaseMeterApp {
fn view(&mut self) -> Element<Message> {
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)
Expand Down Expand Up @@ -240,4 +240,4 @@ impl phase_meter::StyleSheet for CustomPhaseMeterStyle {
center_line_color: Color::WHITE,
}
}
}
}
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
12 changes: 6 additions & 6 deletions src/native/phase_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -169,7 +166,8 @@ impl Default for State {
}
}

impl<'a, Message, Renderer> Widget<Message, Renderer> for PhaseMeter<'a, Renderer>
impl<'a, Message, Renderer> Widget<Message, Renderer>
for PhaseMeter<'a, Renderer>
where
Renderer: self::Renderer,
{
Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion src/style/default_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
pub static PHASE_METER_CENTER_LINE: Color = Color::from_rgb(0.92, 0.92, 0.92);
2 changes: 1 addition & 1 deletion src/style/phase_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ where
fn from(style: T) -> Self {
Box::new(style)
}
}
}
120 changes: 84 additions & 36 deletions src/wgpu/phase_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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)) {
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
(
Expand All @@ -226,7 +247,7 @@ impl phase_meter::Renderer for Renderer {
MouseCursor::default(),
)
}
},
}
Orientation::Vertical => {
let v_center = (bounds_height / 2.0).round();

Expand All @@ -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,
},
Expand All @@ -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);

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
(
Expand All @@ -376,4 +424,4 @@ impl phase_meter::Renderer for Renderer {
}
}
}
}
}

0 comments on commit affc12f

Please sign in to comment.