Paint node kind label

This commit is contained in:
mars 2022-10-21 16:32:24 -06:00
parent 1fb7f03468
commit b0ecf1eb92
1 changed files with 27 additions and 4 deletions

View File

@ -229,13 +229,16 @@ impl GraphLayout {
let mut edges = Vec::new();
let kind_font = egui::FontSelection::Style(egui::TextStyle::Heading);
let kind_font = kind_font.resolve(ui.style());
let kind_spacing = ui.style().spacing.item_spacing.y;
let kind_color = ui.visuals().text_color();
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];
let mut node_pos = egui::pos2(node.pos.x, node.pos.y);
if pointer.action == PointerAction::MovingNode(node_index) {
@ -246,7 +249,22 @@ impl GraphLayout {
let node_rect = egui::Rect::from_min_size(node_pos, node_size);
layout.node_rects.insert(node_index, node_rect);
let slot_top = node_pos.y + style.slot_spacing;
let text = node_kind.title.to_string();
let kind_font = kind_font.clone();
let wrap_width = f32::MAX;
let galley = ui.fonts().layout(text, kind_font, kind_color, wrap_width);
let kind_height = galley.rect.height() + kind_spacing * 2.0;
layout.texts.push(TextLayout {
pos: egui::pos2(
node_rect.center().x - galley.rect.center().x,
node_pos.y + kind_height - galley.rect.height(),
),
galley,
});
let slot_top = node_pos.y + kind_height + style.slot_spacing;
let slot_left = node_rect.left();
let slot_right = node_rect.right();
@ -267,7 +285,9 @@ impl GraphLayout {
let galley = ui.fonts().layout(text, label_font, label_color, wrap_width);
layout.texts.push(TextLayout {
pos: egui::pos2(
position.x - galley.rect.left() + style.slot_radius + style.slot_label_margin,
position.x - galley.rect.left()
+ style.slot_radius
+ style.slot_label_margin,
position.y - galley.rect.bottom() + style.slot_radius,
),
galley,
@ -301,7 +321,10 @@ impl GraphLayout {
let galley = ui.fonts().layout(text, label_font, label_color, wrap_width);
layout.texts.push(TextLayout {
pos: egui::pos2(
position.x - galley.rect.right() - style.slot_radius - style.slot_label_margin,
position.x
- galley.rect.right()
- style.slot_radius
- style.slot_label_margin,
position.y - galley.rect.bottom() + style.slot_radius,
),
galley,