-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a text-box component and logtype (#2011)
* New UI for displaying a textbox * Add new TextBox component to simplify view-category creation * Make module experimental * Move to experimental designation * Add experimental APIs to docs * Python import cleanup * Default word_wrap to true and set autoshrink to false for the scroll area
- Loading branch information
Showing
20 changed files
with
322 additions
and
6 deletions.
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.