mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-19 17:58:29 +00:00
Merge pull request #87 from kamirr/kek/input_ui
Add WidgetValueTrait::value_widget_always
This commit is contained in:
commit
3336daa78f
@ -569,17 +569,26 @@ where
|
|||||||
for (param_name, param_id) in inputs {
|
for (param_name, param_id) in inputs {
|
||||||
if self.graph[param_id].shown_inline {
|
if self.graph[param_id].shown_inline {
|
||||||
let height_before = ui.min_rect().bottom();
|
let height_before = ui.min_rect().bottom();
|
||||||
|
// NOTE: We want to pass the `user_data` to
|
||||||
|
// `value_widget`, but we can't since that would require
|
||||||
|
// borrowing the graph twice. Here, we make the
|
||||||
|
// assumption that the value is cheaply replaced, and
|
||||||
|
// use `std::mem::take` to temporarily replace it with a
|
||||||
|
// dummy value. This requires `ValueType` to implement
|
||||||
|
// Default, but results in a totally safe alternative.
|
||||||
|
let mut value = std::mem::take(&mut self.graph[param_id].value);
|
||||||
|
|
||||||
if self.graph.connection(param_id).is_some() {
|
if self.graph.connection(param_id).is_some() {
|
||||||
ui.label(param_name);
|
let node_responses = value.value_widget_connected(
|
||||||
|
¶m_name,
|
||||||
|
self.node_id,
|
||||||
|
ui,
|
||||||
|
user_state,
|
||||||
|
&self.graph[self.node_id].user_data,
|
||||||
|
);
|
||||||
|
|
||||||
|
responses.extend(node_responses.into_iter().map(NodeResponse::User));
|
||||||
} else {
|
} else {
|
||||||
// NOTE: We want to pass the `user_data` to
|
|
||||||
// `value_widget`, but we can't since that would require
|
|
||||||
// borrowing the graph twice. Here, we make the
|
|
||||||
// assumption that the value is cheaply replaced, and
|
|
||||||
// use `std::mem::take` to temporarily replace it with a
|
|
||||||
// dummy value. This requires `ValueType` to implement
|
|
||||||
// Default, but results in a totally safe alternative.
|
|
||||||
let mut value = std::mem::take(&mut self.graph[param_id].value);
|
|
||||||
let node_responses = value.value_widget(
|
let node_responses = value.value_widget(
|
||||||
¶m_name,
|
¶m_name,
|
||||||
self.node_id,
|
self.node_id,
|
||||||
@ -587,9 +596,12 @@ where
|
|||||||
user_state,
|
user_state,
|
||||||
&self.graph[self.node_id].user_data,
|
&self.graph[self.node_id].user_data,
|
||||||
);
|
);
|
||||||
self.graph[param_id].value = value;
|
|
||||||
responses.extend(node_responses.into_iter().map(NodeResponse::User));
|
responses.extend(node_responses.into_iter().map(NodeResponse::User));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.graph[param_id].value = value;
|
||||||
|
|
||||||
let height_after = ui.min_rect().bottom();
|
let height_after = ui.min_rect().bottom();
|
||||||
input_port_heights.push((height_before + height_after) / 2.0);
|
input_port_heights.push((height_before + height_after) / 2.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,8 +13,10 @@ pub trait WidgetValueTrait: Default {
|
|||||||
type Response;
|
type Response;
|
||||||
type UserState;
|
type UserState;
|
||||||
type NodeData;
|
type NodeData;
|
||||||
/// This method will be called for each input parameter with a widget. The
|
|
||||||
/// return value is a vector of custom response objects which can be used
|
/// This method will be called for each input parameter with a widget with an disconnected
|
||||||
|
/// input only. To display UI for connected inputs use [`WidgetValueTrait::value_widget_connected`].
|
||||||
|
/// The return value is a vector of custom response objects which can be used
|
||||||
/// to implement handling of side effects. If unsure, the response Vec can
|
/// to implement handling of side effects. If unsure, the response Vec can
|
||||||
/// be empty.
|
/// be empty.
|
||||||
fn value_widget(
|
fn value_widget(
|
||||||
@ -25,6 +27,26 @@ pub trait WidgetValueTrait: Default {
|
|||||||
user_state: &mut Self::UserState,
|
user_state: &mut Self::UserState,
|
||||||
node_data: &Self::NodeData,
|
node_data: &Self::NodeData,
|
||||||
) -> Vec<Self::Response>;
|
) -> Vec<Self::Response>;
|
||||||
|
|
||||||
|
/// This method will be called for each input parameter with a widget with a connected
|
||||||
|
/// input only. To display UI for diconnected inputs use [`WidgetValueTrait::value_widget`].
|
||||||
|
/// The return value is a vector of custom response objects which can be used
|
||||||
|
/// to implement handling of side effects. If unsure, the response Vec can
|
||||||
|
/// be empty.
|
||||||
|
///
|
||||||
|
/// Shows the input name label by default.
|
||||||
|
fn value_widget_connected(
|
||||||
|
&mut self,
|
||||||
|
param_name: &str,
|
||||||
|
_node_id: NodeId,
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
_user_state: &mut Self::UserState,
|
||||||
|
_node_data: &Self::NodeData,
|
||||||
|
) -> Vec<Self::Response> {
|
||||||
|
ui.label(param_name);
|
||||||
|
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This trait must be implemented by the `DataType` generic parameter of the
|
/// This trait must be implemented by the `DataType` generic parameter of the
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user