From d55c130df5a3137f044220a6ee18a9e4e246bddc Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Fri, 14 Jan 2022 00:55:58 +0200 Subject: [PATCH] SystemMonitor: Split multi-core CPU usage graphs into multiple rows This looks much nicer than the current cramped single-row solution. --- Userland/Applications/SystemMonitor/main.cpp | 47 ++++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index c2c852e241b..719a8defdf3 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -668,26 +668,35 @@ NonnullRefPtr build_performance_tab() graphs_container->layout()->set_margins(4); auto& cpu_graph_group_box = graphs_container->add("CPU usage"); - cpu_graph_group_box.set_layout(); - cpu_graph_group_box.layout()->set_margins(6); - cpu_graph_group_box.set_fixed_height(120); + cpu_graph_group_box.set_layout(); + + static constexpr size_t cpu_graphs_per_row = 4; + auto cpu_graph_rows = ceil_div(ProcessModel::the().cpus().size(), cpu_graphs_per_row); + cpu_graph_group_box.set_fixed_height(120u * cpu_graph_rows); + Vector cpu_graphs; - for (size_t i = 0; i < ProcessModel::the().cpus().size(); i++) { - auto& cpu_graph = cpu_graph_group_box.add(); - cpu_graph.set_max(100); - cpu_graph.set_value_format(0, { - .graph_color_role = ColorRole::SyntaxPreprocessorStatement, - .text_formatter = [](int value) { - return String::formatted("Total: {}%", value); - }, - }); - cpu_graph.set_value_format(1, { - .graph_color_role = ColorRole::SyntaxPreprocessorValue, - .text_formatter = [](int value) { - return String::formatted("Kernel: {}%", value); - }, - }); - cpu_graphs.append(cpu_graph); + for (auto row = 0u; row < cpu_graph_rows; ++row) { + auto& cpu_graph_row = cpu_graph_group_box.add(); + cpu_graph_row.set_layout(); + cpu_graph_row.layout()->set_margins(6); + cpu_graph_row.set_fixed_height(108); + for (auto i = 0u; i < cpu_graphs_per_row; ++i) { + auto& cpu_graph = cpu_graph_row.add(); + cpu_graph.set_max(100); + cpu_graph.set_value_format(0, { + .graph_color_role = ColorRole::SyntaxPreprocessorStatement, + .text_formatter = [](int value) { + return String::formatted("Total: {}%", value); + }, + }); + cpu_graph.set_value_format(1, { + .graph_color_role = ColorRole::SyntaxPreprocessorValue, + .text_formatter = [](int value) { + return String::formatted("Kernel: {}%", value); + }, + }); + cpu_graphs.append(cpu_graph); + } } ProcessModel::the().on_cpu_info_change = [cpu_graphs](const NonnullOwnPtrVector& cpus) { float sum_cpu = 0;