Skip to content

Commit

Permalink
ResourceGraph: Keep the graph inside the GUI::Frame rect
Browse files Browse the repository at this point in the history
Part of the graph was hidden under the frame rect, which had the effect
of delaying the appearance of spikes (well, all changes really.)
  • Loading branch information
awesomekling committed Aug 21, 2020
1 parent 30554c9 commit b36ac88
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions MenuApplets/ResourceGraph/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class GraphWidget final : public GUI::Frame {
C_OBJECT(GraphWidget);

public:
static constexpr size_t history_size = 30;

GraphWidget(GraphType graph_type, Optional<Gfx::Color> graph_color)
: m_graph_type(graph_type)
{
Expand Down Expand Up @@ -101,8 +103,8 @@ class GraphWidget final : public GUI::Frame {
auto rect = frame_inner_rect();
for (auto value : m_history) {
painter.draw_line(
{ i, rect.bottom() },
{ i, (int)(rect.height() - (value * (float)rect.height())) },
{ rect.x() + i, rect.bottom() },
{ rect.x() + i, (int)(rect.height() - (value * (float)rect.height())) },
m_graph_color);
++i;
}
Expand Down Expand Up @@ -156,7 +158,7 @@ class GraphWidget final : public GUI::Frame {

GraphType m_graph_type;
Gfx::Color m_graph_color;
CircularQueue<float, 30> m_history;
CircularQueue<float, history_size> m_history;
unsigned m_last_cpu_busy { 0 };
unsigned m_last_cpu_idle { 0 };
String m_tooltip;
Expand Down Expand Up @@ -211,7 +213,7 @@ int main(int argc, char** argv)
auto window = GUI::Window::construct();
window->set_title(name);
window->set_window_type(GUI::WindowType::MenuApplet);
window->resize(30, 16);
window->resize(GraphWidget::history_size + 2, 16);

window->set_main_widget<GraphWidget>(graph_type, graph_color);
window->show();
Expand Down

0 comments on commit b36ac88

Please sign in to comment.