Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
Update to egui 0.17. Closes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
STBoyden committed Mar 13, 2022
1 parent ea3d980 commit 1700888
Show file tree
Hide file tree
Showing 15 changed files with 1,472 additions and 213 deletions.
765 changes: 732 additions & 33 deletions Cargo.lock

Large diffs are not rendered by default.

730 changes: 627 additions & 103 deletions codectrl-gui/Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions codectrl-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ authors = [
"Balázs Cene (@bczsalba on Github) <bczsalba@gmail.com>",
"Collin Joseph <c.joseph@authentura.com>"
]
description = "A source code analytic tool. Using egui version 0.16."
description = "A source code analytic tool. Using egui version 0.17."
rust-version = "1.58.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.1", features = ["cargo"] }
codectrl_logger = { git = "https://github.com/authentura/codectrl-rust-logger", default-features = false, features = ["types-only"] }
eframe = "0.16"
egui = { version = "0.16", features = ["persistence"] }
epi = { version = "0.16", features = ["persistence"] }
eframe = "0.17"
egui = { version = "0.17", features = ["persistence"] }
epi = { version = "0.17", features = ["persistence"] }
lazy_static = "1.4"
regex = "1.5"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -42,7 +42,7 @@ web-sys = { version = "0.3", features = ["File", "FilePropertyBag", "console"]}
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
chrono = { version = "0.4", features = ["serde"] }
codectrl_log_server = { path = "../codectrl-log-server" }
egui_glow = "0.16"
egui_glow = "0.17"
rfd = "0.6"
tokio = { version = "1.17", default-features = false, features = ["net", "rt-multi-thread", "io-util", "macros"] }

Expand Down
16 changes: 9 additions & 7 deletions codectrl-gui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// the proposal so far.

use crate::components::{
about_view, details_view, fonts, main_view, main_view_empty, settings_view,
about_view, application_style, details_view, fonts, main_view, main_view_empty,
settings_view,
};
#[cfg(not(target_arch = "wasm32"))]
use crate::data::{AppState, Filter, FontSizes, Receiver};
Expand All @@ -34,7 +35,7 @@ use crate::data::{AppState, Filter, Receiver};

use chrono::{DateTime, Local};
use codectrl_logger::Log;
use egui::{CtxRef, Vec2};
use egui::{Context, Vec2};
#[cfg(not(target_arch = "wasm32"))]
use egui::{Event, InputState, Key};
use epi::{Frame, Storage};
Expand Down Expand Up @@ -350,11 +351,12 @@ impl App {
}

