ui: matrix component

This commit is contained in:
Schrottkatze 2024-05-19 16:22:36 +02:00
parent 7f76618c24
commit 5a6b7756e4
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
4 changed files with 226 additions and 16 deletions

193
Cargo.lock generated
View file

@ -23,6 +23,10 @@ name = "accesskit"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74a4b14f3d99c1255dcba8f45621ab1a2e7540a0009652d33989005a4d0bfc6b"
dependencies = [
"enumn",
"serde",
]
[[package]]
name = "accesskit_consumer"
@ -104,6 +108,7 @@ dependencies = [
"cfg-if",
"getrandom",
"once_cell",
"serde",
"version_check",
"zerocopy",
]
@ -208,6 +213,15 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]]
name = "arboard"
version = "3.4.0"
@ -939,6 +953,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20930a432bbd57a6d55e07976089708d4893f3d556cf42a0d79e9e321fa73b10"
dependencies = [
"bytemuck",
"serde",
]
[[package]]
@ -988,6 +1003,7 @@ dependencies = [
"epaint",
"log",
"nohash-hasher",
"serde",
]
[[package]]
@ -1025,6 +1041,19 @@ dependencies = [
"winit",
]
[[package]]
name = "egui_extras"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b78779f35ded1a853786c9ce0b43fe1053e10a21ea3b23ebea411805ce41593"
dependencies = [
"egui",
"enum-map",
"log",
"mime_guess2",
"serde",
]
[[package]]
name = "egui_glow"
version = "0.27.2"
@ -1048,6 +1077,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4c3a552cfca14630702449d35f41c84a0d15963273771c6059175a803620f3f"
dependencies = [
"bytemuck",
"serde",
]
[[package]]
name = "enum-map"
version = "2.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6866f3bfdf8207509a033af1a75a7b08abda06bbaaeae6669323fd5a097df2e9"
dependencies = [
"enum-map-derive",
"serde",
]
[[package]]
name = "enum-map-derive"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.64",
]
[[package]]
@ -1071,6 +1122,17 @@ dependencies = [
"syn 2.0.64",
]
[[package]]
name = "enumn"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.64",
]
[[package]]
name = "env_filter"
version = "0.1.0"
@ -1108,6 +1170,7 @@ dependencies = [
"log",
"nohash-hasher",
"parking_lot",
"serde",
]
[[package]]
@ -1771,7 +1834,19 @@ version = "0.1.0"
dependencies = [
"bytemuck",
"eframe",
"egui_extras",
"env_logger",
"nalgebra",
]
[[package]]
name = "matrixmultiply"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2"
dependencies = [
"autocfg",
"rawpointer",
]
[[package]]
@ -1822,6 +1897,22 @@ dependencies = [
"paste",
]
[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess2"
version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a3333bb1609500601edc766a39b4c1772874a4ce26022f4d866854dc020c41"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "miniz_oxide"
version = "0.7.2"
@ -1852,6 +1943,33 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "nalgebra"
version = "0.32.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ea4908d4f23254adda3daa60ffef0f1ac7b8c3e9a864cf3cc154b251908a2ef"
dependencies = [
"approx",
"matrixmultiply",
"nalgebra-macros",
"num-complex",
"num-rational",
"num-traits",
"simba",
"typenum",
]
[[package]]
name = "nalgebra-macros"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91761aed67d03ad966ef783ae962ef9bbaca728d2dd7ceb7939ec110fffad998"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "ndk"
version = "0.8.0"
@ -1901,6 +2019,34 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
[[package]]
name = "num-complex"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
dependencies = [
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.19"
@ -2307,6 +2453,12 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cc3bcbdb1ddfc11e700e62968e6b4cc9c75bb466464ad28fb61c5b2c964418b"
[[package]]
name = "rawpointer"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]]
name = "redox_syscall"
version = "0.3.5"
@ -2402,6 +2554,15 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "safe_arch"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f398075ce1e6a179b46f51bd88d0598b92b00d3551f1a2d4ac49e771b56ac354"
dependencies = [
"bytemuck",
]
[[package]]
name = "same-file"
version = "1.0.6"
@ -2487,6 +2648,19 @@ dependencies = [
"libc",
]
[[package]]
name = "simba"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "061507c94fc6ab4ba1c9a0305018408e312e17c041eb63bef8aa726fa33aceae"
dependencies = [
"approx",
"num-complex",
"num-traits",
"paste",
"wide",
]
[[package]]
name = "simd-adler32"
version = "0.3.7"
@ -2787,6 +2961,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "unicase"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.15"
@ -3187,6 +3370,16 @@ dependencies = [
"web-sys",
]
[[package]]
name = "wide"
version = "0.7.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aab6594190de06d718a5dbc5fa781ab62f8903797056480e549ca74add6b7065"
dependencies = [
"bytemuck",
"safe_arch",
]
[[package]]
name = "widestring"
version = "1.1.0"

View file

@ -6,7 +6,9 @@ edition = "2021"
[dependencies]
bytemuck = "1.16.0"
eframe = {version = "0.27", features = ["wgpu"]}
egui_extras = "0.27.2"
env_logger = "0.11.3"
nalgebra = "0.32.5"
# winit = { version = "0.30", features = ["rwh_05" ] }
# log = "0.4"
# console_error_panic_hook = "0.1.6"

View file

@ -8,8 +8,7 @@
- [ ] independent lib/cli app?
- [ ] ui
- [ ] components
- [ ] number picker with slider at bottom?
- [ ] (arbitrary size?) matrix component
- [x] (arbitrary size?) matrix component
- [ ] matrix list that outputs single matrix multiplied from them all
- [ ] Optional: help/what is this buttons
- [ ] Optional: explainer per pixel what's happening on hover

View file

@ -5,12 +5,12 @@ use eframe::{
egui, egui_wgpu,
wgpu::{self, util::DeviceExt},
};
use nalgebra::{Matrix3, SMatrix};
use crate::cb::CustomTriangleCallback;
pub struct App {
name: String,
age: u32,
mat: SMatrix<f32, 3, 3>,
}
impl App {
pub fn new<'a>(cc: &'a eframe::CreationContext<'a>) -> Option<Self> {
@ -97,8 +97,7 @@ impl App {
});
Some(Self {
name: "Jade".to_owned(),
age: 19,
mat: SMatrix::identity(),
})
}
}
@ -107,16 +106,8 @@ impl eframe::App for App {
fn update(&mut self, ctx: &eframe::egui::Context, frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("My egui Application");
ui.horizontal(|ui| {
let name_label = ui.label("Your name: ");
ui.text_edit_singleline(&mut self.name)
.labelled_by(name_label.id);
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Increment").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));
components::mat_editor(ui, &mut self.mat);
egui::Frame::canvas(ui.style()).show(ui, |ui| {
let (rect, response) =
@ -133,6 +124,31 @@ impl eframe::App for App {
}
}
mod components {
use eframe::egui;
use nalgebra::{Matrix, SMatrix};
pub fn mat_editor<const R: usize, const C: usize>(
ui: &mut egui::Ui,
mat: &mut SMatrix<f32, R, C>,
) -> egui::Response {
egui::Grid::new("mat")
.show(ui, |ui| {
mat.row_iter_mut().enumerate().for_each(|(i, mut row)| {
row.iter_mut().for_each(|item| {
ui.add(
egui::DragValue::new(item)
.speed(0.01)
.clamp_range(-1.0..=1.0),
);
});
ui.end_row();
})
})
.response
}
}
mod cb {
use eframe::{egui, egui_wgpu, wgpu};