Skip to content

Commit

Permalink
TextBox is much more common that Textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed May 9, 2023
1 parent cf54edb commit 58c82e1
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions crates/re_log_types/src/component_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ mod rect;
mod scalar;
mod size;
mod tensor;
mod text_box;
mod text_entry;
mod textbox;
mod transform;
mod vec;

Expand Down Expand Up @@ -66,8 +66,8 @@ pub use tensor::{
};
#[cfg(feature = "image")]
pub use tensor::{TensorImageLoadError, TensorImageSaveError};
pub use text_box::TextBox;
pub use text_entry::TextEntry;
pub use textbox::Textbox;
pub use transform::{Pinhole, Rigid3, Transform};
pub use vec::{Vec2D, Vec3D, Vec4D};

Expand Down Expand Up @@ -95,7 +95,7 @@ lazy_static! {
<Size3D as Component>::field(),
<Tensor as Component>::field(),
<TextEntry as Component>::field(),
<Textbox as Component>::field(),
<TextBox as Component>::field(),
<Transform as Component>::field(),
<Vec2D as Component>::field(),
<Vec3D as Component>::field(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ use arrow2_convert::{ArrowDeserialize, ArrowField, ArrowSerialize};

use crate::Component;

/// A text element intended to be displayed in a textbox
/// 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(),
/// 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 {
pub struct TextBox {
// TODO(jleibs): Support options for advanced styling. HTML? Markdown?
pub body: String,
}

impl Textbox {
impl TextBox {
#[inline]
pub fn new(body: impl Into<String>) -> Self {
Self { body: body.into() }
Expand All @@ -35,9 +35,9 @@ impl Textbox {
}
}

impl Component for Textbox {
impl Component for TextBox {
#[inline]
fn name() -> crate::ComponentName {
"rerun.textbox".into()
"rerun.text_box".into()
}
}
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod view_bar_chart;
mod view_category;
mod view_tensor;
mod view_text;
mod view_textbox;
mod view_text_box;
mod view_time_series;
mod viewport;

Expand Down
10 changes: 5 additions & 5 deletions crates/re_viewer/src/ui/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
use super::{
data_blueprint::DataBlueprintTree, space_view_heuristics::default_queried_entities,
view_bar_chart, view_category::ViewCategory, view_spatial, view_tensor, view_text,
view_textbox, view_time_series,
view_text_box, view_time_series,
};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -209,7 +209,7 @@ impl SpaceView {
}

ViewCategory::Textbox => {
let mut scene = view_textbox::SceneTextbox::default();
let mut scene = view_text_box::SceneTextBox::default();
scene.load(ctx, &query);
self.view_state.ui_textbox(ctx, ui, &scene);
}
Expand Down Expand Up @@ -312,7 +312,7 @@ pub struct ViewState {
selected_tensor: Option<InstancePath>,

state_text: view_text::ViewTextState,
state_textbox: view_textbox::ViewTextboxState,
state_textbox: view_text_box::ViewTextBoxState,
state_time_series: view_time_series::ViewTimeSeriesState,
state_bar_chart: view_bar_chart::BarChartState,
pub state_spatial: view_spatial::ViewSpatialState,
Expand Down Expand Up @@ -407,14 +407,14 @@ impl ViewState {
&mut self,
ctx: &mut ViewerContext<'_>,
ui: &mut egui::Ui,
scene: &view_textbox::SceneTextbox,
scene: &view_text_box::SceneTextBox,
) {
egui::Frame {
inner_margin: re_ui::ReUi::view_padding().into(),
..egui::Frame::default()
}
.show(ui, |ui| {
view_textbox::view_textbox(ctx, ui, &mut self.state_textbox, scene);
view_text_box::view_text_box(ctx, ui, &mut self.state_textbox, scene);
});
}

Expand Down
6 changes: 3 additions & 3 deletions crates/re_viewer/src/ui/view_category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use re_arrow_store::{LatestAtQuery, TimeInt};
use re_data_store::{EntityPath, LogDb, Timeline};
use re_log_types::{
component_types::{
Box3D, LineStrip2D, LineStrip3D, Point2D, Point3D, Rect2D, Scalar, Tensor, TextEntry,
Textbox,
Box3D, LineStrip2D, LineStrip3D, Point2D, Point3D, Rect2D, Scalar, Tensor, TextBox,
TextEntry,
},
Arrow3D, Component, Mesh3D, Transform,
};
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn categorize_entity_path(
{
if component == TextEntry::name() {
set.insert(ViewCategory::Text);
} else if component == Textbox::name() {
} else if component == TextBox::name() {
set.insert(ViewCategory::Textbox);
} else if component == Scalar::name() {
set.insert(ViewCategory::TimeSeries);
Expand Down
5 changes: 5 additions & 0 deletions crates/re_viewer/src/ui/view_text_box/mod.rs
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};
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ use re_viewer_context::{SceneQuery, ViewerContext};
// ---

#[derive(Debug, Clone)]
pub struct TextboxEntry {
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>,
pub struct SceneTextBox {
pub text_entries: Vec<TextBoxEntry>,
}

impl SceneTextbox {
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!();
Expand All @@ -30,22 +30,22 @@ impl SceneTextbox {
}

let query = LatestAtQuery::new(query.timeline, query.latest_at);
match query_entity_with_primary::<component_types::Textbox>(
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 });
let component_types::TextBox { body } = text_entry;
self.text_entries.push(TextBoxEntry { body });
}
Ok(())
}) {
Ok(_) | Err(QueryError::PrimaryNotFound) => {}
Err(_) => {
warn_once!("textbox query failed for {ent_path:?}");
warn_once!("text-box query failed for {ent_path:?}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use egui::Label;
use re_viewer_context::ViewerContext;

use super::SceneTextbox;
use super::SceneTextBox;

// --- Main view ---

#[derive(Clone, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(default)]
pub struct ViewTextboxState {
pub struct ViewTextBoxState {
monospace: bool,
word_wrap: bool,
}

impl ViewTextboxState {
impl ViewTextBoxState {
pub fn selection_ui(&mut self, re_ui: &re_ui::ReUi, ui: &mut egui::Ui) {
crate::profile_function!();

Expand All @@ -28,11 +28,11 @@ impl ViewTextboxState {
}
}

pub(crate) fn view_textbox(
pub(crate) fn view_text_box(
_ctx: &mut ViewerContext<'_>,
ui: &mut egui::Ui,
state: &mut ViewTextboxState,
scene: &SceneTextbox,
state: &mut ViewTextBoxState,
scene: &SceneTextBox,
) -> egui::Response {
crate::profile_function!();

Expand All @@ -49,7 +49,7 @@ pub(crate) fn view_textbox(
ui.add(Label::new(text).wrap(state.word_wrap));
} else {
ui.label(format!(
"Unepxected number of text entries: {}. Limit your query to 1.",
"Unexpected number of text entries: {}. Limit your query to 1.",
scene.text_entries.len()
));
}
Expand Down
5 changes: 0 additions & 5 deletions crates/re_viewer/src/ui/view_textbox/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
from rerun.components import REGISTERED_COMPONENT_NAMES, ComponentTypeFactory

__all__ = [
"TextboxArray",
"TextboxType",
"TextBoxArray",
"TextBoxType",
]


class TextboxArray(pa.ExtensionArray): # type: ignore[misc]
def from_bodies(text_entries: Sequence[tuple[str]]) -> TextboxArray:
class TextBoxArray(pa.ExtensionArray): # type: ignore[misc]
def from_bodies(text_entries: Sequence[tuple[str]]) -> TextBoxArray:
"""Build a `TextboxArray` from a sequence of text bodies."""

storage = pa.array(text_entries, type=TextboxType.storage_type)
storage = pa.array(text_entries, type=TextBoxType.storage_type)
# TODO(jleibs) enable extension type wrapper
# return cast(TextboxArray, pa.ExtensionArray.from_storage(TextboxType(), storage))
return storage # type: ignore[no-any-return]


TextboxType = ComponentTypeFactory("TextboxType", TextboxArray, REGISTERED_COMPONENT_NAMES["rerun.textbox"])
TextBoxType = ComponentTypeFactory("TextboxType", TextBoxArray, REGISTERED_COMPONENT_NAMES["rerun.text_box"])

pa.register_extension_type(TextboxType())
pa.register_extension_type(TextBoxType())
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/log/experimental/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Fully qualified to avoid circular import
import rerun.log.extension_components
from rerun import bindings
from rerun.components.experimental.textbox import TextboxArray
from rerun.components.experimental.text_box import TextBoxArray
from rerun.components.instance import InstanceArray
from rerun.log.log_decorator import log_decorator

Expand Down Expand Up @@ -38,7 +38,7 @@ def log_text_box(
splats: Dict[str, Any] = {}

if text:
instanced["rerun.textbox"] = TextboxArray.from_bodies([(text,)])
instanced["rerun.text_box"] = TextBoxArray.from_bodies([(text,)])
else:
logging.warning(f"Null text entry in log_text_entry('{entity_path}') will be dropped.")

Expand Down

0 comments on commit 58c82e1

Please sign in to comment.