diff --git a/src/core/ui.rs b/src/core/ui.rs index 2c7899f..77fd314 100644 --- a/src/core/ui.rs +++ b/src/core/ui.rs @@ -1,7 +1,7 @@ use eframe::egui; use egui::{text::CCursor, text_edit::CCursorRange, Rangef}; use egui_extras::{Size, StripBuilder}; -use std::{cmp::max, env, ffi::OsStr, path::Component, path::Path, path::PathBuf}; +use std::{cmp::max, cmp::min, env, ffi::OsStr, path::Component, path::Path, path::PathBuf}; use crate::core; use crate::editor; @@ -375,6 +375,16 @@ impl Calcifer { .update_from_code(current_tab.code.clone()); panels::draw_project(ui, self.theme, &mut self.project_content); + self.project_content.selected_item.category = min(self.project_content.categories.len() - 2, self.project_content.selected_item.category); + while self.project_content.categories[self.project_content.selected_item.category].content.is_empty() && self.project_content.selected_item.category > 0 { + self.project_content.selected_item.category -= 1; + } + if !self.project_content.categories[self.project_content.selected_item.category].content.is_empty() { + self.project_content.selected_item.row = min(self.project_content.categories[self.project_content.selected_item.category].content.len() - 1, self.project_content.selected_item.row); + } else { + self.project_content.selected_item.row = 0; + } + if self.project_content.item_window.visible { if self.project_content.categories.len() > 1 && !self.project_content.categories[self.project_content.selected_item.category] diff --git a/src/panels/project_mode.rs b/src/panels/project_mode.rs index 3a6b304..0c1cfeb 100644 --- a/src/panels/project_mode.rs +++ b/src/panels/project_mode.rs @@ -1,7 +1,6 @@ use eframe::egui; use serde::{Deserialize, Serialize}; use std::{ - cmp::min, cmp::max, sync::atomic::{AtomicUsize, Ordering}, }; @@ -178,13 +177,6 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project) .content .push(Item::new("item")); } - // if category.name != "+" { - // if ui.add(egui::Button::new("+")).clicked() { - // project.categories[category_index] - // .content - // .push(Item::new("item")); - // } - // } } }); @@ -238,23 +230,15 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project) && project.selected_item.category > 0 { moved = true; - if !project.was_moving { + if !project.was_moving && project.categories[category - 1].content.len() > 0 { project.selected_item.category -= 1; - project.selected_item.row = min( - project.categories[category].content.len() - 1, - project.selected_item.row, - ); } } else if ui.input(|i| i.key_pressed(egui::Key::ArrowRight)) && project.selected_item.category < project.categories.len() - 2 { moved = true; - if !project.was_moving { + if !project.was_moving && project.categories[category + 1].content.len() > 0 { project.selected_item.category += 1; - project.selected_item.row = min( - project.categories[category].content.len() - 1, - project.selected_item.row, - ); } } else if ui.input(|i| i.key_pressed(egui::Key::ArrowUp)) && project.selected_item.row > 0 { moved = true;