Explorar el Código

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.
Sam Atkins hace 2 años
padre
commit
d8ceaf7870

+ 19 - 0
Userland/Applications/SpaceAnalyzer/TreeMapWidget.cpp

@@ -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);

+ 1 - 0
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;