Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Implement number and range pickers. #1524

Merged
merged 29 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a0191bb
feat: Implement number and range pickers.
MichaelMauderer Apr 26, 2021
2305feb
chore: Update changelog.
MichaelMauderer Apr 26, 2021
6f9b5ad
Apply style suggestions from code review
MichaelMauderer Apr 28, 2021
216897f
refactor: Rename `NeverDrop` to `Leak` and make it available through …
MichaelMauderer Apr 28, 2021
322b24e
refactor:Turn `Bounds` and `Range` into a common struct with named fi…
MichaelMauderer Apr 28, 2021
7860a30
refactor: Add tests.
MichaelMauderer Apr 28, 2021
5ef4bbe
fix: Remove unused code.
MichaelMauderer May 4, 2021
ff06c1e
dox: Add missing doc.
MichaelMauderer May 4, 2021
f8702af
redactor+doc: Better document decimal_aligned helper. Remove unused c…
MichaelMauderer May 4, 2021
d0c29e8
doc: Add reference to issue about locales.
MichaelMauderer May 4, 2021
a2ef02b
refactor: Make utility fields public instead of marking them asd dead…
MichaelMauderer May 4, 2021
3fe425e
style: Formatting and alignment.
MichaelMauderer May 4, 2021
b19a523
style: Code formatting.
MichaelMauderer May 4, 2021
3bd4451
style: Code formatting.
MichaelMauderer May 4, 2021
4949537
Update src/rust/ensogl/lib/components/src/selector/common/base_frp.rs
MichaelMauderer May 4, 2021
89c1718
style: Limit line length.
MichaelMauderer May 4, 2021
4f1d71f
test+refactor: Extend tests.
MichaelMauderer May 4, 2021
d2982c1
refactor: Fix clippy lints.
MichaelMauderer May 4, 2021
b75c2d1
Merge branch 'develop' into wip/mm/ide-1199-slider-component
MichaelMauderer May 4, 2021
fc688e1
feat: Implement custom track colors.
MichaelMauderer May 5, 2021
0369a66
Merge branch 'develop' into wip/mm/ide-1199-slider-component
MichaelMauderer May 5, 2021
18096bc
chore: Update changelog.
MichaelMauderer May 5, 2021
6246227
style+refactor+docs: Apply review feedback.
MichaelMauderer May 13, 2021
cd9649d
Merge branch 'develop' into wip/mm/ide-1199-slider-component
MichaelMauderer May 13, 2021
9973300
doc: Update overflow shape docs.
MichaelMauderer May 13, 2021
5924dc7
Merge branch 'develop' into wip/mm/ide-1199-slider-component
MichaelMauderer May 21, 2021
cdd0b3b
style: Fix style.
MichaelMauderer May 21, 2021
3087c09
build: Update lock file.
MichaelMauderer May 21, 2021
1f831d8
fix: Compiler upgrade issues.
MichaelMauderer May 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

#### Visual Environment

#### EnsoGL (rendering engine)
- [Components for picking numbers and ranges.][1524]. We now have some internal
re-usable UI components for selecting numbers or a range. Stay tuned for them
appearing in the IDE.
MichaelMauderer marked this conversation as resolved.
Show resolved Hide resolved

#### EnsoGL (rendering engine)

<br/>![Bug Fixes](/docs/assets/tags/bug_fixes.svg)

Expand All @@ -21,6 +24,8 @@ If you're interested in the enhancements and fixes made to the Enso compiler,
you can find their release notes
[here](https://github.com/enso-org/enso/blob/main/RELEASES.md).

[1524]: https://github.com/enso-org/ide/pull/1524

<br/>

# Enso 2.0.0-alpha.4 (2021-05-04)
Expand Down Expand Up @@ -113,9 +118,6 @@ you can find their release notes

- [Unified shadow generation][1411]. Added a toolset to create shadows for
arbitrary UI components.
- [Components for picking numbers and ranges.][1524]. We now have some internal
re-usable UI components for selecting numbers or a range. Stay tuned for them
appearing in the IDE.

<br/>![Bug Fixes](/docs/assets/tags/bug_fixes.svg)

Expand Down Expand Up @@ -238,7 +240,9 @@ you can find their release notes
[1438]: https://github.com/enso-org/ide/pull/1438
[1367]: https://github.com/enso-org/ide/pull/1367
[1445]: https://github.com/enso-org/ide/pull/1445
[1524]: https://github.com/enso-org/ide/pull/1524
[1447]: https://github.com/enso-org/ide/pull/1447
[1471]: https://github.com/enso-org/ide/pull/1471
[1511]: https://github.com/enso-org/ide/pull/1511

<br/>

Expand Down
7 changes: 7 additions & 0 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/rust/ensogl/example/src/leak.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! `Leak` is a utility struct that prevents the wrapped value from being dropped when `Leak` is
//! being dropped. This is achieved by passing the contained value to `std::mem::forget` in the
//! drop implementation iof `Leak`. Can bue used in examples to keep components alive for the whole
MichaelMauderer marked this conversation as resolved.
Show resolved Hide resolved
MichaelMauderer marked this conversation as resolved.
Show resolved Hide resolved
//! lifetime of the application.


MichaelMauderer marked this conversation as resolved.
Show resolved Hide resolved

/// Wrapper that will prevent the wrapped value from being dropped. Instead, the value will be
/// leaked when the `Leak` is dropped.
#[derive(Debug)]
pub struct Leak<T> {
value: Option<T>
}

impl<T> Leak<T> {
/// Constructor. The passed value will be prevented from being dropped. This will cause memory
/// leaks.
pub fn new(value:T) -> Self {
Self{value:Some(value)}
}

/// Return a reference to the wrapped value.
pub fn inner(&self) -> &T {
// Guaranteed to never panic as this is always initialised with `Some` in the constructor.
self.value.as_ref().unwrap()
}

/// Return a mutable reference to the wrapped value.
pub fn inner_mut(&mut self) -> &mut T {
// Guaranteed to never panic as this is always initialised with `Some` in the constructor.
self.value.as_mut().unwrap()
}
}

impl<T> Drop for Leak<T> {
fn drop(&mut self) {
std::mem::forget(self.value.take());
}
}
2 changes: 2 additions & 0 deletions src/rust/ensogl/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#[allow(clippy::option_map_unit_fn)]

mod leak;
pub mod animation;
pub mod complex_shape_system;
pub mod dom_symbols;
Expand All @@ -44,4 +45,5 @@ pub mod text_area;
/// Common types that should be visible across the whole crate.
pub mod prelude {
pub use ensogl_core::prelude::*;
pub use super::leak::*;
}
39 changes: 12 additions & 27 deletions src/rust/ensogl/example/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use crate::prelude::*;
use wasm_bindgen::prelude::*;

use ensogl_core::application::Application;
use ensogl_core::data::color;
use ensogl_core::display::object::ObjectOps;
use ensogl_core::system::web;
use ensogl_gui_components::selector::Bounds;
use ensogl_gui_components::selector;
use ensogl_text_msdf_sys::run_once_initialized;
use ensogl_theme as theme;
Expand All @@ -30,38 +32,18 @@ pub fn entry_point_slider() {
});
}

