Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7445,6 +7445,7 @@ dependencies = [
"re_arrow_util",
"re_data_ui",
"re_format",
"re_log",
"re_log_types",
"re_protos",
"re_test_context",
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_component_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ all-features = true
re_arrow_util.workspace = true
re_data_ui.workspace = true # Needed for `item_ui`.
re_format.workspace = true
re_log.workspace = true
re_log_types.workspace = true
re_protos.workspace = true
re_tracing.workspace = true
Expand Down
41 changes: 36 additions & 5 deletions crates/viewer/re_component_ui/src/variant_uis/redap_uri_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::str::FromStr as _;

use egui::{Align, Layout, Link, Ui, UiBuilder};
use re_types_core::{ComponentDescriptor, RowId};
use re_ui::UiExt as _;
use re_ui::UiExt;
use re_uri::RedapUri;
use re_viewer_context::{SystemCommand, SystemCommandSender as _, ViewerContext};
use re_viewer_context::{
SystemCommand, SystemCommandSender as _, ViewerContext, open_url::ViewerOpenUrl,
};

/// Display an URL as an `Open` button (instead of spelling the full URL).
///
Expand Down Expand Up @@ -52,16 +54,45 @@ pub fn redap_uri_button(
.iter()
.any(|source| source.redap_uri().as_ref() == Some(&uri));

let uri_clone = uri.clone();
// Show the link left aligned and justified, so the whole cell is clickable.
let put_justified_left_aligned = |ui: &mut Ui, link| {
ui.scope_builder(
UiBuilder::new().max_rect(ui.max_rect()).layout(
Layout::left_to_right(Align::Center)
.with_main_justify(true)
Layout::right_to_left(Align::Center)
.with_cross_justify(true)
.with_main_align(Align::Min),
),
Copy link
Member

Choose a reason for hiding this comment

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

I believe you could use egui::Sides for this. See e.g. how the table headers (which have a right aligned menu button) is implemented, in header_cell_ui (datafusion_table_widget.rs)

Copy link
Member Author

Choose a reason for hiding this comment

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

ahh thanks! I felt like there had to be some better way to do it, still a bit finicky to get the whole cell clickable, but managed to do it :)

|ui| ui.add(link),
|ui| {
let rect = if ui.rect_contains_pointer(ui.max_rect()) {
let res = ui.small_icon_button(&re_ui::icons::COPY, "Copy link");
if res.clicked() {
if let Ok(url) = ViewerOpenUrl::from(uri_clone).sharable_url(None) {
ctx.command_sender()
.send_system(SystemCommand::CopyViewerUrl(url));
} else {
re_log::error!("Failed to create a sharable url for recording");
}
}

let mut rect = ui.max_rect();
rect.max.x = res.rect.min.x;
rect
} else {
ui.max_rect()
};

ui.scope_builder(
UiBuilder::new().max_rect(rect).layout(
Layout::left_to_right(Align::Center)
.with_main_justify(true)
.with_cross_justify(true)
.with_main_align(Align::Min),
),
|ui| ui.add(link),
)
.inner
},
)
.inner
};
Expand Down
11 changes: 11 additions & 0 deletions crates/viewer/re_viewer_context/src/open_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ pub enum ViewerOpenUrl {
},
}

impl From<re_uri::RedapUri> for ViewerOpenUrl {
fn from(value: re_uri::RedapUri) -> Self {
match value {
re_uri::RedapUri::Catalog(uri) => Self::RedapCatalog(uri),
re_uri::RedapUri::Entry(uri) => Self::RedapEntry(uri),
re_uri::RedapUri::DatasetData(uri) => Self::RedapDatasetPartition(uri),
re_uri::RedapUri::Proxy(uri) => Self::RedapProxy(uri),
}
}
}

impl std::str::FromStr for ViewerOpenUrl {
type Err = anyhow::Error;

Expand Down
Loading