fixed project mode crash
This commit is contained in:
parent
acc2c27770
commit
1febc424a2
|
@ -1,7 +1,7 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui::{text::CCursor, text_edit::CCursorRange, Rangef};
|
use egui::{text::CCursor, text_edit::CCursorRange, Rangef};
|
||||||
use egui_extras::{Size, StripBuilder};
|
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::core;
|
||||||
use crate::editor;
|
use crate::editor;
|
||||||
|
@ -375,6 +375,16 @@ impl Calcifer {
|
||||||
.update_from_code(current_tab.code.clone());
|
.update_from_code(current_tab.code.clone());
|
||||||
panels::draw_project(ui, self.theme, &mut self.project_content);
|
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.item_window.visible {
|
||||||
if self.project_content.categories.len() > 1
|
if self.project_content.categories.len() > 1
|
||||||
&& !self.project_content.categories[self.project_content.selected_item.category]
|
&& !self.project_content.categories[self.project_content.selected_item.category]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
cmp::min,
|
|
||||||
cmp::max,
|
cmp::max,
|
||||||
sync::atomic::{AtomicUsize, Ordering},
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
};
|
};
|
||||||
|
@ -178,13 +177,6 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
|
||||||
.content
|
.content
|
||||||
.push(Item::new("item"));
|
.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
|
&& project.selected_item.category > 0
|
||||||
{
|
{
|
||||||
moved = true;
|
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.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))
|
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowRight))
|
||||||
&& project.selected_item.category < project.categories.len() - 2
|
&& project.selected_item.category < project.categories.len() - 2
|
||||||
{
|
{
|
||||||
moved = true;
|
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.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 {
|
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowUp)) && project.selected_item.row > 0 {
|
||||||
moved = true;
|
moved = true;
|
||||||
|
|
Loading…
Reference in a new issue