Paint output slot labels
This commit is contained in:
parent
1f2242c36c
commit
9318b59ac0
|
@ -41,7 +41,7 @@ impl NodeEditor {
|
|||
let pointer_pos = response.interact_pointer_pos();
|
||||
let pointer_target = pointer_pos.map(|pos| layout.pointer_target(pos));
|
||||
let painter = ui.painter_at(rect);
|
||||
layout.paint(rect, &ui, &painter);
|
||||
layout.paint(rect, &painter);
|
||||
|
||||
if let Some(pointer_pos) = pointer_pos {
|
||||
self.pointer_state.position = pointer_pos;
|
||||
|
@ -227,6 +227,10 @@ impl GraphLayout {
|
|||
|
||||
let mut edges = Vec::new();
|
||||
|
||||
let label_font = egui::FontSelection::Style(egui::TextStyle::Body);
|
||||
let label_font = label_font.resolve(ui.style());
|
||||
let label_color = ui.visuals().text_color();
|
||||
|
||||
for (node_index, node) in graph.nodes.iter() {
|
||||
let node_kind = &graph.node_kinds.kinds[node.kind];
|
||||
|
||||
|
@ -256,11 +260,9 @@ impl GraphLayout {
|
|||
layout.input_positions.insert(slot_index, position);
|
||||
|
||||
let text = node_kind.inputs[slot_index.slot].label.to_owned();
|
||||
let font_id =
|
||||
egui::FontSelection::Style(egui::TextStyle::Body).resolve(&ui.style());
|
||||
let color = ui.visuals().text_color();
|
||||
let label_font = label_font.clone();
|
||||
let wrap_width = f32::MAX;
|
||||
let galley = ui.fonts().layout(text, font_id, color, wrap_width);
|
||||
let galley = ui.fonts().layout(text, label_font, label_color, wrap_width);
|
||||
layout.texts.push(TextLayout {
|
||||
pos: egui::pos2(position.x, position.y),
|
||||
galley,
|
||||
|
@ -277,7 +279,7 @@ impl GraphLayout {
|
|||
}
|
||||
}
|
||||
|
||||
for slot_index in 0..1 {
|
||||
for (slot_index, output) in node_kind.outputs.iter().enumerate() {
|
||||
let slot_y = slot_index as f32 * style.slot_spacing + slot_top;
|
||||
let position = glam::Vec2::new(slot_right, slot_y);
|
||||
|
||||
|
@ -288,6 +290,15 @@ impl GraphLayout {
|
|||
|
||||
layout.output_positions.insert(slot_index, position);
|
||||
|
||||
let text = output.label.to_owned();
|
||||
let label_font = label_font.clone();
|
||||
let wrap_width = f32::MAX;
|
||||
let galley = ui.fonts().layout(text, label_font, label_color, wrap_width);
|
||||
layout.texts.push(TextLayout {
|
||||
pos: egui::pos2(position.x, position.y),
|
||||
galley,
|
||||
});
|
||||
|
||||
if pointer.action == PointerAction::SettingOutput(slot_index) {
|
||||
let pointer = Vec2::new(pointer.position.x, pointer.position.y);
|
||||
layout.active_edge = Some((pointer, position));
|
||||
|
@ -354,7 +365,7 @@ impl GraphLayout {
|
|||
PointerTarget::Grid
|
||||
}
|
||||
|
||||
pub fn paint(&self, rect: egui::Rect, ui: &egui::Ui, painter: &egui::Painter) {
|
||||
pub fn paint(&self, rect: egui::Rect, painter: &egui::Painter) {
|
||||
let style = &self.style;
|
||||
let grid_spacing = style.grid_spacing;
|
||||
let grid_pos = rect.left_top().to_vec2() / egui::vec2(grid_spacing, grid_spacing);
|
||||
|
|
Loading…
Reference in New Issue