impl epi::App for App {
fn update(&mut self, ctx: &CtxRef, _frame: &Frame) {
ctx.set_fonts(fonts(self.data.application_settings.font_sizes));
fn update(&mut self, ctx: &Context, _frame: &Frame) {
ctx.set_fonts(fonts());
ctx.set_style(application_style(self.data.application_settings.font_sizes));

#[cfg(not(target_arch = "wasm32"))]
self.handle_key_inputs(ctx.input());
self.handle_key_inputs(&ctx.input());

if self.data.is_about_open {
about_view(&mut self.data, ctx);
Expand Down Expand Up @@ -510,7 +512,7 @@ impl epi::App for App {
}

#[cfg(not(target_arch = "wasm32"))]
fn setup(&mut self, ctx: &CtxRef, frame: &Frame, storage: Option<&dyn Storage>) {
fn setup(&mut self, ctx: &Context, frame: &Frame, storage: Option<&dyn Storage>) {
if let Some(storage) = storage {
let data: AppState =
epi::get_value(storage, epi::APP_KEY).unwrap_or_default();
Expand Down Expand Up @@ -551,7 +553,7 @@ impl epi::App for App {
}

#[cfg(target_arch = "wasm32")]
fn setup(&mut self, _ctx: &CtxRef, _frame: &Frame, storage: Option<&dyn Storage>) {
fn setup(&mut self, _ctx: &Context, _frame: &Frame, storage: Option<&dyn Storage>) {
if let Some(storage) = storage {
let data: AppState =
epi::get_value(storage, epi::APP_KEY).unwrap_or_default();
Expand Down
4 changes: 2 additions & 2 deletions codectrl-gui/src/components/about_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use super::{
};
use crate::data::AppState;

use egui::{CtxRef, Id, RichText};
use egui::{Context, Id, RichText};

pub fn about_view(
AppState {
about_state,
is_about_open,
..
}: &mut AppState,
ctx: &CtxRef,
ctx: &Context,
) {
egui::Window::new(
RichText::new(about_state.to_string()).color(DARK_HEADER_FOREGROUND_COLOUR),
Expand Down
10 changes: 5 additions & 5 deletions codectrl-gui/src/components/about_view_components/about_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::{
};

use clap::{crate_authors, crate_description, crate_version};
use egui::{CtxRef, CursorIcon, RichText, Sense, TextStyle, Ui};
use egui::{Context, CursorIcon, RichText, Sense, TextStyle, Ui};

pub fn draw_about_body(about_state: &AboutState, ctx: &CtxRef, ui: &mut Ui) {
pub fn draw_about_body(about_state: &AboutState, ctx: &Context, ui: &mut Ui) {
egui::ScrollArea::vertical()
.auto_shrink([false, false])
.show(ui, |ui| match about_state {
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn draw_about_body(about_state: &AboutState, ctx: &CtxRef, ui: &mut Ui) {
ui.add(
egui::TextEdit::multiline(&mut include_str!("../../../../LICENSE"))
.desired_width(ui.available_width())
.text_style(TextStyle::Monospace),
.font(TextStyle::Monospace),
);

ui.heading(
Expand All @@ -90,7 +90,7 @@ pub fn draw_about_body(about_state: &AboutState, ctx: &CtxRef, ui: &mut Ui) {
"../../../../assets/fonts/red-hat/LICENSE"
))
.desired_width(ui.available_width())
.text_style(TextStyle::Monospace),
.font(TextStyle::Monospace),
);

ui.heading(
Expand All @@ -101,7 +101,7 @@ pub fn draw_about_body(about_state: &AboutState, ctx: &CtxRef, ui: &mut Ui) {
"../../../../assets/fonts/roboto/LICENSE"
))
.desired_width(ui.available_width())
.text_style(TextStyle::Monospace),
.font(TextStyle::Monospace),
);
},
});
Expand Down
4 changes: 2 additions & 2 deletions codectrl-gui/src/components/details_view.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::details_view_components::draw_information_grid;
use crate::data::AppState;

use egui::CtxRef;
use egui::Context;

pub fn details_view(app_state: &mut AppState, ctx: &CtxRef) {
pub fn details_view(app_state: &mut AppState, ctx: &Context) {
egui::TopBottomPanel::bottom("log_information")
.resizable(true)
.default_height(350.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use codectrl_logger::Log;
use egui::TextFormat;
use egui::{text::LayoutJob, Color32, Context, FontSelection, TextFormat, TextStyle};
use std::path::Path;
use syntect::{
easy::HighlightLines,
Expand All @@ -8,9 +8,10 @@ use syntect::{
util::LinesWithEndings,
};

pub fn code_highlighter(code: &str, log: &Log<String>) -> egui::text::LayoutJob {
pub fn code_highlighter(code: &str, log: &Log<String>, ctx: &Context) -> LayoutJob {
let syntax_set = SyntaxSet::load_defaults_newlines();
let theme_set = ThemeSet::load_defaults();
let font_id = FontSelection::Style(TextStyle::Monospace).resolve(&ctx.style());

let syntax = if let Some(syntax) = syntax_set.find_syntax_by_name(&log.language) {
syntax
Expand All @@ -24,18 +25,19 @@ pub fn code_highlighter(code: &str, log: &Log<String>) -> egui::text::LayoutJob

let mut highlight =
HighlightLines::new(syntax, &theme_set.themes["Solarized (dark)"]);
let mut job = egui::text::LayoutJob::default();
let mut job = LayoutJob::default();

for line in LinesWithEndings::from(code) {
let ranges: Vec<(Style, &str)> = highlight.highlight(line, &syntax_set);

for h in ranges {
let (style, code) = h;
job.append(
code,
0.0,
TextFormat::simple(
egui::TextStyle::Monospace,
egui::Color32::from_rgb(
font_id.clone(),
Color32::from_rgb(
style.foreground.r,
style.foreground.g,
style.foreground.b,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ use crate::{

use chrono::{DateTime, Local};
use codectrl_logger::Log;
use egui::{CtxRef, RichText, TextStyle, Ui};
use egui::{
text::LayoutJob, Context, FontSelection, Layout, RichText, Sense, TextStyle, Ui,
};
use xxhash_rust::xxh3::xxh3_128 as xxhash;

pub fn draw_information_grid(app_state: &mut AppState, ctx: &CtxRef, ui: &mut Ui) {
pub fn draw_information_grid(app_state: &mut AppState, ctx: &Context, ui: &mut Ui) {
app_state.preview_height = ui.available_height() + 2.0;

ui.horizontal(|ui| {
let heading_width = "Log information".chars().fold(0.0, |sum, c| {
sum + ui.fonts().glyph_width(TextStyle::Heading, c)
sum + ui.fonts().glyph_width(
&FontSelection::Style(TextStyle::Heading).resolve(&ctx.style()),
c,
)
});

ui.add_space((ui.available_width() / 2.0) - heading_width * 0.5);
ui.heading(RichText::new("Log information").color(DARK_HEADER_FOREGROUND_COLOUR));

ui.with_layout(egui::Layout::right_to_left(), |ui| {
ui.with_layout(Layout::right_to_left(), |ui| {
// u1f5d9 = 🗙
if ui.button("\u{1f5d9} Close").clicked() {
app_state.clicked_item = None;
Expand Down Expand Up @@ -68,7 +73,7 @@ fn detail_scroll(
app_state: &mut AppState,
log: &Log<String>,
time: &DateTime<Local>,
ctx: &CtxRef,
ctx: &Context,
ui: &mut Ui,
) {
egui::ScrollArea::vertical()
Expand Down Expand Up @@ -164,9 +169,9 @@ fn code_scroll(
is_copying_line_indicator: &mut bool,
copy_language: &mut String,
code_hash: &mut u128,
code_job: &mut egui::text::LayoutJob,
code_job: &mut LayoutJob,
log: &Log<String>,
ctx: &CtxRef,
ctx: &Context,
ui: &mut Ui,
) {
egui::ScrollArea::vertical()
Expand Down Expand Up @@ -196,15 +201,15 @@ fn code_scroll(

let mut indicated_code = indicated_code.trim_end().to_string();

let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
let mut layouter = |ui: &Ui, string: &str, wrap_width: f32| {
// TODO: Hardcoded Langauge should be accepted from the log
let hash: u128 = xxhash(string.as_bytes());
let mut layout_job: egui::text::LayoutJob;
let mut layout_job: LayoutJob;

if *code_hash == hash {
layout_job = egui::text::LayoutJob::from(code_job.clone());
layout_job = LayoutJob::from(code_job.clone());
} else {
let temp_job = code_highlighter(string, &log);
let temp_job = code_highlighter(string, &log, ctx);

*code_job = temp_job.clone();
layout_job = temp_job;
Expand All @@ -223,7 +228,7 @@ fn code_scroll(
.layouter(&mut layouter)
.code_editor(),
)
.interact(egui::Sense::click())
.interact(Sense::click())
.on_hover_ui_at_pointer(|ui| {
ui.label("Right-click to open context menu");
})
Expand Down
12 changes: 8 additions & 4 deletions codectrl-gui/src/components/main_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::data::{AppState, Filter};

use chrono::{DateTime, Local};
use codectrl_logger::Log;
use egui::{CtxRef, RichText};
use egui::{Context, RichText, TextStyle};
use regex::RegexBuilder;

fn app_state_filter(
Expand Down Expand Up @@ -84,7 +84,7 @@ fn app_state_filter(
}
}

pub fn main_view(app_state: &mut AppState, ctx: &CtxRef) {
pub fn main_view(app_state: &mut AppState, ctx: &Context) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.vertical_centered(|ui| {
egui::ScrollArea::vertical()
Expand Down Expand Up @@ -156,10 +156,14 @@ pub fn main_view(app_state: &mut AppState, ctx: &CtxRef) {
});
}

pub fn main_view_empty(ctx: &CtxRef, socket_address: &str) {
pub fn main_view_empty(ctx: &Context, socket_address: &str) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.vertical_centered(|ui| {
ui.small(RichText::new("codeCTRL").color(CODECTRL_GREEN));
ui.label(
RichText::new("codeCTRL")
.color(CODECTRL_GREEN)
.font(TextStyle::Name("Extra Large".into()).resolve(&ctx.style())),
);
ui.heading(RichText::new("by Authentura").italics());
ui.add_space(ui.available_height() / 3.0);

Expand Down
4 changes: 2 additions & 2 deletions codectrl-gui/src/components/main_view_components/log_item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chrono::{DateTime, Local};
use codectrl_logger::Log;
use egui::{Color32, Label, RichText, Sense, Ui};
use egui::{Align, Color32, Label, RichText, Sense, Ui};
use std::collections::BTreeSet;

type Received = (Log<String>, DateTime<Local>);
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn draw_log_item(

if let Some(clicked_item) = clicked_item {
if do_scroll_to_selected_log && *clicked_item == *received {
radio_response.scroll_to_me(egui::Align::Center);
radio_response.scroll_to_me(Some(Align::Center));
}
}

Expand Down
4 changes: 2 additions & 2 deletions codectrl-gui/src/components/message_preview_view.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use egui::{CtxRef, Id};
use egui::{Context, Id};

pub fn message_preview_view(
is_open: &mut bool,
ctx: &CtxRef,
ctx: &Context,
message: &str,
message_type: &str,
) {
Expand Down
4 changes: 2 additions & 2 deletions codectrl-gui/src/components/settings_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
};
use crate::data::AppState;

use egui::{CtxRef, Id, RichText};
use egui::{Context, Id, RichText};

pub fn settings_view(
AppState {
Expand All @@ -16,7 +16,7 @@ pub fn settings_view(
application_settings,
..
}: &mut AppState,
ctx: &CtxRef,
ctx: &Context,
) {
egui::Window::new(RichText::new("Settings").color(DARK_HEADER_FOREGROUND_COLOUR))
.id(Id::new("settings_view"))
Expand Down
Loading

0 comments on commit 1700888

Please # to comment.