1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
#![allow(unused_variables)] use crate::prelude::*; use crate::{Actor, ActorBox, BorderImage, FloatingWidget, Geometry, Widget}; use glib::signal::SignalHandlerId; use std::{cell::RefCell, fmt}; #[derive(Clone, Debug)] pub struct TooltipProps { pub label: Option<Actor>, pub arrow_box: Option<ActorBox>, pub arrow_offset: f32, pub actor_below: f32, pub tip_area: Option<Geometry>, pub stage_matrix: dx::Matrix, pub border_image: BorderImage, pub text_allocation: Option<ActorBox>, pub border_image_texture: Option<dx::Handle>, } #[derive(Clone, Debug)] pub struct Tooltip { props: RefCell<TooltipProps>, widget: FloatingWidget, } impl Tooltip { /// is_in_browse_mode: /// /// Browse mode is entered whenever a tooltip is displayed and it is /// left after a short delay when a tooltip is hidden. This is used to /// make tooltips display quicker when a previous tooltip is already /// displayed. /// /// Returns: %true if the app is in tooltip browse mode or %false /// otherwise. /// pub fn is_in_browse_mode() -> bool { // assert_initialized_main_thread!(); // unsafe { from_glib(ffi::tooltip_is_in_browse_mode()) } unimplemented!() } } impl Object for Tooltip {} impl Is<Tooltip> for Tooltip {} impl AsRef<Tooltip> for Tooltip { fn as_ref(&self) -> &Tooltip { self } } impl Is<FloatingWidget> for Tooltip {} impl AsRef<FloatingWidget> for Tooltip { fn as_ref(&self) -> &FloatingWidget { &self.widget } } impl Is<Widget> for Tooltip {} impl AsRef<Widget> for Tooltip { fn as_ref(&self) -> &Widget { let widget: &Widget = self.widget.as_ref(); widget } } impl Is<Actor> for Tooltip {} impl AsRef<Actor> for Tooltip { fn as_ref(&self) -> &Actor { let actor: &Actor = self.widget.as_ref(); actor } } pub trait TooltipExt: 'static { /// get_text: /// @tooltip: a #Tooltip /// /// Get the text displayed on the tooltip /// /// Returns: the text for the tooltip. This must not be freed by the application /// fn get_text(&self) -> Option<String>; /// get_tip_area: /// @tooltip: A #Tooltip /// /// Retrieve the area on the stage that the tooltip currently applies to /// /// Returns: the #Geometry, owned by the tooltip which must not be freed /// by the application. /// fn get_tip_area(&self) -> Option<Geometry>; /// hide: /// @tooltip: a #Tooltip /// /// Hide the tooltip /// fn hide(&self); /// set_text: /// @tooltip: a #Tooltip /// @text: text to set the label to /// /// Sets the text displayed on the tooltip /// fn set_text(&self, text: &str); /// set_tip_area: /// @tooltip: A #Tooltip /// @area: A #Geometry /// /// Set the area on the stage that the tooltip applies to. /// fn set_tip_area(&self, area: &Geometry); /// set_tip_area_from_actor: /// @tooltip: A #Tooltip /// @actor: A #Actor /// /// Utility function to set the geometry of the tooltip area /// from an existing actor. /// See also set_tip_area /// fn set_tip_area_from_actor<P: Is<Actor>>(&self, actor: &P); /// show: /// @tooltip: a #Tooltip /// /// Show the tooltip relative to the associated widget. /// fn show(&self); fn connect_property_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; fn connect_property_tip_area_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; } impl<O: Is<Tooltip>> TooltipExt for O { /// get_text: /// @tooltip: a #Tooltip /// /// Get the text displayed on the tooltip /// /// Returns: the text for the tooltip. This must not be freed by the application /// fn get_text(&self) -> Option<String> { let tooltip = self.as_ref(); // clutter_text_get_text(CLUTTER_TEXT(tooltip.label)); unimplemented!() } /// get_tip_area: /// @tooltip: A #Tooltip /// /// Retrieve the area on the stage that the tooltip currently applies to /// /// Returns: the #Geometry, owned by the tooltip which must not be freed /// by the application. /// fn get_tip_area(&self) -> Option<Geometry> { let tooltip = self.as_ref(); let props = tooltip.props.borrow(); props.tip_area.clone() } /// hide: /// @tooltip: a #Tooltip /// /// Hide the tooltip /// fn hide(&self) { let tooltip = self.as_ref(); // tooltip_set_opacity(tooltip, 0x0); // g_signal_connect(tooltip, "transition-stopped::opacity", // G_CALLBACK(tooltip_hide_complete), None); // // Leave browse mode after a short delay // if tooltip_browse_mode_timeout { // g_source_remove (tooltip_browse_mode_timeout); // } // tooltip_browse_mode_timeout = // g_timeout_add (TOOLTIP_BROWSE_MODE_TIMEOUT, // tooltip_browse_mode_timeout_cb, // None); } /// set_text: /// @tooltip: a #Tooltip /// @text: text to set the label to /// /// Sets the text displayed on the tooltip /// fn set_text(&self, text: &str) { let tooltip = self.as_ref(); // clutter_text_set_text(CLUTTER_TEXT(tooltip.label), text); // if CLUTTER_ACTOR_IS_VISIBLE(tooltip) { // tooltip_update_position(tooltip); // } // g_object_notify(G_OBJECT(tooltip), "text"); } /// set_tip_area: /// @tooltip: A #Tooltip /// @area: A #Geometry /// /// Set the area on the stage that the tooltip applies to. /// fn set_tip_area(&self, area: &Geometry) { let tooltip = self.as_ref(); let props = tooltip.props.borrow(); if props.tip_area.is_some() { // g_boxed_free(CLUTTER_TYPE_GEOMETRY, tooltip.tip_area); } // tooltip.tip_area = g_boxed_copy(CLUTTER_TYPE_GEOMETRY, area); } /// set_tip_area_from_actor: /// @tooltip: A #Tooltip /// @actor: A #Actor /// /// Utility function to set the geometry of the tooltip area /// from an existing actor. /// See also set_tip_area /// fn set_tip_area_from_actor<P: Is<Actor>>(&self, actor: &P) { let tooltip = self.as_ref(); let actor = actor.as_ref(); // ClutterVertex verts[4]; // ClutterGeometry area; // gfloat x, y, x2, y2; // gint i; // /* Work out the bounding box */ // clutter_actor_get_abs_allocation_vertices (actor, verts); // let x: f32 = y = G_MAXFLOAT; // let x2: f32 = -G_MAXFLOAT; // let y2: f32 = -G_MAXFLOAT; // for idx in 0..G_N_ELEMENTS(verts) { // if verts[idx].x < x { // x = verts[idx].x; // } // if verts[idx].x > x2 { // x2 = verts[idx].x; // } // if verts[idx].y < y { // y = verts[idx].y; // } // if verts[idx].y > y2 { // y2 = verts[idx].y; // } // } // area.x = x; // area.y = y; // area.width = x2 - x; // area.height = y2 - y; // tooltip_set_tip_area(tooltip, &area); } /// show: /// @tooltip: a #Tooltip /// /// Show the tooltip relative to the associated widget. /// fn show(&self) { let tooltip = self.as_ref(); // tooltip_update_position(tooltip); // // finally show the tooltip... // CLUTTER_ACTOR_CLASS(tooltip_parent_class)->show(CLUTTER_ACTOR (tooltip)); // tooltip_set_opacity(tooltip, 0xff); // // Enter browse mode // tooltip_in_browse_mode = true; // // Disable any previous queued attempts to leave browse mode // if tooltip_browse_mode_timeout { // g_source_remove(tooltip_browse_mode_timeout); // tooltip_browse_mode_timeout = 0; // } } fn connect_property_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { // unsafe extern "C" fn notify_text_trampoline<P, F: Fn(&P) + 'static>( // this: *mut ffi::Tooltip, // _param_spec: glib_sys::gpointer, // f: glib_sys::gpointer, // ) where // P: Is<Tooltip>, // { // let f: &F = &*(f as *const F); // f(&Tooltip::from_glib_borrow(this).unsafe_cast_ref()) // } // unsafe { // let f: Box_<F> = Box_::new(f); // connect_raw( // self.as_ptr() as *mut _, // b"notify::text\0".as_ptr() as *const _, // Some(transmute::<_, unsafe extern "C" fn()>( // notify_text_trampoline::<Self, F> as *const (), // )), // Box_::into_raw(f), // ) // } unimplemented!() } fn connect_property_tip_area_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { // unsafe extern "C" fn notify_tip_area_trampoline<P, F: Fn(&P) + 'static>( // this: *mut ffi::Tooltip, // _param_spec: glib_sys::gpointer, // f: glib_sys::gpointer, // ) where // P: Is<Tooltip>, // { // let f: &F = &*(f as *const F); // f(&Tooltip::from_glib_borrow(this).unsafe_cast_ref()) // } // unsafe { // let f: Box_<F> = Box_::new(f); // connect_raw( // self.as_ptr() as *mut _, // b"notify::tip-area\0".as_ptr() as *const _, // Some(transmute::<_, unsafe extern "C" fn()>( // notify_tip_area_trampoline::<Self, F> as *const (), // )), // Box_::into_raw(f), // ) // } unimplemented!() } } impl fmt::Display for Tooltip { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Tooltip") } }