Boot function

This commit is contained in:
Andrew Golovashevich 2026-02-15 18:07:17 +03:00
parent 467f3193b2
commit fa0cdee811
9 changed files with 38 additions and 52 deletions

View File

@ -2,7 +2,7 @@
mod algo;
use bgtu_ai_utility::labeled_slider;
use bgtu_ai_utility::gui::{boot_eframe, labeled_slider};
use eframe::egui;
use eframe::egui::{CornerRadius, Frame};
use eframe::epaint::{Color32, Pos2, Rect};
@ -10,15 +10,7 @@ use rand::SeedableRng;
use std::time::{SystemTime, UNIX_EPOCH};
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 400.0]),
..Default::default()
};
eframe::run_native(
"Annealing Simulation for Chess Queens Task",
options,
Box::new(|_cc| Ok(Box::<MyApp>::default())),
)
return boot_eframe(||MyApp::new())
}
struct MyApp {
@ -28,9 +20,9 @@ struct MyApp {
result: Option<algo::Board>,
}
impl Default for MyApp {
fn default() -> Self {
Self {
impl MyApp {
fn new() -> Self {
return Self {
simulationConfig: algo::AnnealingConfig {
initialTemperature: 30.0,
targetTemperature: 0.5,

View File

@ -3,20 +3,12 @@
mod algo;
use crate::algo::BitVector;
use bgtu_ai_utility::labeled_slider;
use bgtu_ai_utility::gui::{boot_eframe, labeled_slider};
use eframe::egui;
use egui_extras::{Column, TableBuilder};
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 400.0]),
..Default::default()
};
eframe::run_native(
"Adaptive Resonance Theory calculater",
options,
Box::new(|_cc| Ok(Box::<MyApp>::default())),
)
return boot_eframe(|| MyApp::new());
}
enum UpdatePending {
@ -36,8 +28,8 @@ struct MyApp {
rowUpdate: UpdatePending,
}
impl Default for MyApp {
fn default() -> Self {
impl MyApp {
fn new() -> Self {
return Self {
_isFirstFrame: true,
bitCount: 0,

View File

@ -8,23 +8,16 @@ use crate::algo::{
};
use bgtu_ai_utility::gui::lengths_table::{draw_lengths_table, UpdatePending};
use bgtu_ai_utility::gui::render::render_graph;
use bgtu_ai_utility::labeled_slider;
use bgtu_ai_utility::gui::{boot_eframe, labeled_slider};
use eframe::egui;
use eframe::egui::{Frame, Ui};
use std::collections::HashSet;
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 400.0]),
..Default::default()
};
eframe::run_native(
"Ants simulation",
options,
Box::new(|_cc| Ok(Box::<MyApp>::default())),
)
return boot_eframe(|| MyApp::new());
}
enum GlobalState {
Edit,
Running,
@ -39,8 +32,8 @@ struct MyApp {
ants_per_vertex: usize,
}
impl Default for MyApp {
fn default() -> Self {
impl MyApp {
fn new() -> Self {
return Self {
simulation: AntsSimulationState {
edges: EdgesVec::new(),

View File

@ -5,24 +5,17 @@
mod algo;
use crate::algo::{gen_images, ComparationOperatorsModel};
use bgtu_ai_utility::labeled_slider;
use bgtu_ai_utility::gui::{boot_eframe, labeled_slider};
use eframe::egui;
use eframe::egui::Widget;
use egui_extras::{Column, TableBuilder};
use std::cmp::min;
fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 400.0]),
..Default::default()
};
eframe::run_native(
"Neural net",
options,
Box::new(|_cc| Ok(Box::<MyApp>::default())),
)
return boot_eframe(|| MyApp::new());
}
enum TrainingState {
NoTrain,
Training {
@ -42,8 +35,8 @@ struct MyApp {
compute_result: [f64; 8],
}
impl Default for MyApp {
fn default() -> Self {
impl MyApp {
fn new() -> Self {
let imgs = gen_images();
return Self {
model: ComparationOperatorsModel::new(imgs.1),

13
utility/src/gui/boot.rs Normal file
View File

@ -0,0 +1,13 @@
use eframe::egui;
pub fn boot_eframe<T: eframe::App>(init_data: impl FnOnce() -> T) ->eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 400.0]),
..Default::default()
};
eframe::run_native(
"Annealing Simulation for Chess Queens Task",
options,
Box::new(|_cc| Ok(Box::<T>::new(init_data()))),
)
}

View File

@ -1,5 +1,5 @@
use crate::graph::{EdgesVec, VerticesVec};
use crate::slider;
use crate::gui::slider;
use eframe::egui::{ScrollArea, Ui};
use egui_extras::{Column, TableBuilder};
use std::ptr::NonNull;

View File

@ -1,2 +1,7 @@
pub mod lengths_table;
pub mod render;
mod slider;
mod boot;
pub use slider::{slider, labeled_slider};
pub use boot::boot_eframe;

View File

@ -1,5 +1,3 @@
pub mod graph;
pub mod gui;
mod slider;
pub use slider::{slider, labeled_slider};