diff --git a/lab1/src/main.rs b/lab1/src/main.rs index 9e6fe38..1d7e0b7 100644 --- a/lab1/src/main.rs +++ b/lab1/src/main.rs @@ -4,8 +4,9 @@ mod algo; use eframe::egui; -use eframe::egui::Ui; +use eframe::egui::{CornerRadius, Frame, Ui}; use eframe::emath::Numeric; +use eframe::epaint::{Color32, Pos2, Rect, RectShape, Rounding, Shape}; use rand::SeedableRng; use std::ops::RangeInclusive; use std::time::{SystemTime, UNIX_EPOCH}; @@ -123,30 +124,60 @@ impl eframe::App for MyApp { } }); - match &self.result { + match self.result.clone() { None => {} - Some(result) => ui.ctx().show_viewport_immediate( - egui::ViewportId::from_hash_of("immediate_viewport"), + Some(board) => ui.ctx().show_viewport_immediate( + egui::ViewportId::from_hash_of("board"), egui::ViewportBuilder::default() - .with_title("Immediate Viewport") - .with_inner_size([200.0, 100.0]), - |ui, class| { - if class == egui::ViewportClass::Embedded { - /*ui.label( - "This viewport is embedded in the parent window, and cannot be moved outside of it.", - );*/ - } else { - egui::CentralPanel::default().show(ui, |ui| { - ui.label("Hello from immediate viewport"); + .with_title("Board") + .with_inner_size([ + 10.0 * self.boardSize as f32, + 10.0 * self.boardSize as f32, + ]), + |ui, _| { + egui::CentralPanel::default() + .frame(Frame::default().inner_margin(0.0)) + .show(ui, |ui| { + let painter = ui.painter(); + painter.rect_filled( + ui.available_rect_before_wrap(), + CornerRadius::from(0), + Color32::from_rgb(0, 0, 0), + ); + + for y in 0..self.boardSize { + for x in 0..self.boardSize { + if y % 2 == x % 2 { + painter.rect_filled( + Rect::from_min_max( + Pos2::new((10 * x) as f32, (10 * y) as f32), + Pos2::new( + (10 * (x + 1)) as f32, + (10 * (y + 1)) as f32, + ), + ), + CornerRadius::from(0), + Color32::from_rgb(255, 255, 255), + ); + } + } + } + + for i in 0..self.boardSize { + painter.circle_filled( + Pos2::new((10 * board[i] + 5) as f32, (10 * i + 5) as f32), + 4.0, + Color32::from_rgb(255, 0, 0), + ); + } if ui.input(|i| i.viewport().close_requested()) { self.result = None } }); - } }, ), - } + }; }); } }