Skip to content
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 clickable URI component #8567

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions crates/store/re_types/definitions/rerun/components.fbs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions crates/store/re_types/definitions/rerun/components/uri.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace rerun.components;

// ---

/// A general URI (Uniform Resource Identifier).
///
/// To specify a recording, use [archetypes.RecordingUri].
table Uri (
"attr.rust.derive": "PartialEq, Eq, PartialOrd, Ord, Hash",
"attr.docs.unreleased"
) {
uri: rerun.datatypes.Utf8 (order: 100);
}
1 change: 1 addition & 0 deletions crates/store/re_types/src/components/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/store/re_types/src/components/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions crates/store/re_types/src/components/uri.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/store/re_types/src/components/uri_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use super::Uri;

impl Uri {
/// Return the URI contained in this component.
pub fn uri(&self) -> &str {
self.0.as_str()
}
}
8 changes: 8 additions & 0 deletions crates/store/re_types/src/reflection/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/viewer/re_component_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ mod marker_shape;
mod pinhole;
mod plane3d;
mod radius;
mod recording_uri;
mod resolution;
mod response_utils;
mod timeline;
mod transforms;
mod uri;
mod video_timestamp;
mod view_coordinates;
mod visual_bounds2d;
Expand Down Expand Up @@ -165,7 +165,8 @@ pub fn create_component_ui_registry() -> re_viewer_context::ComponentUiRegistry
registry.add_singleline_edit_or_view(pinhole::singleline_view_pinhole);
registry.add_multiline_edit_or_view(pinhole::multiline_view_pinhole);

registry.add_singleline_edit_or_view(recording_uri::singleline_view_recording_uri);
registry.add_singleline_edit_or_view(uri::singleline_view_uri);
registry.add_singleline_edit_or_view(uri::singleline_view_recording_uri);

line_strip::register_linestrip_component_ui(&mut registry);
geo_line_string::register_geo_line_string_component_ui(&mut registry);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use re_types::components::RecordingUri;
use re_types::components::{RecordingUri, Uri};
use re_ui::UiExt as _;
use re_viewer_context::{MaybeMutRef, ViewerContext};

pub fn singleline_view_uri(
_ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
value: &mut MaybeMutRef<'_, Uri>,
) -> egui::Response {
let value = value.as_ref();
ui.re_hyperlink(value.uri())
}

pub fn singleline_view_recording_uri(
_ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems incorrect. it should truncate with the normally

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use re_component_ui::create_component_ui_registry;
use re_log_types::{EntityPath, Timeline};
use re_types::{
blueprint::components::{ComponentColumnSelector, QueryExpression},
components::{self, GraphEdge, GraphNode, ImageFormat, RecordingUri, Text},
components::{self, GraphEdge, GraphNode, ImageFormat, RecordingUri, Text, Uri},
datatypes::{ChannelDatatype, PixelFormat},
};
use re_types_core::{reflection::Reflection, Component, ComponentName, LoggableBatch};
Expand Down Expand Up @@ -68,6 +68,7 @@ fn test_cases(reflection: &Reflection) -> Vec<TestCase> {
RecordingUri::from("rerun://0.0.0.0:1234/recordings/XYZ"),
"simple",
),
TestCase::from_component(Uri::from("https://rerun.io"), "simple"),
TestCase::from_component(Text::from("Hello World!"), "simple"),
];

Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_data_ui/src/component_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DataUi for ComponentName {
}

if let Some(url) = self.doc_url() {
ui.re_hyperlink("Full documentation", url);
ui.re_hyperlink_to("Full documentation", url);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_time_panel/src/time_control_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ You can also define your own timelines, e.g. for sensor time or camera frame num
.trim(),
);

ui.re_hyperlink(
ui.re_hyperlink_to(
"Full documentation",
"https://rerun.io/docs/concepts/timelines",
);
Expand Down
17 changes: 16 additions & 1 deletion crates/viewer/re_ui/src/ui_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,22 @@ pub trait UiExt {
}

/// Helper for adding a list-item hyperlink.
fn re_hyperlink(
fn re_hyperlink(&mut self, url: impl ToString) -> egui::Response {
let ui = self.ui_mut();
let response = ListItem::new()
.show_flat(
ui,
LabelContent::new(url.to_string()).with_icon(&crate::icons::EXTERNAL_LINK),
)
.on_hover_cursor(egui::CursorIcon::PointingHand);
if response.clicked() {
ui.ctx().open_url(egui::OpenUrl::new_tab(url));
}
response
}

/// Helper for adding a list-item hyperlink with text.
fn re_hyperlink_to(
&mut self,
text: impl Into<egui::WidgetText>,
url: impl ToString,
Expand Down
1 change: 1 addition & 0 deletions docs/content/reference/types/components.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/content/reference/types/components/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions docs/content/reference/types/components/uri.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/content/reference/types/datatypes/utf8.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rerun_cpp/src/rerun/components.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rerun_cpp/src/rerun/components/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading