Skip to content

Commit

Permalink
Implementation of elements adding to List Editor and a lot of interna…
Browse files Browse the repository at this point in the history
…l API (#6390)
  • Loading branch information
wdanilo authored Apr 25, 2023
1 parent 952de24 commit 115e9b4
Show file tree
Hide file tree
Showing 8 changed files with 878 additions and 455 deletions.
438 changes: 297 additions & 141 deletions lib/rust/ensogl/component/list-editor/src/lib.rs

Large diffs are not rendered by default.

431 changes: 185 additions & 246 deletions lib/rust/ensogl/component/slider/src/lib.rs

Large diffs are not rendered by default.

52 changes: 24 additions & 28 deletions lib/rust/ensogl/component/slider/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
use ensogl_core::display::shape::*;
use ensogl_core::prelude::*;

use crate::Kind;
use crate::LabelPosition;
use crate::SliderOrientation;
use crate::ValueIndicator;

use ensogl_core::application::Application;
use ensogl_core::data::color;
Expand Down Expand Up @@ -264,33 +263,30 @@ impl Model {
}

/// Set whether the lower overfow marker is visible.
pub fn set_value_indicator(&self, indicator: &ValueIndicator) {
pub fn kind(&self, indicator: &Kind) {
match indicator {
ValueIndicator::Track => {
Kind::SingleValue => {
self.root.add_child(&self.track);
self.root.remove_child(&self.thumb);
}
ValueIndicator::Thumb => {
Kind::Scrollbar(_) => {
self.root.add_child(&self.thumb);
self.root.remove_child(&self.track);
}
}
}

/// Set the position of the value indicator.
pub fn set_indicator_position(
&self,
(fraction, size, orientation): &(f32, f32, SliderOrientation),
) {
pub fn set_indicator_position(&self, (fraction, size, orientation): &(f32, f32, Axis2)) {
self.thumb.slider_fraction.set(*fraction);
match orientation {
SliderOrientation::Horizontal => {
Axis2::X => {
self.track.slider_fraction_horizontal.set(fraction.clamp(0.0, 1.0));
self.track.slider_fraction_vertical.set(1.0);
self.thumb.thumb_width.set(*size);
self.thumb.thumb_height.set(1.0);
}
SliderOrientation::Vertical => {
Axis2::Y => {
self.track.slider_fraction_horizontal.set(1.0);
self.track.slider_fraction_vertical.set(fraction.clamp(0.0, 1.0));
self.thumb.thumb_width.set(1.0);
Expand All @@ -300,17 +296,17 @@ impl Model {
}

/// Set the size and orientation of the overflow markers.
pub fn set_overflow_marker_shape(&self, (size, orientation): &(f32, SliderOrientation)) {
pub fn set_overflow_marker_shape(&self, (size, orientation): &(f32, Axis2)) {
let margin = Vector2(COMPONENT_MARGIN * 2.0, COMPONENT_MARGIN * 2.0);
let size = Vector2(*size, *size) * OVERFLOW_MARKER_SIZE + margin;
self.overflow_lower.set_size(size);
self.overflow_upper.set_size(size);
match orientation {
SliderOrientation::Horizontal => {
Axis2::X => {
self.overflow_lower.set_rotation_z(std::f32::consts::FRAC_PI_2);
self.overflow_upper.set_rotation_z(-std::f32::consts::FRAC_PI_2);
}
SliderOrientation::Vertical => {
Axis2::Y => {
self.overflow_lower.set_rotation_z(std::f32::consts::PI);
self.overflow_upper.set_rotation_z(0.0);
}
Expand All @@ -320,17 +316,17 @@ impl Model {
/// Set the position of the overflow markers.
pub fn set_overflow_marker_position(
&self,
(comp_width, comp_height, orientation): &(f32, f32, SliderOrientation),
(comp_width, comp_height, orientation): &(f32, f32, Axis2),
) {
match orientation {
SliderOrientation::Horizontal => {
Axis2::X => {
let pos_x = comp_width / 2.0 - comp_height / 4.0;
self.overflow_lower.set_x(-pos_x);
self.overflow_lower.set_y(0.0);
self.overflow_upper.set_x(pos_x);
self.overflow_upper.set_y(0.0);
}
SliderOrientation::Vertical => {
Axis2::Y => {
let pos_y = comp_height / 2.0 - comp_width / 4.0;
self.overflow_lower.set_x(0.0);
self.overflow_lower.set_y(-pos_y);
Expand Down Expand Up @@ -367,19 +363,19 @@ impl Model {
f32,
f32,
LabelPosition,
SliderOrientation,
Axis2,
),
) {
let label_position_x = match orientation {
SliderOrientation::Horizontal => match position {
Axis2::X => match position {
LabelPosition::Inside => -comp_width / 2.0 + comp_height / 2.0,
LabelPosition::Outside => -comp_width / 2.0 - comp_height / 2.0 - lab_width,
},
SliderOrientation::Vertical => -lab_width / 2.0,
Axis2::Y => -lab_width / 2.0,
};
let label_position_y = match orientation {
SliderOrientation::Horizontal => lab_height / 2.0,
SliderOrientation::Vertical => match position {
Axis2::X => lab_height / 2.0,
Axis2::Y => match position {
LabelPosition::Inside => comp_height / 2.0 - comp_width / 2.0,
LabelPosition::Outside => comp_height / 2.0 + comp_width / 2.0 + lab_height,
},
Expand All @@ -388,15 +384,15 @@ impl Model {
}

/// Set whether the slider value text is hidden.
pub fn set_value_text_hidden(&self, hidden: bool) {
if hidden {
self.root.remove_child(&self.value_text_left);
self.root.remove_child(&self.value_text_dot);
self.root.remove_child(&self.value_text_right);
} else {
pub fn show_value(&self, visible: bool) {
if visible {
self.root.add_child(&self.value_text_left);
self.root.add_child(&self.value_text_dot);
self.root.add_child(&self.value_text_right);
} else {
self.root.remove_child(&self.value_text_left);
self.root.remove_child(&self.value_text_dot);
self.root.remove_child(&self.value_text_right);
}
}

Expand Down
27 changes: 26 additions & 1 deletion lib/rust/ensogl/core/src/gui/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ define_style! {
press: f32,
port_selection_layer : bool,
trash: f32,
plus: f32,
}


Expand Down Expand Up @@ -106,6 +107,11 @@ impl Style {
let trash = Some(StyleValue::new(1.0));
Self { trash, ..default() }
}

pub fn plus() -> Self {
let plus = Some(StyleValue::new(1.0));
Self { plus, ..default() }
}
}


Expand Down Expand Up @@ -153,6 +159,7 @@ pub mod shape {
radius: f32,
color: Vector4,
trash: f32,
plus: f32,
) {
let width : Var<Pixels> = "input_size.x".into();
let height : Var<Pixels> = "input_size.y".into();
Expand All @@ -167,13 +174,24 @@ pub mod shape {
let color: Var<color::Rgba> = color.into();
let trash_color: Var<color::Rgba> = color::Rgba::new(0.91, 0.32, 0.32, 1.0).into();
let color = color.mix(&trash_color, &trash);

let plus_color: Var<color::Rgba> = color::Rgba::new(0.39, 0.71, 0.15, 1.0).into();
let color = color.mix(&plus_color, &plus);


let cursor = cursor.fill(color);

let trash_bar1 = Rect((2.px(), (&height - 4.px()) * &trash - 1.px()));
let trash_bar2 = trash_bar1.rotate((PI/2.0).radians());
let trash_bar_x = (trash_bar1 + trash_bar2).rotate((PI/4.0).radians());
let trash_bar_x = trash_bar_x.fill(color::Rgba::new(1.0,1.0,1.0,0.8));
let cursor = cursor + trash_bar_x;

let plus_bar1 = Rect((2.px(), (&height - 4.px()) * &plus - 1.px()));
let plus_bar2 = plus_bar1.rotate((PI/2.0).radians());
let plus_sign = plus_bar1 + plus_bar2;
let plus_sign = plus_sign.fill(color::Rgba::new(1.0,1.0,1.0,0.8));

let cursor = cursor + trash_bar_x + plus_sign;
cursor.into()
}
}
Expand Down Expand Up @@ -298,6 +316,7 @@ impl Cursor {
let host_attached_weight = Easing::new(network);
let port_selection_layer_weight = Animation::<f32>::new(network);
let trash = Animation::<f32>::new(network);
let plus = Animation::<f32>::new(network);

host_attached_weight.set_duration(300.0);
color_lab.set_target_value(DEFAULT_COLOR.opaque.into());
Expand All @@ -316,6 +335,7 @@ impl Cursor {
model.for_each_view(|vw| {vw.set_size(dim);});
});
eval trash.value ((v) model.for_each_view(|vw| vw.trash.set(*v)));
eval plus.value ((v) model.for_each_view(|vw| vw.plus.set(*v)));

alpha <- all_with(&color_alpha.value,&inactive_fade.value,|s,t| s*t);

Expand Down Expand Up @@ -394,6 +414,11 @@ impl Cursor {
Some(t) => trash.target.emit(t.value.unwrap_or(0.0)),
}

match &new_style.plus {
None => plus.target.emit(0.0),
Some(t) => plus.target.emit(t.value.unwrap_or(0.0)),
}

*model.style.borrow_mut() = new_style.clone();
});

Expand Down
Loading

0 comments on commit 115e9b4

Please sign in to comment.