-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): 🎸 builtin widget of tooltips
- Loading branch information
Showing
13 changed files
with
149 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::prelude::*; | ||
class_names! { | ||
#[doc = "Class name for the tooltips"] | ||
TOOLTIPS, | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct Tooltips { | ||
pub(crate) tips: CowArc<str>, | ||
} | ||
|
||
impl<'c> ComposeChild<'c> for Tooltips { | ||
type Child = Widget<'c>; | ||
fn compose_child(this: impl StateWriter<Value = Self>, child: Self::Child) -> Widget<'c> { | ||
fn_widget! { | ||
let wnd = BuildCtx::get().window(); | ||
let mut child = FatObj::new(child); | ||
|
||
watch!($child.is_hover()) | ||
.distinct_until_changed() | ||
.filter(|v| *v) | ||
.subscribe(move |_| { | ||
let this = this.clone_writer(); | ||
let overlay = Overlay::new( | ||
fn_widget! { | ||
@Text { | ||
text: pipe!($this.tips.clone()), | ||
class: TOOLTIPS, | ||
} | ||
}, OverlayStyle { | ||
auto_close_policy: AutoClosePolicy::NOT_AUTO_CLOSE, | ||
mask: None, | ||
}); | ||
|
||
overlay.clone().show_map(move |w: Widget| { | ||
let overlay = overlay.clone(); | ||
watch!($child.is_hover()) | ||
.distinct_until_changed() | ||
.filter(|v| !v) | ||
.take(1) | ||
.subscribe(move |_| overlay.close()); | ||
let mut w = FatObj::new(w); | ||
let anchor_widget = w.get_global_anchor_widget().clone_writer(); | ||
@$ w{ | ||
anchor: pipe!(Anchor::left(-$w.layout_size().width / 2.)), | ||
on_mounted: move|e| { | ||
if let Some(wid) = $child.track_id() { | ||
anchor_widget.bottom_align_to(&wid, $child.layout_size().height, e.window()); | ||
anchor_widget.left_align_to(&wid, $child.layout_size().width / 2., e.window()); | ||
} | ||
} | ||
}.into_widget() | ||
}, wnd.clone()); | ||
}); | ||
@ $child {} | ||
} | ||
.into_widget() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use ribir_core::prelude::*; | ||
|
||
class_names! { | ||
TOOLTIPS_BASE, | ||
} | ||
|
||
pub(super) fn init(classes: &mut Classes) { | ||
classes.insert(TOOLTIPS_BASE, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
@BoxDecoration { | ||
background: Palette::of(BuildCtx::get()).inverse_surface(), | ||
margin: EdgeInsets::only_bottom(4.), | ||
border_radius: Radius::all(32.), | ||
@ $w { | ||
margin: EdgeInsets::new(8., 4., 4., 8.), | ||
foreground: Palette::of(BuildCtx::get()).inverse_on_surface(), | ||
v_align: VAlign::Center, | ||
h_align: HAlign::Center, | ||
} | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(TOOLTIPS, |w| { | ||
fn_widget! { | ||
let w = FatObj::new(w); | ||
let mut w = @ $w { | ||
class: TOOLTIPS_BASE, | ||
}; | ||
$w.write().keep_alive = true; | ||
|
||
let animate = part_writer!(&mut w.opacity) | ||
.transition(transitions::LINEAR.of(BuildCtx::get())); | ||
@ $w { | ||
on_disposed: move |_| { | ||
animate.run(); | ||
$w.write().opacity = 0.; | ||
let animate = animate.clone_watcher(); | ||
watch!($animate.is_running()) | ||
.distinct_until_changed() | ||
.filter(|v| !v) | ||
.take(1) | ||
.subscribe(move|v| { | ||
if !v { | ||
$w.write().keep_alive = false; | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters