Serenity Operating System
at master 63 lines 1.6 kB view raw
1/* 2 * Copyright (c) 2021, Nicholas Hollett <niax@niax.co.uk> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include "Profile.h" 10#include <AK/Function.h> 11#include <AK/Optional.h> 12#include <LibGUI/Model.h> 13#include <LibGUI/Painter.h> 14#include <LibGUI/ScrollableContainerWidget.h> 15#include <LibGUI/Widget.h> 16#include <LibGfx/Color.h> 17 18namespace Profiler { 19 20class FlameGraphView final : public GUI::AbstractScrollableWidget 21 , GUI::ModelClient { 22 C_OBJECT(FlameGraphView); 23 24public: 25 virtual ~FlameGraphView() override = default; 26 27 Function<void()> on_hover_change; 28 29 GUI::ModelIndex hovered_index() const; 30 31protected: 32 virtual void model_did_update(unsigned flags) override; 33 34 virtual void mousemove_event(GUI::MouseEvent&) override; 35 virtual void mousedown_event(GUI::MouseEvent&) override; 36 37 virtual void resize_event(GUI::ResizeEvent&) override; 38 virtual void paint_event(GUI::PaintEvent&) override; 39 40private: 41 explicit FlameGraphView(GUI::Model&, int text_column, int width_column); 42 43 struct StackBar { 44 GUI::ModelIndex const index; 45 Gfx::IntRect rect; 46 bool selected; 47 }; 48 49 DeprecatedString bar_label(StackBar const&) const; 50 void layout_bars(); 51 void layout_children(GUI::ModelIndex& parent, int depth, int left, int right, Vector<GUI::ModelIndex>& selected); 52 53 GUI::Model& m_model; 54 int m_text_column { -1 }; 55 int m_width_column { -1 }; 56 Vector<Gfx::Color> m_colors; 57 Vector<StackBar> m_bars; 58 StackBar* m_hovered_bar {}; 59 Vector<GUI::ModelIndex> m_selected_indexes; 60 Gfx::IntSize m_old_available_size {}; 61}; 62 63}