-
Notifications
You must be signed in to change notification settings - Fork 335
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
Allow TextLog body to display as immutable TextEdit rather than Label #4716
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use egui::Widget; | ||
use re_entity_db::EntityProperties; | ||
use std::collections::BTreeMap; | ||
|
||
|
@@ -24,6 +25,8 @@ pub struct TextSpaceViewState { | |
pub filters: ViewTextFilters, | ||
|
||
monospace: bool, | ||
|
||
selectable: bool, | ||
} | ||
|
||
impl SpaceViewState for TextSpaceViewState { | ||
|
@@ -125,6 +128,7 @@ impl SpaceViewClass for TextSpaceView { | |
.radio_value(ui, &mut state.monospace, false, "Proportional"); | ||
ctx.re_ui | ||
.radio_value(ui, &mut state.monospace, true, "Monospace"); | ||
ctx.re_ui.checkbox(ui, &mut state.selectable, "Selectable"); | ||
}); | ||
ui.end_row(); | ||
}); | ||
|
@@ -402,16 +406,60 @@ fn table_ui( | |
|
||
// body | ||
row.col(|ui| { | ||
let mut text = egui::RichText::new(entry.body.as_str()); | ||
if state.selectable { | ||
// Use a &str with TextEdit so body is selectable but immutable. | ||
let entry_text_rows = entry.num_body_lines; | ||
let mut binding = entry.body.as_str(); | ||
let mut text = egui::TextEdit::multiline(&mut binding) | ||
.min_size([0.0, 0.0].into()) | ||
.desired_rows(entry_text_rows) | ||
.desired_width(f32::INFINITY); | ||
// Font information for LayoutJob, based on default_layouter in `egui::TextEdit::show_contents` | ||
let font_id = if state.monospace { | ||
egui::TextStyle::Monospace.into() | ||
} else { | ||
egui::FontSelection::default() | ||
} | ||
.resolve(ui.style()); | ||
let text_color = if let Some(color) = entry.color { | ||
color.into() | ||
} else { | ||
// TODO(lupickup): Understand why TextEdit text color is white instead of gray like the RichText version. | ||
ui.visuals() | ||
.override_text_color | ||
.unwrap_or_else(|| ui.visuals().widgets.inactive.text_color()) | ||
}; | ||
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| { | ||
let mut layout_job = egui::text::LayoutJob::simple( | ||
string.to_owned(), | ||
font_id.clone(), | ||
text_color, | ||
wrap_width, | ||
); | ||
layout_job.wrap.max_rows = entry_text_rows; | ||
// Fill to end of body column instead of choosing a full "word" to ellide | ||
layout_job.wrap.break_anywhere = true; | ||
ui.fonts(|f| f.layout_job(layout_job)) | ||
Comment on lines
+433
to
+442
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. I suggest you compute this By computing the galley up-front you can pass the size of it to |
||
}; | ||
text = text.layouter(&mut layouter); | ||
|
||
let response = text.ui(ui); | ||
if response.hovered() { | ||
response.on_hover_text(entry.body.as_str()); | ||
} | ||
} else { | ||
let mut text = egui::RichText::new(entry.body.as_str()); | ||
|
||
if state.monospace { | ||
text = text.monospace(); | ||
} | ||
if let Some(color) = entry.color { | ||
text = text.color(color); | ||
} | ||
if state.monospace { | ||
text = text.monospace(); | ||
} | ||
|
||
ui.label(text); | ||
if let Some(color) = entry.color { | ||
text = text.color(color); | ||
} | ||
|
||
ui.label(text); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
@@ -428,8 +476,5 @@ fn table_ui( | |
} | ||
|
||
fn calc_row_height(entry: &Entry) -> f32 { | ||
// Simple, fast, ugly, and functional | ||
let num_newlines = entry.body.bytes().filter(|&c| c == b'\n').count(); | ||
let num_rows = 1 + num_newlines; | ||
num_rows as f32 * re_ui::ReUi::table_line_height() | ||
entry.num_body_lines as f32 * re_ui::ReUi::table_line_height() | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
inactive.text_color
is the text color of an interactive widget (that is not currently being interacted with). That's why you get white text: https://docs.rs/egui/latest/egui/style/struct.Widgets.html#structfield.inactiveUse
noninteractive
instead (we don't count text selection as interaction)