fixed project mode crash

This commit is contained in:
WanderingPenwing 2024-07-27 23:17:42 +02:00
parent acc2c27770
commit 1febc424a2
2 changed files with 13 additions and 19 deletions

View file

@ -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]

View file

@ -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;