Skip to content

Commit

Permalink
added VectorLine style to Knob
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyDM authored and BillyDM committed May 31, 2020
1 parent 336c73f commit 7a3c118
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 165 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iced_audio"
version = "0.1.0"
version = "0.1.1"
authors = ["Billy Messenger <https://github.com/BillyDM>"]
license = "MIT"
edition = "2018"
Expand Down Expand Up @@ -29,6 +29,6 @@ name = "simple"
# https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
iced = { version = "0.1" }
iced = { version = "0.1", features = ["canvas"] }
iced_native = "0.2"
iced_wgpu = "0.2"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cargo run --example simple --release
* [x] XYPad

## Widgets partially implemented
* [x] Knob - Due to current limitations of iced, only a simple flat circle style is implemented for now. There is also a known bug where input will stop when the mouse leaves the window under some conditions.
* [x] Knob - Due to current limitations of iced, the texture style is not implemented yet. There is also a known bug where input will stop when the mouse leaves the window under some conditions.

## Roadmap of planned widgets
### Inputs
Expand Down
5 changes: 4 additions & 1 deletion examples/tour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub use tour_steps::style;
static STARTING_STEP: usize = 0;

pub fn main() {
Tour::run(Settings::default())
Tour::run(Settings {
antialiasing: true,
..Settings::default()
})
}

