ladybird/Userland/DevTools/Profiler/TimelineContainer.cpp
Andreas Kling 4eb198baf3 Profiler: Limit the initial size of the timeline container
If there are a lot of process timeline tracks, we don't want to make the
window gigantic. So let's just put a limit on it.
2021-08-18 13:06:27 +02:00

75 lines
2.0 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "TimelineContainer.h"
#include "TimelineView.h"
#include <LibGUI/Layout.h>
namespace Profiler {
TimelineContainer::TimelineContainer(GUI::Widget& header_container, TimelineView& timeline_view)
{
set_should_hide_unnecessary_scrollbars(true);
m_header_container = header_container;
m_timeline_view = timeline_view;
add_child(header_container);
add_child(timeline_view);
header_container.move_to_back();
timeline_view.move_to_back();
update_widget_sizes();
update_widget_positions();
int initial_height = min(300, timeline_view.height() + frame_thickness() * 2);
set_fixed_height(initial_height);
m_timeline_view->on_scale_change = [this] {
update_widget_sizes();
update_widget_positions();
};
}
TimelineContainer::~TimelineContainer()
{
}
void TimelineContainer::did_scroll()
{
AbstractScrollableWidget::did_scroll();
update_widget_positions();
}
void TimelineContainer::update_widget_positions()
{
m_header_container->move_to(0, -vertical_scrollbar().value());
m_timeline_view->move_to(m_header_container->width() + -horizontal_scrollbar().value(), -vertical_scrollbar().value());
}
void TimelineContainer::update_widget_sizes()
{
{
m_timeline_view->do_layout();
auto preferred_size = m_timeline_view->layout()->preferred_size();
m_timeline_view->resize(preferred_size);
set_content_size(preferred_size);
}
{
m_header_container->do_layout();
auto preferred_size = m_header_container->layout()->preferred_size();
m_header_container->resize(preferred_size);
set_size_occupied_by_fixed_elements({ preferred_size.width(), 0 });
}
}
void TimelineContainer::resize_event(GUI::ResizeEvent& event)
{
AbstractScrollableWidget::resize_event(event);
update_widget_sizes();
update_widget_positions();
}
}