added item deletion

This commit is contained in:
WanderingPenwing 2024-03-01 22:08:01 +01:00
parent 2237384ca2
commit 2065385ea8
3 changed files with 49 additions and 25 deletions

View file

@ -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":[]}]} {"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":[]}]}

View file

@ -345,12 +345,22 @@ impl Calcifer {
.content .content
.is_empty() .is_empty()
{ {
self.project_content.item_window.show( let delete_item = self.project_content.item_window.show(
ctx, ctx,
&mut self.project_content.categories &mut self.project_content.categories
[self.project_content.selected_item.category] [self.project_content.selected_item.category]
.content[self.project_content.selected_item.row], .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 { } else {
self.project_content.item_window.visible = false; self.project_content.item_window.visible = false;
} }

View file

@ -3,32 +3,46 @@ use eframe::egui;
use crate::panels; use crate::panels;
pub struct ProjectItemWindow { pub struct ProjectItemWindow {
pub visible: bool, pub visible: bool,
} }
impl ProjectItemWindow { impl ProjectItemWindow {
pub fn new() -> Self { pub fn new() -> Self {
Self { visible: false } Self { visible: false }
} }
pub fn show(&mut self, ctx: &egui::Context, item: &mut panels::Item) { pub fn show(&mut self, ctx: &egui::Context, item: &mut panels::Item) -> bool {
let mut visible = self.visible; let mut visible = self.visible;
egui::Window::new("Item") let maybe_response = egui::Window::new("Item")
.open(&mut visible) .open(&mut visible)
.vscroll(true) .vscroll(true)
.hscroll(true) .hscroll(true)
.show(ctx, |ui| self.ui(ui, item)); .show(ctx, |ui| self.ui(ui, item));
self.visible = self.visible && visible; self.visible = self.visible && visible;
}
fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) { if let Some(response) = maybe_response {
ui.set_min_width(250.0); if let Some(delete_option) = response.inner {
ui.set_min_height(250.0); return delete_option
ui.add(egui::TextEdit::singleline(&mut item.name).desired_width(f32::INFINITY)); }
ui.separator(); }
ui.add_sized( return false
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()
}
} }