diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-22 23:20:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-22 23:20:31 +0200 |
commit | 62819df713bf8f1671e345a84307bae617a51e46 (patch) | |
tree | 98c1a144cf348dddd99c2aafc0ba5c7858726db0 /Userland/DevTools | |
parent | 3dfc3e362bdf9b8b6dd5d6219296f718dacf4403 (diff) | |
download | serenity-62819df713bf8f1671e345a84307bae617a51e46.zip |
Profiler: Allow scaling the timeline with Ctrl+MouseWheel :^)
Diffstat (limited to 'Userland/DevTools')
-rw-r--r-- | Userland/DevTools/Profiler/TimelineContainer.cpp | 5 | ||||
-rw-r--r-- | Userland/DevTools/Profiler/TimelineTrack.cpp | 7 | ||||
-rw-r--r-- | Userland/DevTools/Profiler/TimelineTrack.h | 2 | ||||
-rw-r--r-- | Userland/DevTools/Profiler/TimelineView.cpp | 15 | ||||
-rw-r--r-- | Userland/DevTools/Profiler/TimelineView.h | 5 |
5 files changed, 33 insertions, 1 deletions
diff --git a/Userland/DevTools/Profiler/TimelineContainer.cpp b/Userland/DevTools/Profiler/TimelineContainer.cpp index d00a2b4ee2..b56303ec3c 100644 --- a/Userland/DevTools/Profiler/TimelineContainer.cpp +++ b/Userland/DevTools/Profiler/TimelineContainer.cpp @@ -20,6 +20,11 @@ TimelineContainer::TimelineContainer(GUI::Widget& header_container, TimelineView timeline_view.move_to_back(); update_widget_sizes(); update_widget_positions(); + + m_timeline_view->on_scale_change = [this] { + update_widget_positions(); + update_widget_sizes(); + }; } TimelineContainer::~TimelineContainer() diff --git a/Userland/DevTools/Profiler/TimelineTrack.cpp b/Userland/DevTools/Profiler/TimelineTrack.cpp index e04934e0d4..f19a6c91e5 100644 --- a/Userland/DevTools/Profiler/TimelineTrack.cpp +++ b/Userland/DevTools/Profiler/TimelineTrack.cpp @@ -22,7 +22,7 @@ TimelineTrack::TimelineTrack(TimelineView const& view, Profile const& profile, P set_fill_with_background_color(true); set_background_role(Gfx::ColorRole::Base); set_fixed_height(40); - set_fixed_width(m_profile.length_in_ms() / 10); + set_scale(view.scale()); set_frame_thickness(1); } @@ -30,6 +30,11 @@ TimelineTrack::~TimelineTrack() { } +void TimelineTrack::set_scale(float scale) +{ + set_fixed_width(m_profile.length_in_ms() / scale); +} + void TimelineTrack::event(Core::Event& event) { switch (event.type()) { diff --git a/Userland/DevTools/Profiler/TimelineTrack.h b/Userland/DevTools/Profiler/TimelineTrack.h index 0fca8fea5e..723b4cae5d 100644 --- a/Userland/DevTools/Profiler/TimelineTrack.h +++ b/Userland/DevTools/Profiler/TimelineTrack.h @@ -20,6 +20,8 @@ class TimelineTrack final : public GUI::Frame { public: virtual ~TimelineTrack() override; + void set_scale(float); + private: virtual void event(Core::Event&) override; virtual void paint_event(GUI::PaintEvent&) override; diff --git a/Userland/DevTools/Profiler/TimelineView.cpp b/Userland/DevTools/Profiler/TimelineView.cpp index 7a36abd663..60cf4648a7 100644 --- a/Userland/DevTools/Profiler/TimelineView.cpp +++ b/Userland/DevTools/Profiler/TimelineView.cpp @@ -6,6 +6,7 @@ #include "TimelineView.h" #include "Profile.h" +#include "TimelineTrack.h" #include <LibGUI/BoxLayout.h> namespace Profiler { @@ -62,4 +63,18 @@ void TimelineView::mouseup_event(GUI::MouseEvent& event) m_profile.clear_timestamp_filter_range(); } +void TimelineView::mousewheel_event(GUI::MouseEvent& event) +{ + if (event.modifiers() == Mod_Ctrl) { + event.accept(); + m_scale += event.wheel_delta(); + m_scale = clamp(m_scale, 1.0f, 100.0f); + for_each_child_of_type<TimelineTrack>([&](auto& track) { + track.set_scale(m_scale); + return IterationDecision::Continue; + }); + on_scale_change(); + } +} + } diff --git a/Userland/DevTools/Profiler/TimelineView.h b/Userland/DevTools/Profiler/TimelineView.h index 9eed2ff7d1..97b0943c23 100644 --- a/Userland/DevTools/Profiler/TimelineView.h +++ b/Userland/DevTools/Profiler/TimelineView.h @@ -20,6 +20,9 @@ public: virtual ~TimelineView() override; Function<void()> on_selection_change; + Function<void()> on_scale_change; + + float scale() const { return m_scale; } bool is_selecting() const { return m_selecting; } u64 select_start_time() const { return m_select_start_time; } @@ -65,6 +68,7 @@ private: virtual void mousedown_event(GUI::MouseEvent&) override; virtual void mousemove_event(GUI::MouseEvent&) override; virtual void mouseup_event(GUI::MouseEvent&) override; + virtual void mousewheel_event(GUI::MouseEvent&) override; explicit TimelineView(Profile&); @@ -75,6 +79,7 @@ private: u64 m_select_start_time { 0 }; u64 m_select_end_time { 0 }; u64 m_hover_time { 0 }; + float m_scale { 10 }; }; } |