summaryrefslogtreecommitdiff
path: root/Userland/DevTools/Profiler/TimelineContainer.cpp
blob: dd93c6e83891324f976835a3d037c5a52c717654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * 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();
}

}