1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

SpaceAnalyzer: Add a tooltip for the hovered tree node

Many of the nodes are visually too small to show their full name and
file size, so this makes that information visible.
This commit is contained in:
Sam Atkins 2022-12-09 21:43:04 +00:00 committed by Linus Groh
parent 6d64e650f1
commit d8ceaf7870
2 changed files with 20 additions and 0 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021-2022, the SerenityOS developers.
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -273,6 +274,24 @@ Vector<int> TreeMapWidget::path_to_position(Gfx::IntPoint position)
return path;
}
void TreeMapWidget::mousemove_event(GUI::MouseEvent& event)
{
auto* node = path_node(m_viewpoint);
if (!node) {
set_tooltip({});
return;
}
auto* hovered_node = node;
lay_out_children(*node, frame_inner_rect(), m_viewpoint, [&](TreeMapNode const&, int index, Gfx::IntRect const& rect, Gfx::IntRect const&, int, HasLabel, IsRemainder is_remainder) {
if (is_remainder == IsRemainder::No && rect.contains(event.position())) {
hovered_node = &hovered_node->child_at(index);
}
});
set_tooltip(DeprecatedString::formatted("{}\n{}", hovered_node->name(), human_readable_size(hovered_node->area())));
}
void TreeMapWidget::mousedown_event(GUI::MouseEvent& event)
{
TreeMapNode const* node = path_node(m_viewpoint);

View file

@ -43,6 +43,7 @@ public:
private:
TreeMapWidget() = default;
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void doubleclick_event(GUI::MouseEvent&) override;
virtual void mousewheel_event(GUI::MouseEvent&) override;