@@ -5,7 +5,9 @@ use egui::{Align, Layout, Link, Ui, UiBuilder};
5
5
use re_types_core:: { ComponentDescriptor , RowId } ;
6
6
use re_ui:: UiExt as _;
7
7
use re_uri:: RedapUri ;
8
- use re_viewer_context:: { SystemCommand , SystemCommandSender as _, ViewerContext } ;
8
+ use re_viewer_context:: {
9
+ SystemCommand , SystemCommandSender as _, ViewerContext , open_url:: ViewerOpenUrl ,
10
+ } ;
9
11
10
12
/// Display an URL as an `Open` button (instead of spelling the full URL).
11
13
///
@@ -52,22 +54,50 @@ pub fn redap_uri_button(
52
54
. iter ( )
53
55
. any ( |source| source. stripped_redap_uri ( ) . as_ref ( ) == Some ( & uri) ) ;
54
56
55
- // Show the link left aligned and justified, so the whole cell is clickable.
56
- let put_justified_left_aligned = |ui : & mut Ui , link| {
57
- ui. scope_builder (
58
- UiBuilder :: new ( ) . max_rect ( ui. max_rect ( ) ) . layout (
59
- Layout :: left_to_right ( Align :: Center )
60
- . with_main_justify ( true )
61
- . with_cross_justify ( true )
62
- . with_main_align ( Align :: Min ) ,
63
- ) ,
64
- |ui| ui. add ( link) ,
65
- )
66
- . inner
57
+ let uri_clone = uri. clone ( ) ;
58
+ // Show the link left aligned and justified so the whole cell is clickable.
59
+ //
60
+ // And add a button to copy the link.
61
+ let link_with_copy = |ui : & mut Ui , link| {
62
+ let rect = ui. max_rect ( ) ;
63
+ let contains_pointer = ui. rect_contains_pointer ( rect) ;
64
+ egui:: Sides :: new ( )
65
+ . shrink_left ( )
66
+ . height ( ui. max_rect ( ) . height ( ) )
67
+ . show (
68
+ ui,
69
+ |ui| {
70
+ ui. scope_builder (
71
+ UiBuilder :: new ( ) . max_rect ( ui. max_rect ( ) ) . layout (
72
+ Layout :: left_to_right ( Align :: Center )
73
+ . with_main_justify ( true )
74
+ . with_cross_justify ( true )
75
+ . with_main_align ( Align :: Min ) ,
76
+ ) ,
77
+ |ui| ui. add ( link) ,
78
+ )
79
+ . inner
80
+ } ,
81
+ |ui| {
82
+ if contains_pointer
83
+ && ui
84
+ . small_icon_button ( & re_ui:: icons:: COPY , "Copy link" )
85
+ . clicked ( )
86
+ {
87
+ if let Ok ( url) = ViewerOpenUrl :: from ( uri_clone) . sharable_url ( None ) {
88
+ ctx. command_sender ( )
89
+ . send_system ( SystemCommand :: CopyViewerUrl ( url) ) ;
90
+ } else {
91
+ re_log:: error!( "Failed to create a sharable url for recording" ) ;
92
+ }
93
+ }
94
+ } ,
95
+ )
96
+ . 0
67
97
} ;
68
98
69
99
if let Some ( loaded_recording_id) = loaded_recording_id {
70
- let response = put_justified_left_aligned ( ui, Link :: new ( "Switch to" ) ) . on_hover_ui ( |ui| {
100
+ let response = link_with_copy ( ui, Link :: new ( "Switch to" ) ) . on_hover_ui ( |ui| {
71
101
ui. label ( "This recording is already loaded. Click to switch to it." ) ;
72
102
} ) ;
73
103
@@ -91,7 +121,7 @@ pub fn redap_uri_button(
91
121
}
92
122
} ) ;
93
123
} else {
94
- let response = put_justified_left_aligned ( ui, Link :: new ( "Open" ) ) . on_hover_ui ( |ui| {
124
+ let response = link_with_copy ( ui, Link :: new ( "Open" ) ) . on_hover_ui ( |ui| {
95
125
ui. label ( uri. to_string ( ) ) ;
96
126
} ) ;
97
127
0 commit comments