diff --git a/calcifer.project b/calcifer.project index c2adc41..707695c 100644 --- a/calcifer.project +++ b/calcifer.project @@ -1 +1 @@ -{"categories":[{"name":"to do","content":[{"name":"clean up","description":"using the feedback from ourstory discord","id":1},{"name":"be able to delete item","description":"in project mode add a button in item edit window to delete an item","id":4},{"name":"be able to delete category","description":"in project mode, if no focus and name is empty => delete category\n\nalready did xD I am a geniius\nfor clarification, I had a loong pause in develompent, and had forgotten I had this implemented, and while looking for where to code it, i found at the exact right place, the exact code needed","id":5},{"name":"update category layout","description":"take inspo form tab layout (number of column is max( min col, n_col +1)\nor scroll ?","id":6},{"name":"keep tree in save","description":"keep track of the opened tabs and reopens them\n","id":1},{"name":"u","description":"// Hello there","id":2},{"name":"less enter trigger (project)","description":"if in a textbox, don't open the item window when enter is pressed","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"mark tab as unsaved (project)","description":"when modifying a project, mark it as unsaved","id":2},{"name":"fix + color in project","description":"the '+' to add an item has a wrong color if last item in list is selected","id":3}]},{"name":"bugs","content":[]},{"name":"+","content":[]}]} \ No newline at end of file +{"categories":[{"name":"to do","content":[{"name":"clean up","description":"using the feedback from ourstory discord","id":1},{"name":"keep tree in save","description":"keep track of the opened tabs and reopens them\n","id":1},{"name":"u","description":"// Hello there","id":2}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"mark tab as unsaved (project)","description":"when modifying a project, mark it as unsaved","id":2},{"name":"fix + color in project","description":"the '+' to add an item has a wrong color if last item in list is selected","id":3},{"name":"be able to delete category","description":"in project mode, if no focus and name is empty => delete category\n\nalready did xD I am a geniius\nfor clarification, I had a loong pause in develompent, and had forgotten I had this implemented, and while looking for where to code it, i found at the exact right place, the exact code needed","id":5},{"name":"update category layout","description":"take inspo form tab layout (number of column is max( min col, n_col +1)\nor scroll ?","id":6},{"name":"less enter trigger (project)","description":"if in a textbox, don't open the item window when enter is pressed","id":3},{"name":"be able to delete item","description":"in project mode add a button in item edit window to delete an item","id":4}]},{"name":"bugs","content":[]},{"name":"+","content":[]}]} \ No newline at end of file diff --git a/src/core/ui.rs b/src/core/ui.rs index bc436c2..abe9abd 100644 --- a/src/core/ui.rs +++ b/src/core/ui.rs @@ -345,12 +345,22 @@ impl Calcifer { .content .is_empty() { - self.project_content.item_window.show( + let delete_item = self.project_content.item_window.show( ctx, &mut self.project_content.categories [self.project_content.selected_item.category] .content[self.project_content.selected_item.row], ); + + if delete_item { + self.project_content.item_window.visible = false; + self.project_content.categories + [self.project_content.selected_item.category] + .content.remove(self.project_content.selected_item.row); + if self.project_content.selected_item.row >= self.project_content.categories[self.project_content.selected_item.category].content.len() && self.project_content.selected_item.row > 0 { + self.project_content.selected_item.row -= 1; + } + } } else { self.project_content.item_window.visible = false; } diff --git a/src/sub_windows/project_item.rs b/src/sub_windows/project_item.rs index 467e5f9..89160ab 100644 --- a/src/sub_windows/project_item.rs +++ b/src/sub_windows/project_item.rs @@ -3,32 +3,46 @@ use eframe::egui; use crate::panels; pub struct ProjectItemWindow { - pub visible: bool, + pub visible: bool, } impl ProjectItemWindow { - pub fn new() -> Self { - Self { visible: false } - } + pub fn new() -> Self { + Self { visible: false } + } - pub fn show(&mut self, ctx: &egui::Context, item: &mut panels::Item) { - let mut visible = self.visible; - egui::Window::new("Item") - .open(&mut visible) - .vscroll(true) - .hscroll(true) - .show(ctx, |ui| self.ui(ui, item)); - self.visible = self.visible && visible; - } + pub fn show(&mut self, ctx: &egui::Context, item: &mut panels::Item) -> bool { + let mut visible = self.visible; + let maybe_response = egui::Window::new("Item") + .open(&mut visible) + .vscroll(true) + .hscroll(true) + .show(ctx, |ui| self.ui(ui, item)); + self.visible = self.visible && visible; + + if let Some(response) = maybe_response { + if let Some(delete_option) = response.inner { + return delete_option + } + } + return false + } - fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) { - ui.set_min_width(250.0); - ui.set_min_height(250.0); - ui.add(egui::TextEdit::singleline(&mut item.name).desired_width(f32::INFINITY)); - ui.separator(); - ui.add_sized( - ui.available_size(), - egui::TextEdit::multiline(&mut item.description), - ); - } + fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) -> bool { + let mut delete_item = false; + ui.set_min_width(250.0); + ui.set_min_height(250.0); + ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| { + if ui.add(egui::Button::new("delete")).clicked() { + delete_item = true; + } + ui.add(egui::TextEdit::singleline(&mut item.name).desired_width(f32::INFINITY)); + }); + ui.separator(); + ui.add_sized( + ui.available_size(), + egui::TextEdit::multiline(&mut item.description), + ); + return delete_item.clone() + } }