From 642bb6619d9285d290775f159bffffca163abe37 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Mon, 16 Feb 2026 01:45:51 +0300 Subject: [PATCH] [lab3] Vertex IDs in graph render --- lab3/src/main.rs | 2 +- utility/src/gui/mod.rs | 3 +- .../src/gui/{render.rs => render_graph.rs} | 31 ++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) rename utility/src/gui/{render.rs => render_graph.rs} (66%) diff --git a/lab3/src/main.rs b/lab3/src/main.rs index e39a680..996717a 100644 --- a/lab3/src/main.rs +++ b/lab3/src/main.rs @@ -8,7 +8,7 @@ use crate::algo::{ }; use bgtu_ai_utility::UpdatePending; use bgtu_ai_utility::gui::lengths_table::draw_lengths_table; -use bgtu_ai_utility::gui::render::render_graph; +use bgtu_ai_utility::gui::render_graph; use bgtu_ai_utility::gui::{boot_eframe, labeled_slider}; use eframe::egui; use eframe::egui::{Frame, Ui}; diff --git a/utility/src/gui/mod.rs b/utility/src/gui/mod.rs index 667f4ba..7afcb77 100644 --- a/utility/src/gui/mod.rs +++ b/utility/src/gui/mod.rs @@ -1,9 +1,10 @@ mod boot; pub mod lengths_table; -pub mod render; +mod render_graph; mod slider; mod subwindow; pub use boot::boot_eframe; pub use slider::{labeled_slider, slider}; pub use subwindow::subwindow; +pub use render_graph::render_graph; \ No newline at end of file diff --git a/utility/src/gui/render.rs b/utility/src/gui/render_graph.rs similarity index 66% rename from utility/src/gui/render.rs rename to utility/src/gui/render_graph.rs index 30592c9..8535271 100644 --- a/utility/src/gui/render.rs +++ b/utility/src/gui/render_graph.rs @@ -1,5 +1,6 @@ use crate::graph::{Edge, EdgesVec, VerticesVec}; -use eframe::egui::{Color32, Pos2, Rect, Ui}; +use eframe::egui; +use eframe::egui::{Align2, Color32, FontDefinitions, Pos2, Rect, StrokeKind, Ui, Vec2}; use eframe::epaint::{CornerRadius, Stroke}; pub fn render_graph( @@ -34,6 +35,34 @@ pub fn render_graph( Stroke::new(1.0, intensity2color(normalized_intensity(e))), ); } + let font_id = &ui.style().text_styles[&egui::TextStyle::Body]; + + for (vi, _) in vertices.iter_indexed() { + let center = vertex_locations[vi]; + let center = Pos2::new( + center.0 * rect.width() + rect.min.x, + center.1 * rect.height() + rect.min.y, + ); + + let galley = + canvas.layout_no_wrap(vi.to_string(), font_id.clone(), Color32::from_rgb(0, 0, 0)); + + canvas.rect( + Rect::from_center_size(center, galley.size() + Vec2::new(6.0, 6.0)), + CornerRadius::from(0), + Color32::from_rgb(0, 0, 0), + Stroke::new(1.0, Color32::from_rgb(255, 255, 255)), + StrokeKind::Middle, + ); + + canvas.text( + center, + Align2::CENTER_CENTER, + vi, + font_id.clone(), + Color32::from_rgb(255, 255, 255), + ); + } } fn intensity2color(intensity: f64) -> Color32 {