fix tooltips not disappearing, clippy

This commit is contained in:
Aleksander
2025-11-26 22:01:19 +01:00
parent d5c5d06b3a
commit 85eab33c94
10 changed files with 131 additions and 74 deletions

View File

@@ -1,6 +1,6 @@
use crate::{
animation::{Animation, AnimationEasing},
components::{self, tooltip::ComponentTooltip, Component, ComponentBase, ComponentTrait, RefreshData},
components::{self, Component, ComponentBase, ComponentTrait, RefreshData, tooltip::ComponentTooltip},
drawing::{self, Boundary, Color},
event::{CallbackDataCommon, EventListenerCollection, EventListenerID, EventListenerKind},
i18n::Translation,
@@ -10,15 +10,15 @@ use crate::{
util::centered_matrix,
},
widget::{
self, ConstructEssentials, EventResult, WidgetData,
label::{WidgetLabel, WidgetLabelParams},
rectangle::{WidgetRectangle, WidgetRectangleParams},
util::WLength,
ConstructEssentials, EventResult, WidgetData,
},
};
use glam::{Mat4, Vec3};
use std::{cell::RefCell, rc::Rc};
use taffy::{prelude::length, AlignItems, JustifyContent};
use taffy::{AlignItems, JustifyContent, prelude::length};
pub struct Params {
pub text: Option<Translation>, // if unset, label will not be populated
@@ -91,8 +91,19 @@ impl ComponentTrait for ComponentButton {
&mut self.base
}
fn refresh(&self, _data: &mut RefreshData) {
fn refresh(&self, data: &mut RefreshData) {
// nothing to do
let mut state = self.state.borrow_mut();
if state.active_tooltip.is_some() {
if let Some(node_id) = data.common.state.nodes.get(self.base.get_id()) {
if !widget::is_node_visible(&data.common.state.tree, *node_id) {
state.active_tooltip = None; // destroy the tooltip, this button is now hidden
}
} else {
debug_assert!(false);
}
}
}
}
@@ -472,6 +483,6 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
let button = Rc::new(ComponentButton { base, data, state });
ess.layout.defer_component_refresh(Component(button.clone()));
ess.layout.register_component_refresh(Component(button.clone()));
Ok((root, button))
}

View File

@@ -1,4 +1,5 @@
use std::rc::Rc;
use std::hash::Hash;
use std::{hash::Hasher, rc::Rc};
use crate::{
any::AnyTrait,
@@ -54,3 +55,21 @@ impl Component {
unsafe { Ok(Rc::from_raw(Rc::into_raw(self.0.clone()).cast())) }
}
}
// these hash/eq impls are required in case we want to do something like HashSet<Component> for convenience reasons.
// hash by address
impl Hash for Component {
fn hash<H: Hasher>(&self, state: &mut H) {
std::ptr::hash(&raw const self.0, state);
}
}
// match by address
impl PartialEq for Component {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(&raw const self.0, &raw const other.0)
}
}
impl Eq for Component {}