-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,6 +4,10 @@ version = "0.1.0" | |
authors = ["Enso Team <[email protected]>"] | ||
edition = "2021" | ||
|
||
[features] | ||
tooltip = ["ensogl-tooltip"] | ||
|
||
[dependencies] | ||
enso-frp = { path = "../../../frp" } | ||
ensogl-core = { path = "../../core" } | ||
ensogl-tooltip = { optional = true, path = "../tooltip" } |
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,60 @@ | ||
use ensogl_core::prelude::*; | ||
|
||
use crate::Tooltip; | ||
|
||
use ensogl_core::application::tooltip::Style; | ||
use ensogl_core::application::Application; | ||
use ensogl_core::display; | ||
use frp::stream::EventOutput; | ||
use frp::HasOutput; | ||
|
||
|
||
|
||
/// Tooltip component that is only visible when hovering over another component. | ||
#[derive(Clone, CloneRef, Debug, Deref)] | ||
pub struct OnHover<T: Clone + CloneRef> { | ||
tooltip: Tooltip, | ||
#[deref] | ||
target: T, | ||
} | ||
|
||
impl<T: Clone + CloneRef + Hover> OnHover<T> { | ||
/// Constructor. | ||
pub fn new(app: &Application, label: String, target: T) -> Self { | ||
let tooltip = Tooltip::new(app); | ||
Self { tooltip, target }.init(app, label) | ||
} | ||
|
||
fn init(self, app: &Application, label: String) -> Self { | ||
app.display.default_scene.add_child(&self.tooltip); | ||
let network = &self.tooltip.frp.network; | ||
frp::extend! { network | ||
let is_hovered = self.target.is_hovered(); | ||
tooltip <- is_hovered.map(move |is_hovered| { | ||
if *is_hovered { | ||
Style::set_label(label.clone()) | ||
} else { | ||
Style::unset_label() | ||
} | ||
}); | ||
app.frp.set_tooltip <+ tooltip; | ||
} | ||
self | ||
} | ||
} | ||
|
||
impl<T: Clone + CloneRef + display::Object> display::Object for OnHover<T> { | ||
fn display_object(&self) -> &display::object::Instance { | ||
self.target.display_object() | ||
} | ||
} | ||
|
||
|
||
pub trait Hover | ||
where | ||
Self::Output: EventOutput, | ||
Self::Output: HasOutput<Output = bool>, { | ||
type Output; | ||
|
||
fn is_hovered(&self) -> Self::Output; | ||
} |
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