-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split side panel settings into tabs :
Create plot settings tab and highlights settings tab. - The highlights settings allow user to set until 4 regex sentence to find in content and highlight them with predefined color - Edits the plot settings to hide the plot view if number of plot equals 0 Signed-off-by: stropee <[email protected]>
- Loading branch information
Showing
4 changed files
with
467 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
|
||
|
||
use eframe::egui::{FontFamily, FontId}; | ||
use eframe::egui::{self, text::LayoutJob, Color32, TextFormat}; | ||
|
||
|
||
extern crate regex; | ||
use regex::Regex; | ||
use regex::RegexSet; | ||
const DEFAULT_FONT_ID: FontId = FontId::new(14.0, FontFamily::Monospace); | ||
|
||
|
||
#[derive(Debug)] | ||
#[derive(Clone, Copy)] | ||
pub struct HighLightElement | ||
{ | ||
pos_start:usize, | ||
pos_end:usize, | ||
token_idx:usize | ||
} | ||
impl HighLightElement{ | ||
pub fn new(pos_start: usize, pos_end:usize,token_idx:usize) -> Self{ | ||
Self{ | ||
pos_start, | ||
pos_end, | ||
token_idx | ||
} | ||
} | ||
} | ||
pub fn highlight_impl( | ||
_ctx: &egui::Context, | ||
text: &str, | ||
tokens: Vec<String>, | ||
default_color:Color32 | ||
) -> Option<LayoutJob> { | ||
// Extremely simple syntax highlighter for when we compile without syntect | ||
|
||
|
||
let mut my_tokens = tokens.clone(); | ||
for token in my_tokens.clone() | ||
{ | ||
if token.len() < 1 | ||
{ | ||
let index = my_tokens.iter().position(|x| *x == token).unwrap(); | ||
my_tokens.remove(index); | ||
} | ||
} | ||
let set = RegexSet::new(my_tokens.clone()).unwrap(); | ||
let content_string = String::from(text); | ||
// let _ = file.read_to_string(&mut isi); | ||
let mut regexs:Vec<Regex> = Vec::new(); | ||
for sentence in my_tokens.clone() { | ||
let re = Regex::new(&sentence).unwrap(); // should not panic because we parsed Regexes above already | ||
regexs.push(re); | ||
} | ||
|
||
let mut highlight_list : Vec<HighLightElement> = Vec::<HighLightElement>::new(); | ||
|
||
for idx in set.matches(&content_string).into_iter() { | ||
for caps in regexs[idx].captures_iter(&content_string) { | ||
highlight_list.push(HighLightElement::new( | ||
caps.get(0).unwrap().start(), | ||
caps.get(0).unwrap().end(), | ||
idx)); | ||
} | ||
} | ||
|
||
highlight_list.sort_by_key(|item| (item.pos_start, item.pos_end)); | ||
|
||
|
||
let mut job = LayoutJob::default(); | ||
let mut previous = HighLightElement::new(0,0, 0); | ||
for matches in highlight_list | ||
{ | ||
if previous.pos_end >= matches.pos_start | ||
{ | ||
continue | ||
} | ||
job.append(&text[previous.pos_end..(matches.pos_start)], 0.0, TextFormat::simple(DEFAULT_FONT_ID, default_color)); | ||
if matches.token_idx == 0 | ||
{ | ||
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(255, 100, 100))); | ||
}else if matches.token_idx == 1 | ||
{ | ||
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(225, 159, 0))); | ||
|
||
}else if matches.token_idx == 2 | ||
{ | ||
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(87, 165, 171))); | ||
}else if matches.token_idx == 3 | ||
{ | ||
job.append(&text[matches.pos_start..matches.pos_end], 0.0, TextFormat::simple(DEFAULT_FONT_ID, Color32::from_rgb(109, 147, 226))); | ||
} | ||
previous = matches.clone(); | ||
} | ||
job.append(&text[previous.pos_end..], 0.0, TextFormat::simple(DEFAULT_FONT_ID, default_color)); | ||
|
||
|
||
Some(job) | ||
} | ||
|
Oops, something went wrong.