added item window, and item movement
This commit is contained in:
parent
34274dfb9d
commit
afec8f6426
|
@ -42,10 +42,10 @@ impl Calcifer {
|
|||
ui.separator();
|
||||
self.profiler_visible = self.toggle(ui, self.profiler_visible, "⚡");
|
||||
|
||||
if self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION {
|
||||
ui.separator();
|
||||
self.project_mode = self.toggle(ui, self.project_mode, "c");
|
||||
}
|
||||
// if self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION {
|
||||
// ui.separator();
|
||||
// self.project_mode = self.toggle(ui, self.project_mode, "c");
|
||||
// }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -158,7 +158,11 @@ impl Calcifer {
|
|||
|
||||
for line in &entry.result {
|
||||
let color = if line.error { RED } else { entry_color };
|
||||
ui.label(egui::RichText::new(&line.text).monospace().color(color));
|
||||
ui.label(
|
||||
egui::RichText::new(&line.text)
|
||||
.monospace()
|
||||
.color(color),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -284,6 +288,13 @@ impl Calcifer {
|
|||
}
|
||||
|
||||
pub fn draw_windows(&mut self, ctx: &egui::Context) {
|
||||
if self.project_content.item_window.visible {
|
||||
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 self.search_menu.visible {
|
||||
self.search_menu
|
||||
.show(ctx, &mut self.tabs, &mut self.selected_tab);
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -1,7 +1,6 @@
|
|||
use eframe::egui;
|
||||
use egui::{
|
||||
FontFamily,
|
||||
FontId,
|
||||
FontFamily, FontId,
|
||||
TextStyle::{Body, Button, Heading, Monospace, Small},
|
||||
};
|
||||
use homedir::get_my_home;
|
||||
|
@ -149,10 +148,19 @@ impl eframe::App for Calcifer {
|
|||
|
||||
let mut style = (*ctx.style()).clone();
|
||||
style.text_styles = [
|
||||
(Heading, FontId::new(self.font_size * 1.6, FontFamily::Proportional)),
|
||||
(
|
||||
Heading,
|
||||
FontId::new(self.font_size * 1.6, FontFamily::Proportional),
|
||||
),
|
||||
(Body, FontId::new(self.font_size, FontFamily::Proportional)),
|
||||
(Monospace, FontId::new(self.font_size, FontFamily::Monospace)),
|
||||
(Button, FontId::new(self.font_size, FontFamily::Proportional)),
|
||||
(
|
||||
Monospace,
|
||||
FontId::new(self.font_size, FontFamily::Monospace),
|
||||
),
|
||||
(
|
||||
Button,
|
||||
FontId::new(self.font_size, FontFamily::Proportional),
|
||||
),
|
||||
(Small, FontId::new(self.font_size, FontFamily::Proportional)),
|
||||
]
|
||||
.into();
|
||||
|
@ -168,6 +176,12 @@ impl eframe::App for Calcifer {
|
|||
}
|
||||
}
|
||||
|
||||
if ctx.input(|i| i.key_pressed(egui::Key::Enter))
|
||||
&& self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION
|
||||
{
|
||||
self.project_content.item_window.visible = true;
|
||||
}
|
||||
|
||||
if ctx.input(|i| i.key_pressed(egui::Key::S) && i.modifiers.ctrl) {
|
||||
self.handle_save_file(self.save_tab());
|
||||
}
|
||||
|
|
|
@ -1,22 +1,28 @@
|
|||
use eframe::egui;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::{
|
||||
cmp::min,
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
use crate::MAX_PROJECT_COLUMNS;
|
||||
use crate::core::hex_str_to_color;
|
||||
use crate::editor::ColorTheme;
|
||||
use crate::sub_windows;
|
||||
use crate::MAX_PROJECT_COLUMNS;
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Project {
|
||||
categories: Vec<Category>,
|
||||
selected_item: Option<[usize; 2]>,
|
||||
pub categories: Vec<Category>,
|
||||
pub selected_item: Location,
|
||||
pub item_window: sub_windows::ProjectItemWindow,
|
||||
was_moving: bool,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
categories: vec![Category::create()],
|
||||
selected_item: None,
|
||||
selected_item: Location::zero(),
|
||||
was_moving: false,
|
||||
item_window: sub_windows::ProjectItemWindow::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,9 +44,9 @@ impl Project {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Category {
|
||||
pub struct Category {
|
||||
name: String,
|
||||
content: Vec<Item>,
|
||||
pub content: Vec<Item>,
|
||||
}
|
||||
|
||||
impl Category {
|
||||
|
@ -56,11 +62,10 @@ impl Category {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Hash)]
|
||||
struct Item {
|
||||
name: String,
|
||||
description: String,
|
||||
pub struct Item {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
id: usize,
|
||||
}
|
||||
|
||||
|
@ -76,13 +81,21 @@ impl Item {
|
|||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Location {
|
||||
category: usize,
|
||||
row: usize,
|
||||
pub category: usize,
|
||||
pub row: usize,
|
||||
}
|
||||
|
||||
impl Location {
|
||||
fn zero() -> Self {
|
||||
Self {
|
||||
category: 0,
|
||||
row: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_id() -> usize {
|
||||
static COUNTER:AtomicUsize = AtomicUsize::new(1);
|
||||
static COUNTER: AtomicUsize = AtomicUsize::new(1);
|
||||
COUNTER.fetch_add(1, Ordering::Relaxed)
|
||||
}
|
||||
|
||||
|
@ -96,36 +109,115 @@ pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project)
|
|||
project.add_category();
|
||||
}
|
||||
} else {
|
||||
let response = ui.add(egui::TextEdit::singleline(&mut project.categories[category_index].name).desired_width(f32::INFINITY));
|
||||
let response = ui.add(
|
||||
egui::TextEdit::singleline(&mut project.categories[category_index].name)
|
||||
.desired_width(f32::INFINITY),
|
||||
);
|
||||
if response.lost_focus() && project.categories[category_index].name.is_empty() {
|
||||
project.delete_category(category_index);
|
||||
}
|
||||
}
|
||||
|
||||
for (item_index, item) in category.content.iter().enumerate() {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.literals));
|
||||
if ui.add(egui::Button::new("✒")).clicked() {
|
||||
println!("yes");
|
||||
}
|
||||
|
||||
if project.selected_item == Some([category_index, item_index]) {
|
||||
if project.selected_item
|
||||
== (Location {
|
||||
category: category_index,
|
||||
row: item_index,
|
||||
})
|
||||
{
|
||||
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.bg));
|
||||
ui.add(egui::Button::new(item.name.clone()).fill(hex_str_to_color(theme.functions)));
|
||||
ui.add(
|
||||
egui::Button::new(item.name.clone())
|
||||
.fill(hex_str_to_color(theme.functions)),
|
||||
);
|
||||
} else {
|
||||
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.literals));
|
||||
if ui.add(egui::Button::new(item.name.clone()).fill(hex_str_to_color(theme.bg))).clicked() {
|
||||
project.selected_item = Some([category_index, item_index]);
|
||||
ui.style_mut().visuals.override_text_color =
|
||||
Some(hex_str_to_color(theme.literals));
|
||||
if ui
|
||||
.add(egui::Button::new(item.name.clone()).fill(hex_str_to_color(theme.bg)))
|
||||
.clicked()
|
||||
{
|
||||
project.selected_item = Location {
|
||||
category: category_index,
|
||||
row: item_index,
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if category.name != "+" {
|
||||
if ui.add(egui::Button::new("+")).clicked() {
|
||||
project.categories[category_index].content.push(Item::new("item"));
|
||||
project.categories[category_index]
|
||||
.content
|
||||
.push(Item::new("item"));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let mut moved = false;
|
||||
let category = project.selected_item.category.clone();
|
||||
let row = project.selected_item.row.clone();
|
||||
|
||||
if ui.input(|i| i.key_pressed(egui::Key::ArrowLeft)) && project.selected_item.category > 0 {
|
||||
moved = true;
|
||||
if !project.was_moving {
|
||||
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 {
|
||||
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;
|
||||
if !project.was_moving {
|
||||
project.selected_item.row -= 1;
|
||||
}
|
||||
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowDown))
|
||||
&& project.selected_item.row < project.categories[category].content.len() - 1
|
||||
{
|
||||
moved = true;
|
||||
if !project.was_moving {
|
||||
project.selected_item.row += 1;
|
||||
}
|
||||
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowLeft) && i.modifiers.shift) {
|
||||
moved = true;
|
||||
if !project.was_moving {}
|
||||
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowRight) && i.modifiers.shift) {
|
||||
moved = true;
|
||||
if !project.was_moving {}
|
||||
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowUp) && i.modifiers.shift)
|
||||
&& project.selected_item.row > 0
|
||||
{
|
||||
moved = true;
|
||||
if !project.was_moving {
|
||||
let temp = project.categories[category].content[row].clone();
|
||||
project.categories[category].content[row] =
|
||||
project.categories[category].content[row - 1].clone();
|
||||
project.categories[category].content[row - 1] = temp.clone();
|
||||
project.selected_item.row -= 1;
|
||||
}
|
||||
} else if ui.input(|i| i.key_pressed(egui::Key::ArrowDown) && i.modifiers.shift) {
|
||||
moved = true;
|
||||
if !project.was_moving {
|
||||
let temp = project.categories[category].content[row].clone();
|
||||
project.categories[category].content[row] =
|
||||
project.categories[category].content[row + 1].clone();
|
||||
project.categories[category].content[row + 1] = temp.clone();
|
||||
project.selected_item.row += 1;
|
||||
}
|
||||
}
|
||||
|
||||
project.was_moving = moved;
|
||||
}
|
|
@ -10,3 +10,6 @@ pub use settings::*;
|
|||
|
||||
mod shortcuts;
|
||||
pub use shortcuts::*;
|
||||
|
||||
mod project_item;
|
||||
pub use project_item::*;
|
||||
|
|
28
src/sub_windows/project_item.rs
Normal file
28
src/sub_windows/project_item.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use eframe::egui;
|
||||
|
||||
use crate::panels;
|
||||
|
||||
pub struct ProjectItemWindow {
|
||||
pub visible: bool,
|
||||
}
|
||||
|
||||
impl ProjectItemWindow {
|
||||
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("Project Item")
|
||||
.open(&mut visible)
|
||||
.vscroll(true)
|
||||
.hscroll(true)
|
||||
.show(ctx, |ui| self.ui(ui, item));
|
||||
self.visible = self.visible && visible;
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, item: &mut panels::Item) {
|
||||
ui.set_min_width(250.0);
|
||||
ui.label(item.name.clone());
|
||||
}
|
||||
}
|
|
@ -235,9 +235,7 @@ impl SearchWindow {
|
|||
}
|
||||
|
||||
fn replace(&mut self, tabs: &mut Vec<Tab>, selected_tab: &mut TabNumber) {
|
||||
if self.searched_text != self.search_text {
|
||||
self.search(tabs, &mut *selected_tab);
|
||||
}
|
||||
|
||||
let mut done: Vec<TabNumber> = vec![];
|
||||
for element in &self.results {
|
||||
|
|
Loading…
Reference in a new issue