-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
975 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,7 @@ | |
**/*rustc-ice* | ||
|
||
.bacon-locations | ||
|
||
perf* | ||
dhat-heap.json | ||
flamegraphs/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use gbp_linalg::{Float, Matrix, Vector}; | ||
|
||
#[allow(clippy::len_without_is_empty)] | ||
#[derive(Debug, Clone)] | ||
pub struct DummyNormal { | ||
pub information: Vector<Float>, | ||
pub precision: Matrix<Float>, | ||
pub mean: Vector<Float>, | ||
} | ||
|
||
impl DummyNormal {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#![allow(missing_docs)] | ||
|
||
use bevy::{input::common_conditions::input_just_pressed, prelude::*, window::PrimaryWindow}; | ||
use bevy_egui::{ | ||
egui, | ||
egui::{Ui, WidgetText}, | ||
EguiContexts, EguiPlugin, | ||
}; | ||
use egui_dock::{DockArea, DockState, Style, TabViewer}; | ||
|
||
fn main() { | ||
let mut app = App::new(); | ||
app.add_plugins(DefaultPlugins) | ||
.add_plugins(EguiPlugin) | ||
.init_resource::<MyTabs>() | ||
.init_resource::<Enabled>() | ||
.add_systems(Update, render) | ||
.add_systems(Update, toggle_enabled.run_if(input_just_pressed(KeyCode::Space))); | ||
|
||
app.run(); | ||
} | ||
|
||
// First, let's pick a type that we'll use to attach some data to each tab. | ||
// It can be any type. | ||
type Tab = String; | ||
|
||
// To define the contents and properties of individual tabs, we implement the | ||
// `TabViewer` trait. Only three things are mandatory: the `Tab` associated | ||
// type, and the `ui` and `title` methods. There are more methods in `TabViewer` | ||
// which you can also override. | ||
struct MyTabViewer; | ||
|
||
impl TabViewer for MyTabViewer { | ||
// This associated type is used to attach some data to each tab. | ||
type Tab = Tab; | ||
|
||
// Returns the current `tab`'s title. | ||
fn title(&mut self, tab: &mut Self::Tab) -> WidgetText { | ||
tab.as_str().into() | ||
} | ||
|
||
// Defines the contents of a given `tab`. | ||
fn ui(&mut self, ui: &mut Ui, tab: &mut Self::Tab) { | ||
ui.label(format!("Content of {tab}")); | ||
} | ||
} | ||
|
||
// Here is a simple example of how you can manage a `DockState` of your | ||
// application. | ||
#[derive(Resource)] | ||
struct MyTabs { | ||
dock_state: DockState<Tab>, | ||
} | ||
|
||
impl Default for MyTabs { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl MyTabs { | ||
pub fn new() -> Self { | ||
// Create a `DockState` with an initial tab "tab1" in the main `Surface`'s root | ||
// node. | ||
let tabs = ["tab1", "tab2", "tab3"].map(str::to_string).into_iter().collect(); | ||
let dock_state = DockState::new(tabs); | ||
Self { dock_state } | ||
} | ||
|
||
fn ui(&mut self, ui: &mut Ui) { | ||
// Here we just display the `DockState` using a `DockArea`. | ||
// This is where egui handles rendering and all the integrations. | ||
// | ||
// We can specify a custom `Style` for the `DockArea`, or just inherit | ||
// all of it from egui. | ||
DockArea::new(&mut self.dock_state) | ||
.style(Style::from_egui(ui.style().as_ref())) | ||
.show_inside(ui, &mut MyTabViewer); | ||
} | ||
} | ||
|
||
#[derive(Debug, Resource, Default, Deref, DerefMut)] | ||
pub struct Enabled(pub bool); | ||
|
||
fn toggle_enabled(mut enabled: ResMut<Enabled>) { | ||
enabled.0 = !enabled.0; | ||
} | ||
|
||
fn render( | ||
mut egui_ctx: EguiContexts, | ||
mut tabs: ResMut<MyTabs>, | ||
enabled: Res<Enabled>, | ||
primary_window: Query<&Window, With<PrimaryWindow>>, | ||
) { | ||
let primary_window = primary_window.single(); | ||
|
||
let _window = egui::Window::new("main window") | ||
.default_height(primary_window.height()) | ||
.default_width(primary_window.width()) | ||
.collapsible(false) | ||
.movable(false) | ||
.enabled(enabled.0) | ||
// .default_width(1080.0) | ||
// .default_height(780.0) | ||
.show(egui_ctx.ctx_mut(), |ui| { | ||
tabs.ui(ui); | ||
}); | ||
} | ||
|
||
// #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
// enum Pane { | ||
// Settings, | ||
// Text(String), | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
#![allow(missing_docs, unused_variables, dead_code)] | ||
use bevy::{app::AppExit, input::common_conditions::input_just_pressed, prelude::*}; | ||
use bevy_egui::{ | ||
egui::{self, Color32, RichText, Ui}, | ||
EguiContexts, EguiPlugin, | ||
}; | ||
use ndarray::prelude::*; | ||
|
||
const NAME: &str = env!("CARGO_PKG_NAME"); | ||
|
||
// bevy v0.13.0 | ||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_plugins(EguiPlugin) | ||
.insert_resource(VariableData::default()) | ||
.add_systems(Update, quit_application.run_if(input_just_pressed(KeyCode::KeyQ))) | ||
.add_systems(Update, render) | ||
.run(); | ||
} | ||
|
||
/// Quit the running bevy application | ||
fn quit_application(mut app_exit_event: EventWriter<AppExit>) { | ||
info!("quitting application"); | ||
app_exit_event.send(AppExit); | ||
} | ||
|
||
#[derive(Debug, Resource)] | ||
pub struct VariableData { | ||
pub information_vector: Array1<f32>, | ||
pub precision_matrix: Array2<f32>, | ||
pub mean: Array1<f32>, | ||
} | ||
|
||
impl Default for VariableData { | ||
fn default() -> Self { | ||
Self { | ||
information_vector: array![-1., 2., -3., 4.], | ||
precision_matrix: array![[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.], [ | ||
13., 14., 15., 16. | ||
]], | ||
mean: array![1., 2., 3., 4.], | ||
} | ||
} | ||
} | ||
|
||
fn render(mut egui_ctx: EguiContexts, data: Res<VariableData>) { | ||
let window = egui::Window::new("window").show(egui_ctx.ctx_mut(), |ui| { | ||
// let grid = egui::Grid::new("some_unique_id").show(ui, |ui| { | ||
// ui.label("First row, first column"); | ||
// ui.label("First row, second column"); | ||
// ui.end_row(); | ||
|
||
// ui.label("Second row, first column"); | ||
// ui.label("Second row, second column"); | ||
// ui.label("Second row, third column"); | ||
// ui.end_row(); | ||
|
||
// ui.horizontal(|ui| { | ||
// ui.label("Same"); | ||
// ui.label("cell"); | ||
// }); | ||
// ui.label("Third row, second column"); | ||
// ui.end_row(); | ||
// }); | ||
|
||
subheading(ui, "Information Vector", Some(Color32::LIGHT_RED)); | ||
let information_vector = egui::Grid::new("information_vector") | ||
.with_row_color(|row, style| None) | ||
.num_columns(data.information_vector.len()) | ||
.show(ui, |ui| { | ||
for elem in &data.information_vector { | ||
ui.label(float_cell(*elem)); | ||
// ui.label(elem.to_string()).highlight(); | ||
} | ||
ui.end_row(); | ||
}); | ||
|
||
ui.add_space(10.0); | ||
subheading(ui, "Precision Matrix", Some(Color32::LIGHT_GREEN)); | ||
let precision_matrix = egui::Grid::new("precision_matrix") | ||
.striped(true) | ||
// .with_row_color(|row, style| { | ||
// if row % 2 == 0 { | ||
// Some(Color32::LIGHT_YELLOW) | ||
// } else { | ||
// None | ||
// } | ||
// }) | ||
.num_columns(data.information_vector.len()) | ||
.show(ui, |ui| { | ||
for r in 0..data.precision_matrix.nrows() { | ||
for c in 0..data.precision_matrix.ncols() { | ||
ui.label(float_cell(data.precision_matrix[(r, c)])); | ||
// ui.label(data.precision_matrix[(r, c)].to_string()); | ||
} | ||
ui.end_row(); | ||
} | ||
}); | ||
|
||
ui.add_space(10.0); | ||
|
||
subheading(ui, "Mean", Some(Color32::LIGHT_BLUE)); | ||
let mean = egui::Grid::new("mean").show(ui, |ui| { | ||
for elem in &data.mean { | ||
ui.label(float_cell(*elem)); | ||
// ui.label(elem.to_string()); | ||
} | ||
ui.end_row(); | ||
}); | ||
|
||
// ui.end_row(); | ||
// ui.end_row(); | ||
// ui.end_row(); | ||
}); | ||
} | ||
|
||
#[must_use] | ||
pub fn float_cell(f: f32) -> egui::RichText { | ||
if f < 0.0 { | ||
RichText::new(f.to_string()).color(Color32::LIGHT_RED) | ||
} else { | ||
// Default::default() | ||
RichText::new(f.to_string()).color(Color32::WHITE) | ||
} | ||
} | ||
|
||
/// A separator with color and space before and after | ||
pub fn separator(ui: &mut Ui, color: Option<Color32>, space_before: Option<f32>, space_after: Option<f32>) { | ||
ui.add_space(space_before.unwrap_or(0.0)); | ||
let before = ui.visuals().widgets.noninteractive.bg_stroke.color; | ||
ui.visuals_mut().widgets.noninteractive.bg_stroke.color = color.unwrap_or(before); | ||
ui.separator(); | ||
ui.visuals_mut().widgets.noninteractive.bg_stroke.color = before; | ||
ui.add_space(space_after.unwrap_or(0.0)); | ||
} | ||
|
||
/// A heading with color and a separator after | ||
pub fn heading(ui: &mut Ui, text: &str, color: Option<Color32>) { | ||
ui.add_space(10.0); | ||
ui.heading(RichText::new(text).color(color.unwrap_or_else(|| ui.visuals().text_color()))); | ||
separator(ui, color, Some(5.0), Some(0.0)); | ||
} | ||
|
||
/// A subheading with color and a separator after | ||
pub fn subheading(ui: &mut Ui, text: &str, color: Option<Color32>) { | ||
ui.add_space(10.0); | ||
ui.label( | ||
RichText::new(text) | ||
.size(16.0) | ||
.color(color.unwrap_or_else(|| ui.visuals().text_color())), | ||
); | ||
separator(ui, color, None, Some(5.0)); | ||
} |
Oops, something went wrong.