-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax highlighting of entity paths and instance paths #4803
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use re_entity_db::InstancePath; | ||
use re_log_types::{EntityPath, EntityPathPart}; | ||
|
||
use egui::{text::LayoutJob, Color32, Style, TextFormat}; | ||
|
||
pub trait SyntaxHighlighting { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it actually syntax highlighting or just "make this an egui text"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed live: we'll probably use this trait for more syntax highlighting stuff in the future, and that's what you want to search for in the code. Still, we can revisit the name later if we want to. |
||
fn syntax_highlighted(&self, style: &Style) -> LayoutJob { | ||
let mut job = LayoutJob::default(); | ||
self.syntax_highlight_into(style, &mut job); | ||
job | ||
} | ||
|
||
fn syntax_highlight_into(&self, style: &Style, job: &mut LayoutJob); | ||
} | ||
|
||
fn text_format(style: &Style) -> TextFormat { | ||
TextFormat { | ||
font_id: egui::TextStyle::Body.resolve(style), | ||
|
||
// This color be replaced with appropriate color based on widget, | ||
// and whether the widget is hovered, etc | ||
color: Color32::PLACEHOLDER, | ||
|
||
..Default::default() | ||
} | ||
} | ||
|
||
fn faint_text_format(style: &Style) -> TextFormat { | ||
TextFormat { | ||
color: Color32::WHITE, | ||
|
||
..text_format(style) | ||
} | ||
} | ||
|
||
impl SyntaxHighlighting for EntityPathPart { | ||
fn syntax_highlight_into(&self, style: &Style, job: &mut LayoutJob) { | ||
job.append(&self.ui_string(), 0.0, text_format(style)); | ||
} | ||
} | ||
|
||
impl SyntaxHighlighting for EntityPath { | ||
fn syntax_highlight_into(&self, style: &Style, job: &mut LayoutJob) { | ||
job.append("/", 0.0, faint_text_format(style)); | ||
|
||
for (i, part) in self.iter().enumerate() { | ||
if i != 0 { | ||
job.append("/", 0.0, faint_text_format(style)); | ||
} | ||
part.syntax_highlight_into(style, job); | ||
} | ||
} | ||
} | ||
|
||
impl SyntaxHighlighting for InstancePath { | ||
fn syntax_highlight_into(&self, style: &Style, job: &mut LayoutJob) { | ||
self.entity_path.syntax_highlight_into(style, job); | ||
if !self.instance_key.is_splat() { | ||
job.append("[", 0.0, faint_text_format(style)); | ||
job.append(&self.instance_key.to_string(), 0.0, text_format(style)); | ||
job.append("]", 0.0, faint_text_format(style)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move instance path to where?
aren't these making re_ui a lot less lightweight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like it belongs in a more low-level crate, like
re_types
Yes. The alternative is to create yet another crate, or add more feature flags, and both kind of sucks.