-
Notifications
You must be signed in to change notification settings - Fork 373
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
Add an experimental text-box component and logtype #2011
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
87f9082
New UI for displaying a textbox
jleibs 56ff35a
Add new TextBox component to simplify view-category creation
jleibs 5b49c48
Lints
jleibs 71baddd
typos
jleibs 7fbf154
Rust lints
jleibs c53d97d
Fix doctest
jleibs 811b937
Fixup after rebase
jleibs f09233d
Make module experimental
jleibs 6c303d9
Move to experimental designation
jleibs cf54edb
Add experimental APIs to docs
jleibs 58c82e1
TextBox is much more common that Textbox
jleibs 143c744
Add TODO
jleibs 6185661
Fix doctest
jleibs b51b7b7
Consistent capitalization for view category
jleibs 7b307ac
Python import cleanup
jleibs fad78f3
Default word_wrap to true and set autoshrink to false for the scroll …
jleibs 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
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,43 @@ | ||
use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize}; | ||
|
||
use crate::Component; | ||
|
||
/// A text element intended to be displayed in a text-box | ||
/// | ||
/// ``` | ||
/// use re_log_types::component_types::TextBox; | ||
/// use arrow2_convert::field::ArrowField; | ||
/// use arrow2::datatypes::{DataType, Field}; | ||
/// | ||
/// assert_eq!( | ||
/// TextBox::data_type(), | ||
/// DataType::Struct(vec![ | ||
/// Field::new("body", DataType::Utf8, false), | ||
/// ]) | ||
/// ); | ||
/// ``` | ||
// TODO(jleibs): Should this be reconciled with the `TextEntry` component? | ||
#[derive(Clone, Debug, ArrowField, ArrowSerialize, ArrowDeserialize, PartialEq, Eq)] | ||
pub struct TextBox { | ||
// TODO(jleibs): Support options for advanced styling. HTML? Markdown? | ||
pub body: String, // TODO(#1887): avoid allocations | ||
} | ||
|
||
impl TextBox { | ||
#[inline] | ||
pub fn new(body: impl Into<String>) -> Self { | ||
Self { body: body.into() } | ||
} | ||
|
||
#[inline] | ||
pub fn from_body(body: impl Into<String>) -> Self { | ||
Self { body: body.into() } | ||
} | ||
} | ||
|
||
impl Component for TextBox { | ||
#[inline] | ||
fn name() -> crate::ComponentName { | ||
"rerun.text_box".into() | ||
} | ||
} |
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
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,5 @@ | ||
mod scene; | ||
pub(crate) use self::scene::SceneTextBox; | ||
|
||
mod ui; | ||
pub(crate) use self::ui::{view_text_box, ViewTextBoxState}; |
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,53 @@ | ||
use re_arrow_store::LatestAtQuery; | ||
use re_log::warn_once; | ||
use re_log_types::component_types::{self}; | ||
use re_query::{query_entity_with_primary, QueryError}; | ||
use re_viewer_context::{SceneQuery, ViewerContext}; | ||
|
||
// --- | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct TextBoxEntry { | ||
pub body: String, | ||
} | ||
|
||
/// A text scene, with everything needed to render it. | ||
#[derive(Default)] | ||
pub struct SceneTextBox { | ||
pub text_entries: Vec<TextBoxEntry>, | ||
} | ||
|
||
impl SceneTextBox { | ||
/// Loads all text components into the scene according to the given query. | ||
pub(crate) fn load(&mut self, ctx: &ViewerContext<'_>, query: &SceneQuery<'_>) { | ||
crate::profile_function!(); | ||
|
||
let store = &ctx.log_db.entity_db.data_store; | ||
|
||
for (ent_path, props) in query.iter_entities() { | ||
if !props.visible { | ||
continue; | ||
} | ||
|
||
let query = LatestAtQuery::new(query.timeline, query.latest_at); | ||
match query_entity_with_primary::<component_types::TextBox>( | ||
store, | ||
&query, | ||
ent_path, | ||
&[], | ||
) | ||
.and_then(|ent_view| { | ||
for text_entry in ent_view.iter_primary()?.flatten() { | ||
let component_types::TextBox { body } = text_entry; | ||
self.text_entries.push(TextBoxEntry { body }); | ||
} | ||
Ok(()) | ||
}) { | ||
Ok(_) | Err(QueryError::PrimaryNotFound) => {} | ||
Err(_) => { | ||
warn_once!("text-box query failed for {ent_path:?}"); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,69 @@ | ||
use egui::Label; | ||
use re_viewer_context::ViewerContext; | ||
|
||
use super::SceneTextBox; | ||
|
||
// --- Main view --- | ||
|
||
#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)] | ||
pub struct ViewTextBoxState { | ||
monospace: bool, | ||
word_wrap: bool, | ||
} | ||
|
||
impl Default for ViewTextBoxState { | ||
fn default() -> Self { | ||
Self { | ||
monospace: false, | ||
word_wrap: true, | ||
} | ||
} | ||
} | ||
|
||
impl ViewTextBoxState { | ||
pub fn selection_ui(&mut self, re_ui: &re_ui::ReUi, ui: &mut egui::Ui) { | ||
crate::profile_function!(); | ||
|
||
re_ui.selection_grid(ui, "text_config").show(ui, |ui| { | ||
re_ui.grid_left_hand_label(ui, "Text style"); | ||
ui.vertical(|ui| { | ||
ui.radio_value(&mut self.monospace, false, "Proportional"); | ||
ui.radio_value(&mut self.monospace, true, "Monospace"); | ||
ui.checkbox(&mut self.word_wrap, "Word Wrap"); | ||
}); | ||
ui.end_row(); | ||
}); | ||
} | ||
} | ||
|
||
pub(crate) fn view_text_box( | ||
_ctx: &mut ViewerContext<'_>, | ||
ui: &mut egui::Ui, | ||
state: &mut ViewTextBoxState, | ||
scene: &SceneTextBox, | ||
) -> egui::Response { | ||
crate::profile_function!(); | ||
|
||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| { | ||
egui::ScrollArea::both() | ||
.auto_shrink([false, false]) | ||
.show(ui, |ui| { | ||
// TODO(jleibs): better handling for multiple results | ||
if scene.text_entries.len() == 1 { | ||
let mut text = egui::RichText::new(&scene.text_entries[0].body); | ||
|
||
if state.monospace { | ||
text = text.monospace(); | ||
} | ||
|
||
ui.add(Label::new(text).wrap(state.word_wrap)); | ||
} else { | ||
ui.label(format!( | ||
"Unexpected number of text entries: {}. Limit your query to 1.", | ||
scene.text_entries.len() | ||
)); | ||
} | ||
}) | ||
}) | ||
.response | ||
} |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
"arrow", | ||
"box", | ||
"color", | ||
"experimental", | ||
"label", | ||
"point", | ||
"quaternion", | ||
|
Empty file.
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.
Doesn't it make more sense for word wrapping to be on by default?
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.
Yeah, that's a fair point. I guess I'm so used to text-editor contexts where I self-wrap that I forgot how bad an experience it is to have non-wrapped lines not end up wrapping.