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

Profiler: Allow scaling the timeline with Ctrl+MouseWheel :^)

This commit is contained in:
Andreas Kling 2021-05-22 23:20:31 +02:00
parent 3dfc3e362b
commit 62819df713
5 changed files with 33 additions and 1 deletions

View file

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

View file

@ -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()) {

View file

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

View file

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

View file

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