diff --git a/crates/opensi-editor/Cargo.toml b/crates/opensi-editor/Cargo.toml index d012e6c..0ee55cc 100644 --- a/crates/opensi-editor/Cargo.toml +++ b/crates/opensi-editor/Cargo.toml @@ -21,6 +21,7 @@ thiserror = "1.0.64" # You only need serde if you want app persistence: serde = { version = "1", features = ["derive"] } +egui_extras = "0.29.0" # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/crates/opensi-editor/src/package_tab.rs b/crates/opensi-editor/src/package_tab.rs index 6c8ad4e..fdbcb08 100644 --- a/crates/opensi-editor/src/package_tab.rs +++ b/crates/opensi-editor/src/package_tab.rs @@ -1,8 +1,59 @@ use opensi_core::Package; +/// Workarea tab to edit package info. pub fn package_tab(package: &mut Package, ui: &mut egui::Ui) { - ui.vertical(|ui| { - ui.label(&package.id); - ui.label(package.name.clone().unwrap_or_default()); + egui_extras::TableBuilder::new(ui) + .column(egui_extras::Column::auto()) + .column(egui_extras::Column::remainder().at_least(400.0)) + .cell_layout(egui::Layout::left_to_right(egui::Align::Min)) + .striped(false) + .body(|mut body| { + package_edit_row("Название", &mut body, |ui| { + ui.text_edit_singleline(&mut package.name); + }); + package_edit_row("Сложность", &mut body, |ui| { + ui.add(egui::DragValue::new(&mut package.difficulty).range(0..=10)); + }); + package_edit_row("Ограничения", &mut body, |ui| { + ui.text_edit_singleline(&mut package.restriciton); + }); + package_edit_row("Дата создания", &mut body, |ui| { + ui.text_edit_singleline(&mut package.date); + }); + package_edit_row("Издатель", &mut body, |ui| { + ui.text_edit_singleline(&mut package.publisher); + }); + package_edit_row("Язык", &mut body, |ui| { + ui.text_edit_singleline(&mut package.language); + }); + }); + + ui.collapsing("Метаданные", |ui| { + egui_extras::TableBuilder::new(ui) + .column(egui_extras::Column::auto()) + .column(egui_extras::Column::remainder().at_least(400.0)) + .cell_layout(egui::Layout::left_to_right(egui::Align::Min)) + .striped(true) + .body(|mut body| { + package_edit_row("ID пакета", &mut body, |ui| { + ui.label(&package.id); + }); + package_edit_row("Версия", &mut body, |ui| { + ui.label(format!("{:.1}", package.version)); + }); + }); + }); +} + +fn package_edit_row( + label: impl AsRef, + body: &mut egui_extras::TableBody, + content: impl FnOnce(&mut egui::Ui), +) { + body.row(20.0, |mut row| { + row.col(|ui| { + ui.label(label.as_ref()); + }); + row.col(content); }); } diff --git a/crates/opensi-editor/src/package_tree.rs b/crates/opensi-editor/src/package_tree.rs index 92dedd3..370caed 100644 --- a/crates/opensi-editor/src/package_tree.rs +++ b/crates/opensi-editor/src/package_tree.rs @@ -8,10 +8,8 @@ use crate::utils::node_name; /// It can add new rounds, themes and questions, edit /// names/prices of existing ones and select them. pub fn package_tree(package: &mut Package, selected: &mut Option, ui: &mut egui::Ui) { - let name = package.name.as_ref().map(|name| name.as_str()).unwrap_or("Новый пакет вопросов"); - ui.vertical_centered_justified(|ui| { - let text = egui::RichText::new(name).strong().heading(); + let text = egui::RichText::new(&package.name).strong().heading(); if ui.add(egui::Label::new(text).sense(egui::Sense::click()).selectable(false)).clicked() { *selected = None; } diff --git a/crates/opensi-editor/src/workarea.rs b/crates/opensi-editor/src/workarea.rs index fc72d29..64cc9f5 100644 --- a/crates/opensi-editor/src/workarea.rs +++ b/crates/opensi-editor/src/workarea.rs @@ -11,7 +11,7 @@ pub fn workarea(package: &mut Package, selected: &mut Option, ui: & ui.add_space(16.0); - ui.centered_and_justified(|ui| { + ui.vertical_centered_justified(|ui| { selected_tab(package, selected, ui); }); });