-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Syntax highlighting of entity paths and instance paths (#4803)
### What * Closes #4598 Adds basic syntax highlighting to patsh. Slashes and brackets are in a fixed bright-white color, while the text uses the color appropriate for the widget it is in (labels are dimmer than button, for instance). For labels this produces a lot of contrast: ![image](https://github.com/rerun-io/rerun/assets/1148717/b77139e6-6a5e-4779-a367-c64026997b47) For buttons, not so much: ![image](https://github.com/rerun-io/rerun/assets/1148717/104f59b1-8226-4b88-a1e6-3c0a7d93ae14) ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/4803/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4803/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4803/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4803) - [Docs preview](https://rerun.io/preview/6243e3c459dffd9c6c7f9f72c2bc4d9ab176044c/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/6243e3c459dffd9c6c7f9f72c2bc4d9ab176044c/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
- Loading branch information
Showing
6 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,64 @@ | ||
use re_entity_db::InstancePath; | ||
use re_log_types::{EntityPath, EntityPathPart}; | ||
|
||
use egui::{text::LayoutJob, Color32, Style, TextFormat}; | ||
|
||
pub trait SyntaxHighlighting { | ||
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)); | ||
} | ||
} | ||
} |
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