refactor(tooltip): add extra message parameter to tooltips
This commit is contained in:
parent
9821c92f59
commit
5072cc3045
3 changed files with 38 additions and 34 deletions
|
|
@ -117,10 +117,9 @@ impl cosmic::Application for Window {
|
|||
}
|
||||
|
||||
Message::Surface(a) => {
|
||||
dbg!("hi i got an action...");
|
||||
return cosmic::task::message(cosmic::Action::Cosmic(cosmic::app::Action::Surface(
|
||||
a,
|
||||
)));
|
||||
return cosmic::task::message(cosmic::Action::Cosmic(
|
||||
cosmic::app::Action::Surface(a),
|
||||
));
|
||||
}
|
||||
Message::Selected(i) => {
|
||||
self.selected = Some(i);
|
||||
|
|
@ -195,11 +194,12 @@ impl cosmic::Application for Window {
|
|||
},
|
||||
);
|
||||
|
||||
Element::from(
|
||||
self.core
|
||||
.applet
|
||||
.applet_tooltip(btn, "test", self.popup.is_some(), |a| Message::Surface(a)),
|
||||
)
|
||||
Element::from(self.core.applet.applet_tooltip::<Message>(
|
||||
btn,
|
||||
"test",
|
||||
self.popup.is_some(),
|
||||
|a| Message::Surface(a),
|
||||
))
|
||||
}
|
||||
|
||||
fn view_window(&self, _id: Id) -> Element<Message> {
|
||||
|
|
@ -209,13 +209,4 @@ impl cosmic::Application for Window {
|
|||
fn style(&self) -> Option<cosmic::iced_runtime::Appearance> {
|
||||
Some(cosmic::applet::style())
|
||||
}
|
||||
|
||||
fn subscription(&self) -> cosmic::iced::Subscription<Message> {
|
||||
listen_with(|e, status, id| {
|
||||
if matches!(e, iced::event::Event::Keyboard(_)) {
|
||||
dbg!(e, id);
|
||||
}
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,13 +225,13 @@ impl Context {
|
|||
tooltip: impl Into<Cow<'static, str>>,
|
||||
has_popup: bool,
|
||||
on_surface_action: impl Fn(crate::surface::Action) -> Message + 'static,
|
||||
) -> crate::widget::wayland::tooltip::widget::Tooltip<'a, Message> {
|
||||
) -> crate::widget::wayland::tooltip::widget::Tooltip<'a, Message, Message> {
|
||||
let window_id = *TOOLTIP_WINDOW_ID;
|
||||
let subsurface_id = TOOLTIP_ID.clone();
|
||||
let anchor = self.anchor;
|
||||
let tooltip = tooltip.into();
|
||||
|
||||
crate::widget::wayland::tooltip::widget::Tooltip::<'a, Message>::new(
|
||||
crate::widget::wayland::tooltip::widget::Tooltip::<'a, Message, Message>::new(
|
||||
content,
|
||||
(!has_popup).then_some(move |bounds: Rectangle| {
|
||||
let window_id = window_id;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ enum Variant<Message> {
|
|||
/// A generic button which emits a message when pressed.
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[must_use]
|
||||
pub struct Tooltip<'a, Message> {
|
||||
pub struct Tooltip<'a, Message, TopLevelMessage> {
|
||||
id: Id,
|
||||
#[cfg(feature = "a11y")]
|
||||
name: Option<std::borrow::Cow<'a, str>>,
|
||||
|
|
@ -64,10 +64,12 @@ pub struct Tooltip<'a, Message> {
|
|||
+ 'static,
|
||||
>,
|
||||
>,
|
||||
view: Arc<dyn Fn() -> crate::Element<'static, Message> + Send + Sync + 'static>,
|
||||
view: Arc<
|
||||
dyn Fn() -> crate::Element<'static, crate::Action<TopLevelMessage>> + Send + Sync + 'static,
|
||||
>,
|
||||
}
|
||||
|
||||
impl<'a, Message> Tooltip<'a, Message> {
|
||||
impl<'a, Message, TopLevelMessage> Tooltip<'a, Message, TopLevelMessage> {
|
||||
/// Creates a new [`Tooltip`] with the given content.
|
||||
pub fn new(
|
||||
content: impl Into<crate::Element<'a, Message>>,
|
||||
|
|
@ -77,7 +79,10 @@ impl<'a, Message> Tooltip<'a, Message> {
|
|||
+ Sync
|
||||
+ 'static,
|
||||
>,
|
||||
view: impl Fn() -> crate::Element<'static, Message> + Send + Sync + 'static,
|
||||
view: impl Fn() -> crate::Element<'static, crate::Action<TopLevelMessage>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
on_leave: Message,
|
||||
on_surface_action: impl Fn(crate::surface::Action) -> Message + 'static,
|
||||
) -> Self {
|
||||
|
|
@ -182,8 +187,8 @@ impl<'a, Message> Tooltip<'a, Message> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Message: 'static + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||
for Tooltip<'a, Message>
|
||||
impl<'a, Message: 'static + Clone, TopLevelMessage: 'static + Clone>
|
||||
Widget<Message, crate::Theme, crate::Renderer> for Tooltip<'a, Message, TopLevelMessage>
|
||||
{
|
||||
fn tag(&self) -> tree::Tag {
|
||||
tree::Tag::of::<State>()
|
||||
|
|
@ -381,8 +386,10 @@ impl<'a, Message: 'static + Clone> Widget<Message, crate::Theme, crate::Renderer
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, Message: Clone + 'static> From<Tooltip<'a, Message>> for crate::Element<'a, Message> {
|
||||
fn from(button: Tooltip<'a, Message>) -> Self {
|
||||
impl<'a, Message: Clone + 'static, TopLevelMessage: Clone + 'static>
|
||||
From<Tooltip<'a, Message, TopLevelMessage>> for crate::Element<'a, Message>
|
||||
{
|
||||
fn from(button: Tooltip<'a, Message, TopLevelMessage>) -> Self {
|
||||
Self::new(button)
|
||||
}
|
||||
}
|
||||
|
|
@ -405,7 +412,7 @@ impl State {
|
|||
/// Processes the given [`Event`] and updates the [`State`] of a [`Tooltip`]
|
||||
/// accordingly.
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn update<'a, Message: Clone + 'static>(
|
||||
pub fn update<'a, Message: Clone + 'static, TopLevelMessage: Clone + 'static>(
|
||||
_id: Id,
|
||||
event: Event,
|
||||
layout: Layout<'_>,
|
||||
|
|
@ -419,7 +426,9 @@ pub fn update<'a, Message: Clone + 'static>(
|
|||
+ 'static,
|
||||
>,
|
||||
>,
|
||||
view: &Arc<dyn Fn() -> crate::Element<'static, Message> + Send + Sync + 'static>,
|
||||
view: &Arc<
|
||||
dyn Fn() -> crate::Element<'static, crate::Action<TopLevelMessage>> + Send + Sync + 'static,
|
||||
>,
|
||||
delay: Option<Duration>,
|
||||
on_leave: &Message,
|
||||
on_surface_action: &dyn Fn(crate::surface::Action) -> Message,
|
||||
|
|
@ -493,8 +502,10 @@ pub fn update<'a, Message: Clone + 'static>(
|
|||
Arc::new(boxed),
|
||||
Some({
|
||||
let boxed: Box<
|
||||
dyn Fn() -> crate::Element<'static, Message>
|
||||
+ Send
|
||||
dyn Fn() -> crate::Element<
|
||||
'static,
|
||||
crate::Action<TopLevelMessage>,
|
||||
> + Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
> = Box::new(move || view());
|
||||
|
|
@ -524,8 +535,10 @@ pub fn update<'a, Message: Clone + 'static>(
|
|||
Arc::new(boxed),
|
||||
Some({
|
||||
let boxed: Box<
|
||||
dyn Fn() -> crate::Element<'static, Message>
|
||||
+ Send
|
||||
dyn Fn() -> crate::Element<
|
||||
'static,
|
||||
crate::Action<TopLevelMessage>,
|
||||
> + Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
> = Box::new(move || view());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue