Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing visualizations #7164

Merged
merged 19 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
self-review fixes
  • Loading branch information
vitvakatu committed Jun 30, 2023
commit 938a2f09d1746f13280fd42f5bb8b35f55b4792b
5 changes: 2 additions & 3 deletions app/gui/view/documentation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![warn(unused_import_braces)]
#![warn(unused_qualifications)]

use ensogl::display::shape::Rectangle;
use ensogl::display::shape::*;
use ensogl::prelude::*;
use ensogl::system::web::traits::*;

Expand All @@ -32,7 +32,6 @@ use ensogl::data::color;
use ensogl::display;
use ensogl::display::scene::Scene;
use ensogl::display::shape::primitive::StyleWatch;
use ensogl::display::shape::StyleWatchFrp;
use ensogl::display::DomSymbol;
use ensogl::system::web;
use ensogl::Animation;
Expand Down Expand Up @@ -104,7 +103,7 @@ impl Model {
let inner_div = web::document.create_div_or_panic();
let inner_dom = DomSymbol::new(&inner_div);
let overlay = Rectangle::new().build(|r| {
r.set_color(color::Rgba::red());
r.set_color(INVISIBLE_HOVER_COLOR);
});
let caption_div = web::document.create_div_or_panic();
let caption_dom = DomSymbol::new(&caption_div);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ pub mod visualization_chooser;
// === Constants ===
// =================

/// Default width and height of the visualisation container.
/// Default width and height of the visualization container.
pub const DEFAULT_SIZE: (f32, f32) = (200.0, 200.0);
/// Minimal allowed size of the visualization container.
const MIN_SIZE: Vector2 = Vector2(200.0, 200.0);
const PADDING: f32 = 20.0;
const CORNER_RADIUS: f32 = super::super::node::CORNER_RADIUS;
const ACTION_BAR_HEIGHT: f32 = 2.0 * CORNER_RADIUS;
const MIN_SIZE: Vector2 = Vector2(200.0, 200.0);



Expand Down Expand Up @@ -157,6 +158,7 @@ ensogl::define_endpoints_2! {
deselect (),
set_size (Vector2),
set_vis_input_type (Option<enso::Type>),
// Set width of the container, preserving the current height.
set_width (f32),
}
Output {
Expand Down Expand Up @@ -204,7 +206,6 @@ impl View {
let resize_grip = Rectangle::default().build(|r| {
r.set_color(INVISIBLE_HOVER_COLOR);
});
resize_grip.set_xy(Vector2(10.0, -10.0));
display_object.add_child(&background);
display_object.add_child(&overlay);
overlay.add_child(&resize_grip);
Expand Down Expand Up @@ -243,11 +244,14 @@ impl View {
self.loading_spinner.unset_parent();
}

fn init_background(&self) {
fn init_resize_grip(&self, styles: &StyleWatch) {
let offset_x = styles.get_number(theme::resize_grip::offset_x);
let offset_y = styles.get_number(theme::resize_grip::offset_y);
self.resize_grip.set_xy(Vector2(offset_x, offset_y));
}

fn init_background(&self, styles: &StyleWatch) {
let background = &self.background_dom;
// FIXME : StyleWatch is unsuitable here, as it was designed as an internal tool for shape
// system (#795)
let styles = StyleWatch::new(&self.scene.style_sheet);
let bg_color =
styles.get_color(ensogl_hardcoded_theme::graph_editor::visualization::background);
let bg_hex = format!(
Expand Down Expand Up @@ -278,7 +282,9 @@ impl View {
}

fn init(self) -> Self {
self.init_background();
let styles = StyleWatch::new(&self.scene.style_sheet);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FIXME comment was lost. You can also take the chance and change it to StyleWatchFRP (but it would need some FRP nodes for refreshing).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the fixme comment, also used FRP for part of the stuff in this method. The main stopper is shadow for dom, I don't think we have FRP-based API for that at the moment.

self.init_background(&styles);
self.init_resize_grip(&styles);
self.init_spinner();
self.show_waiting_screen();
self.set_layer(visualization::Layer::Default);
Expand Down Expand Up @@ -594,12 +600,26 @@ impl Container {
output.fullscreen <+ output.view_state.map(|state| state.is_fullscreen()).on_change();
output.visible <+ output.view_state.map(|state| state.is_visible()).on_change();

visualisation_not_selected <- input.set_visualization.map(|t| t.is_none());
input_type_not_set <- input.set_vis_input_type.is_some().not();
uninitialised <- visualisation_not_selected && input_type_not_set;
set_default_visualisation <- uninitialised.on_change().on_true().map(|_| {
Some(visualization::Registry::default_visualisation())
});
vis_input_type_changed <- input.set_vis_input_type.on_change();
vis_input_type_changed_without_selection <-
vis_input_type_changed.gate(&visualisation_not_selected).unwrap();
set_default_visualisation_for_type <- vis_input_type_changed_without_selection.map(f!((tp) {
registry.default_visualization_for_type(tp)
}));
set_default_visualisation <- any(
&set_default_visualisation, &set_default_visualisation_for_type);


// Drag-resize.
// === Drag-resize ===

on_down <- on_down.gate(&output.visible);
on_up <- on_up_source.gate(&output.visible);

is_down <- bool(&on_up, &on_down);
on_move_down <- on_move.gate(&is_down);
glob_pos_on_down <- on_down.map(|event| event.client_centered());
Expand All @@ -608,44 +628,27 @@ impl Container {
pos_on_move_down <- glob_pos_on_move_down.map(f!((p) model.screen_to_object_space(*p)));
pos_diff <- pos_on_move_down.map2(&pos_on_down, |a, b| a - b);
size_on_drag_start <- output.size.sample(&on_down);

output.size <+ pos_diff.map3(&size_on_drag_start, &output.view_state, f!([model](diff, size, view_state) {
let diff = Vector2(diff.x, -diff.y);
let new_size = size + diff;
model.resize(new_size, *view_state)
}));

// Size changes.

// === Adjust width to the width of the node ===

size_was_not_changed_manually <- any(...);
size_was_not_changed_manually <+ init.constant(true);
size_was_not_changed_manually <+ pos_diff.filter(|d| *d != Vector2::default()).constant(false);
size_was_not_changed_manually <+ output.visible.on_change().constant(true);

width_target <- input.set_width.identity();
on_visible <- output.visible.on_true();
width_change_after_open <- width_target.sample(&on_visible);
width_anim.target <+ width_target.gate(&size_was_not_changed_manually);
new_size <- width_anim.value.map2(&output.size, |w, s| Vector2(*w, s.y));
size_reset <- width_change_after_open.map(|w| Vector2(*w, DEFAULT_SIZE.1));
size_change <- any3(&new_size, &input.set_size, &size_reset);

output.size <+ size_change.map2(&output.view_state, f!((new_size, view_state) model.resize(*new_size, *view_state)));

visualisation_not_selected <- input.set_visualization.map(|t| t.is_none());
input_type_not_set <- input.set_vis_input_type.is_some().not();
uninitialised <- visualisation_not_selected && input_type_not_set;
set_default_visualisation <- uninitialised.on_change().on_true().map(|_| {
Some(visualization::Registry::default_visualisation())
});
vis_input_type_changed <- input.set_vis_input_type.on_change();
vis_input_type_changed_without_selection <-
vis_input_type_changed.gate(&visualisation_not_selected).unwrap();
set_default_visualisation_for_type <- vis_input_type_changed_without_selection.map(f!((tp) {
registry.default_visualization_for_type(tp)
}));
set_default_visualisation <- any(
&set_default_visualisation, &set_default_visualisation_for_type);

}


Expand Down
4 changes: 4 additions & 0 deletions lib/rust/ensogl/app/theme/hardcoded/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ define_themes! { [light:0, dark:1]
size = 8.0 , 8.0;
offset = 0.0 , 0.0;
}
resize_grip {
offset_x = 10.0, 10.0;
offset_y = 10.0, 10.0;
}
text_grid {
font = "DejaVu Sans Mono" , "DejaVu Sans Mono";
font_size = 12.0 , 12.0;
Expand Down
4 changes: 0 additions & 4 deletions lib/rust/ensogl/core/src/display/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ fn partition_layer<S: display::shape::primitive::system::Shape>(
/// ```plaintext
/// - root
/// ├── viz
/// │ ├── viz_background
/// │ ├── viz_resize_grip
/// │ ├── viz_overlay
/// ├── below_main
Expand Down Expand Up @@ -690,7 +689,6 @@ pub struct HardcodedLayers {
pub DETACHED: Layer,
pub root: Layer,
pub viz: Layer,
pub viz_background: RectLayerPartition,
pub viz_resize_grip: RectLayerPartition,
pub viz_overlay: RectLayerPartition,
pub below_main: Layer,
Expand Down Expand Up @@ -744,7 +742,6 @@ impl HardcodedLayers {
let root = Layer::new_with_camera("root", &main_cam);

let viz = root.create_sublayer("viz");
let viz_background = partition_layer(&viz, "viz_bg");
let viz_resize_grip = partition_layer(&viz, "viz_resize_grip");
let viz_overlay = partition_layer(&viz, "viz_overlay");
let below_main = root.create_sublayer("below_main");
Expand Down Expand Up @@ -783,7 +780,6 @@ impl HardcodedLayers {
DETACHED,
root,
viz,
viz_background,
viz_resize_grip,
viz_overlay,
below_main,
Expand Down