Skip to content

Commit

Permalink
widget metadata -> configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Frizi committed Apr 21, 2023
1 parent 1846acf commit 35a4a3f
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 105 deletions.
12 changes: 6 additions & 6 deletions app/gui/src/controller/graph/widget.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Widget controller.
//!
//! The Widget Controller is responsible for querying the language server for information about
//! the node's widget metadata or resolving it from local cache.
//! the node's widget configuration or resolving it from local cache.


mod metadata;
mod configuration;
mod response;

use crate::prelude::*;
Expand Down Expand Up @@ -67,11 +67,11 @@ define_endpoints_2! {
}
}

/// Graph widgets controller. Handles requests for widget metadata using visualizations. Maps
/// Graph widgets controller. Handles requests for widget configuration using visualizations. Maps
/// response data to the relevant node Id updates, and dispatches them over the FRP output.
/// Guarantees that each individual query eventually receives an update. It internally caches the
/// results of the last queries, so that the metadata can be delivered to the presenter even when no
/// visualization change is necessary.
/// results of the last queries, so that the configuration can be delivered to the presenter even
/// when no visualization change is necessary.
#[derive(Debug, Deref)]
pub struct Controller {
#[deref]
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Model {
) -> Option<(NodeId, CallWidgetsConfig)> {
let query_data = self.widget_queries.get_mut(&target)?;

let (definitions, errors) = metadata::deserialize_widget_definitions(&data);
let (definitions, errors) = configuration::deserialize_widget_definitions(&data);

for error in errors {
error!("{:?}", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn deserialize_widget_definitions(
let msg = "Failed to deserialize widget data for argument";
e.context(format!("{msg} '{argument_name}'"))
})?;
let meta = widget.map(to_metadata);
let meta = widget.map(to_configuration);
let argument_name = argument_name.to_owned();
Ok(ArgumentWidgetConfig { argument_name, meta })
},
Expand All @@ -46,25 +46,25 @@ pub fn deserialize_widget_definitions(
}
}

/// == Conversion to Widget Metadata IDE structs ===
/// == Conversion to Widget Configuration IDE structs ===
/// Convert a widget definition from the engine response into a IDE internal widget metadata struct.
/// See [`widget::Metadata`] for more information.
fn to_metadata(resp: response::WidgetDefinition) -> widget::Metadata {
widget::Metadata { display: resp.display, config: to_config(resp.inner), has_port: true }
/// Convert a widget definition from the engine response into a IDE internal widget configuration
/// struct. See [`widget::Configuration`] for more information.
fn to_configuration(resp: response::WidgetDefinition) -> widget::Configuration {
widget::Configuration { display: resp.display, kind: to_kind(resp.inner), has_port: true }
}

fn to_config(inner: response::WidgetKindDefinition) -> widget::Config {
fn to_kind(inner: response::WidgetKindDefinition) -> widget::DynConfig {
match inner {
response::WidgetKindDefinition::SingleChoice { label, values } =>
widget::single_choice::Config {
label: label.map(Into::into),
entries: Rc::new(to_entries(&values)),
}
.into(),
response::WidgetKindDefinition::ListEditor { item_editor, item_default } =>
response::WidgetKindDefinition::ListEditor { item_widget, item_default } =>
widget::list_editor::Config {
item_editor: Some(Rc::new(to_metadata(*item_editor))),
item_widget: Some(Rc::new(to_configuration(*item_widget))),
item_default: item_default.into(),
}
.into(),
Expand Down
2 changes: 1 addition & 1 deletion app/gui/src/controller/graph/widget/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(super) enum WidgetKindDefinition<'a> {
ListEditor {
/// The widget to use for editing the items.
#[serde(borrow, alias = "item_editor")]
item_editor: Box<WidgetDefinition<'a>>,
item_widget: Box<WidgetDefinition<'a>>,
/// The default value for new items inserted when the user adds a new element.
#[serde(borrow)]
item_default: &'a str,
Expand Down
17 changes: 10 additions & 7 deletions app/gui/view/graph-editor/src/component/node/input/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ensogl::display::traits::*;
use crate::component::type_coloring;
use crate::node;
use crate::node::input::widget;
use crate::node::input::widget::MetadataPointer;
use crate::node::input::widget::OverrideKey;
use crate::node::profiling;
use crate::view;
use crate::CallWidgetsConfig;
Expand Down Expand Up @@ -238,13 +238,16 @@ impl Model {
Some(cursor::Style::new_highlight(display_object, size, radius, color))
}

/// Apply widget configuration to widgets in this input area.
fn set_widget_configuration(&self, config: &CallWidgetsConfig) {
/// Configure widgets associated with single Enso call expression, overriding default widgets
/// generated from span tree. The provided widget configuration is merged with configurations
/// already present in the widget tree. Setting a widget configuration to `None` will remove
/// an override, and a default widget will be used.
fn apply_widget_configuration(&self, config: &CallWidgetsConfig) {
let CallWidgetsConfig { call_id, definitions } = config;
for definition in definitions.iter() {
let argument_name = definition.argument_name.clone().into();
let meta_pointer = MetadataPointer { call_id: *call_id, argument_name };
self.widget_tree.set_metadata(meta_pointer, definition.meta.clone());
let override_key = OverrideKey { call_id: *call_id, argument_name };
self.widget_tree.set_config_override(override_key, definition.meta.clone());
}
}

Expand Down Expand Up @@ -324,7 +327,7 @@ ensogl::define_endpoints! {
/// contains the color of connected edge.
set_connected (Crumbs, Option<color::Lcha>),

/// Update widget metadata for widgets already present in this input area.
/// Update widget configuration for widgets already present in this input area.
update_widgets (CallWidgetsConfig),

/// Enable / disable port hovering. The optional type indicates the type of the active edge
Expand Down Expand Up @@ -511,7 +514,7 @@ impl Area {

// === Widgets ===

eval frp.update_widgets((a) model.set_widget_configuration(a));
eval frp.update_widgets((a) model.apply_widget_configuration(a));
eval frp.set_connected(((crumbs,status)) model.set_connected(crumbs,*status));
eval frp.set_expression_usage_type(((id,tp)) model.set_expression_usage_type(*id,tp.clone()));
eval frp.set_disabled ((disabled) model.widget_tree.set_disabled(*disabled));
Expand Down
8 changes: 4 additions & 4 deletions app/gui/view/graph-editor/src/component/node/input/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
use crate::prelude::*;

use crate::component::node::input::widget::Config;
use crate::component::node::input::widget::ConfigContext;
use crate::component::node::input::widget::ConnectionData;
use crate::component::node::input::widget::DynConfig;
use crate::component::node::input::widget::DynWidget;
use crate::component::node::input::widget::EdgeData;
use crate::component::node::input::widget::SpanWidget;
use crate::component::node::input::widget::WidgetsFrp;

Expand Down Expand Up @@ -213,7 +213,7 @@ impl Port {
}

/// Configure the port and its attached widget.
pub fn configure(&mut self, config: &Config, ctx: ConfigContext) {
pub fn configure(&mut self, config: &DynConfig, ctx: ConfigContext) {
self.crumbs.replace(ctx.span_node.crumbs.clone());
self.set_connected(ctx.info.connection);
self.set_port_layout(&ctx);
Expand All @@ -223,7 +223,7 @@ impl Port {

/// Update connection status of this port. Changing the connection status will add or remove the
/// port's visible shape from the display hierarchy.
fn set_connected(&self, status: Option<ConnectionData>) {
fn set_connected(&self, status: Option<EdgeData>) {
match status {
Some(data) => {
self.port_root.add_child(&self.port_shape);
Expand Down
Loading

0 comments on commit 35a4a3f

Please sign in to comment.