fn make_number_picker(app:&Application) -> NeverDrop<selector::NumberPicker> {
fn make_number_picker(app:&Application) -> Leak<selector::NumberPicker> {
let slider = app.new_view::<selector::NumberPicker>();
slider.frp.resize(Vector2(200.0,50.0));
app.display.add_child(&slider);
NeverDrop::new(slider)
Leak::new(slider)
}

fn make_range_picker(app:&Application) -> NeverDrop<selector::NumberRangePicker> {
fn make_range_picker(app:&Application) -> Leak<selector::NumberRangePicker> {
let slider = app.new_view::<selector::NumberRangePicker>();
slider.frp.resize(Vector2(400.0,50.0));
app.display.add_child(&slider);
NeverDrop::new(slider)
}

// Utility struct that leaks a struct instead of dropping it. Will cause memory leaks.
struct NeverDrop<T> {
value: Option<T>
}

impl<T> NeverDrop<T> {
fn new(value:T) -> Self {
NeverDrop{value:Some(value)}
}
fn inner(&self) -> &T {
self.value.as_ref().unwrap()
}
}

impl<T> Drop for NeverDrop<T> {
fn drop(&mut self) {
std::mem::forget(self.value.take());
}
Leak::new(slider)
}


Expand All @@ -77,18 +59,21 @@ fn init(app:&Application) {

let slider1 = make_number_picker(app);
slider1.inner().frp.allow_click_selection(true);

let slider2 = make_number_picker(app);
slider2.inner().frp.resize(Vector2(400.0,50.0));
slider2.inner().frp.set_bounds.emit((-100.0,100.0));
slider2.inner().frp.set_bounds.emit(Bounds::new(-100.0,100.0));
slider2.inner().set_position_y(50.0);
slider2.inner().frp.use_overflow_bounds((-150.0,200.0));
slider2.inner().frp.use_overflow_bounds(Bounds::new(-150.0,200.0));
slider2.inner().frp.set_caption(Some("Value:".to_string()));

let slider3 = make_range_picker(app);
slider3.inner().set_position_y(-100.0);
slider3.inner().set_track_color(color::Rgba::new(0.0,0.80,0.80,1.0));

let slider4 = make_range_picker(app);
slider4.inner().set_position_y(-200.0);
slider4.inner().frp.use_overflow_bounds((-2.0,3.0));
slider4.inner().frp.use_overflow_bounds(Bounds::new(-2.0,3.0));
slider4.inner().frp.set_caption(Some("Caption".to_string()));
slider4.inner().set_track_color(color::Rgba::new(0.5,0.70,0.70,1.0));
}
1 change: 1 addition & 0 deletions src/rust/ensogl/lib/components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ ensogl-theme = { path = "../theme" }

[dev-dependencies]
wasm-bindgen-test = { version = "0.3.8" }
float_eq = "0.5"
MichaelMauderer marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 5 additions & 4 deletions src/rust/ensogl/lib/components/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ mod common;
use ensogl_core::application;
use ensogl_core::application::Application;

pub use common::Bounds;


// ====================
// =====================
// === Number Picker ===
// ====================
// =====================

/// UI component for selecting a number.
pub type NumberPicker = crate::component::Component<common::Model,number::Frp>;
Expand All @@ -23,9 +24,9 @@ impl application::View for NumberPicker {



// =========================
// ===========================
// === Number Range Picker ===
// =========================
// ===========================

/// UI component for selecting a number.
pub type NumberRangePicker = crate::component::Component<common::Model,range::Frp>;
Expand Down
Loading