diff --git a/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp b/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp index 55f214bdb0..d26d630907 100644 --- a/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp +++ b/Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021-2022, the SerenityOS developers. + * Copyright (c) 2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -273,6 +274,24 @@ Vector 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); diff --git a/Userland/Applications/SpaceAnalyzer/TreeMapWidget.h b/Userland/Applications/SpaceAnalyzer/TreeMapWidget.h index d28ac5bea0..f24406dd6e 100644 --- a/Userland/Applications/SpaceAnalyzer/TreeMapWidget.h +++ b/Userland/Applications/SpaceAnalyzer/TreeMapWidget.h @@ -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;