pub struct Tour {
Expand Down
68 changes: 49 additions & 19 deletions examples/tour_steps/step_knobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub enum KnobsID {
Int,
DB,
Octave,
Vector,
Circle,
Line,
Texture,
}

Expand All @@ -43,9 +44,13 @@ pub struct KnobsStep {
knob_oct_state: knob::State,
knob_oct_label: String,

knob_vector_param: FloatParam<KnobsID>,
knob_vector_state: knob::State,
knob_vector_label: String,
knob_circle_param: FloatParam<KnobsID>,
knob_circle_state: knob::State,
knob_circle_label: String,

knob_line_param: FloatParam<KnobsID>,
knob_line_state: knob::State,
knob_line_label: String,

/*
knob_texture_param: FloatParam<KnobsID>,
Expand Down Expand Up @@ -79,8 +84,11 @@ impl Default for KnobsStep {
let knob_oct_param = OctaveParam::<KnobsID>::new(
KnobsID::Octave, 20.0, 20_480.0, 1000.0, 1000.0);

let knob_vector_param = FloatParam::<KnobsID>::new(
KnobsID::Vector, -1.0, 1.0, 0.0, 0.0);
let knob_circle_param = FloatParam::<KnobsID>::new(
KnobsID::Circle, -1.0, 1.0, 0.0, 0.0);

let knob_line_param = FloatParam::<KnobsID>::new(
KnobsID::Line, -1.0, 1.0, 0.0, 0.0);

/*
let knob_texture_param = FloatParam::<KnobsID>::new(
Expand Down Expand Up @@ -119,11 +127,17 @@ impl Default for KnobsStep {
),
knob_oct_label: String::from("Octave Freq Range"),

knob_vector_param,
knob_vector_state: knob::State::new(
&knob_vector_param
knob_circle_param,
knob_circle_state: knob::State::new(
&knob_circle_param
),
knob_circle_label: String::from("Custom Vector Circle Style"),

knob_line_param,
knob_line_state: knob::State::new(
&knob_line_param
),
knob_vector_label: String::from("Custom Vector Style"),
knob_line_label: String::from("Custom Vector Line Style"),

/*
knob_texture_param,
Expand Down Expand Up @@ -231,10 +245,15 @@ impl KnobsStep {
self.output_text = crate::info_text_octave(id,
self.knob_oct_param.value());
},
KnobsID::Vector => {
self.knob_vector_param.set_from_normal(normal);
KnobsID::Circle => {
self.knob_circle_param.set_from_normal(normal);
self.output_text = crate::info_text_f32(id,
self.knob_circle_param.value());
},
KnobsID::Line => {
self.knob_line_param.set_from_normal(normal);
self.output_text = crate::info_text_f32(id,
self.knob_vector_param.value());
self.knob_line_param.value());
},
KnobsID::Texture => {
/*
Expand Down Expand Up @@ -280,13 +299,21 @@ impl KnobsStep {
)
.tick_marks(&self.octave_tick_marks);

let knob_vector = Knob::new(
&mut self.knob_vector_state,
&self.knob_vector_param,
let knob_circle = Knob::new(
&mut self.knob_circle_state,
&self.knob_circle_param,
Message::KnobsChanged,
)
.tick_marks(&self.float_tick_marks)
.style(style::KnobCustomStyle);
.style(style::KnobCustomStyleCircle);

let knob_line = Knob::new(
&mut self.knob_line_state,
&self.knob_line_param,
Message::KnobsChanged,
)
.tick_marks(&self.float_tick_marks)
.style(style::KnobCustomStyleLine);

/*
let knob_texture = Knob::new(
Expand Down Expand Up @@ -332,8 +359,11 @@ impl KnobsStep {
.max_height(400)
.width(Length::Fill)
.spacing(10)
.push(Text::new(&self.knob_vector_label))
.push(knob_vector)
.push(Text::new(&self.knob_circle_label))
.push(knob_circle)

.push(Text::new(&self.knob_line_label))
.push(knob_line)

//.push(Text::new(&self.knob_texture_label))
//.push(knob_texture)
Expand Down
60 changes: 58 additions & 2 deletions examples/tour_steps/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ impl v_slider::StyleSheet for VSliderTextureStyle {

// Custom style for the Knob

pub struct KnobCustomStyle;
impl knob::StyleSheet for KnobCustomStyle {
pub struct KnobCustomStyleCircle;
impl knob::StyleSheet for KnobCustomStyleCircle {
fn active(&self) -> knob::Style {
knob::Style::VectorCircle(
knob::VectorCircleStyle {
Expand Down Expand Up @@ -375,6 +375,62 @@ impl knob::StyleSheet for KnobCustomStyle {
}
}

// Custom style for the Knob

pub struct KnobCustomStyleLine;
impl knob::StyleSheet for KnobCustomStyleLine {
fn active(&self) -> knob::Style {
knob::Style::VectorLine(
knob::VectorLineStyle {
knob_color: KNOB_COLOR,
knob_border_width: 0,
knob_border_color: KNOB_BORDER_COLOR,
notch_color: Color::from_rgb(0.0, 0.8, 0.0),
notch_width: 4.0,
notch_scale: 0.35.into(),
notch_offset: 0.21.into(),
})
}

#[allow(irrefutable_let_patterns)]
fn hovered(&self) -> knob::Style {
let active = self.active();
if let knob::Style::VectorLine(active) = self.active() {

knob::Style::VectorLine(
knob::VectorLineStyle {
knob_border_width: 2,
notch_width: 3.0,
notch_color: Color::from_rgb(0.0, 0.85, 0.0),
..active
})

} else { active }
}

fn dragging(&self) -> knob::Style {
self.hovered()
}

fn tick_mark_style(&self) -> Option<knob::TickMarkStyle> {
Some(knob::TickMarkStyle::Line(knob::LineTickMarks {
width_tier_1: 2.0,
width_tier_2: 1.0,
width_tier_3: 1.0,

length_tier_1: 4.0,
length_tier_2: 2.5,
length_tier_3: 2.5,

color_tier_1: Color::from_rgb(0.56, 0.56, 0.56),
color_tier_2: Color::from_rgb(0.45, 0.45, 0.45),
color_tier_3: Color::from_rgb(0.45, 0.45, 0.45),

offset: 2.1,
}))
}
}


// Custom style for the Texture VSlider

Expand Down
Binary file modified screenshots/Knobs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7a3c118

Please sign in to comment.