Skip to content

Commit

Permalink
editor: basic package tab
Browse files Browse the repository at this point in the history
  • Loading branch information
barsoosayque committed Sep 27, 2024
1 parent 37f485c commit 1d16284
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/opensi-editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
57 changes: 54 additions & 3 deletions crates/opensi-editor/src/package_tab.rs
Original file line number Diff line number Diff line change
@@ -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<str>,
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);
});
}
4 changes: 1 addition & 3 deletions crates/opensi-editor/src/package_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageNode>, 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;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/opensi-editor/src/workarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn workarea(package: &mut Package, selected: &mut Option<PackageNode>, ui: &

ui.add_space(16.0);

ui.centered_and_justified(|ui| {
ui.vertical_centered_justified(|ui| {
selected_tab(package, selected, ui);
});
});
Expand Down

0 comments on commit 1d16284

Please sign in to comment.