Skip to content

Commit

Permalink
SystemMonitor: Use system color themes for graph widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ccapitalK authored and awesomekling committed Feb 12, 2021
1 parent feb6656 commit e47af30
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Userland/Applications/SystemMonitor/GraphWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#include "GraphWidget.h"
#include <LibGUI/Painter.h>
#include <LibGfx/Font.h>
#include <LibGfx/Palette.h>
#include <LibGfx/Path.h>
#include <LibGfx/SystemTheme.h>

GraphWidget::GraphWidget()
{
Expand All @@ -49,7 +51,7 @@ void GraphWidget::paint_event(GUI::PaintEvent& event)
GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());
painter.add_clip_rect(frame_inner_rect());
painter.fill_rect(event.rect(), m_background_color);
painter.fill_rect(event.rect(), palette().base());

auto inner_rect = frame_inner_rect();
float scale = (float)inner_rect.height() / (float)m_max;
Expand Down
3 changes: 0 additions & 3 deletions Userland/Applications/SystemMonitor/GraphWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class GraphWidget final : public GUI::Frame {

void add_value(Vector<int, 1>&&);

void set_background_color(Color color) { m_background_color = color; }

struct ValueFormat {
Color line_color { Color::Transparent };
Color background_color { Color::Transparent };
Expand All @@ -63,7 +61,6 @@ class GraphWidget final : public GUI::Frame {
int m_max { 100 };
Vector<ValueFormat, 1> m_value_format;
CircularQueue<Vector<int, 1>, 4000> m_values;
Color m_background_color { Color::Black };
bool m_stack_values { false };

Vector<Gfx::IntPoint, 1> m_calculated_points;
Expand Down
19 changes: 7 additions & 12 deletions Userland/Applications/SystemMonitor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
auto graphs_container = GUI::LazyWidget::construct();

graphs_container->on_first_show = [](GUI::LazyWidget& self) {
const auto system_palette = GUI::Application::the()->palette();

self.set_fill_with_background_color(true);
self.set_background_role(ColorRole::Button);
self.set_layout<GUI::VerticalBoxLayout>();
Expand All @@ -586,17 +588,14 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
for (size_t i = 0; i < ProcessModel::the().cpus().size(); i++) {
auto& cpu_graph = cpu_graph_group_box.add<GraphWidget>();
cpu_graph.set_max(100);
cpu_graph.set_background_color(Color::White);
cpu_graph.set_value_format(0, {
.line_color = Color::Blue,
.background_color = Color::from_rgb(0xaaaaff),
.line_color = system_palette.syntax_preprocessor_statement(),
.text_formatter = [](int value) {
return String::formatted("Total: {}%", value);
},
});
cpu_graph.set_value_format(1, {
.line_color = Color::Red,
.background_color = Color::from_rgb(0xffaaaa),
.line_color = system_palette.syntax_preprocessor_value(),
.text_formatter = [](int value) {
return String::formatted("Kernel: {}%", value);
},
Expand All @@ -613,25 +612,21 @@ NonnullRefPtr<GUI::Widget> build_graphs_tab()
memory_graph_group_box.layout()->set_margins({ 6, 16, 6, 6 });
memory_graph_group_box.set_fixed_height(120);
auto& memory_graph = memory_graph_group_box.add<GraphWidget>();
memory_graph.set_background_color(Color::White);
memory_graph.set_stack_values(true);
memory_graph.set_value_format(0, {
.line_color = Color::from_rgb(0x619910),
.background_color = Color::from_rgb(0xbbffbb),
.line_color = system_palette.syntax_comment(),
.text_formatter = [&memory_graph](int value) {
return String::formatted("Committed: {} KiB", value);
},
});
memory_graph.set_value_format(1, {
.line_color = Color::Blue,
.background_color = Color::from_rgb(0xaaaaff),
.line_color = system_palette.syntax_preprocessor_statement(),
.text_formatter = [&memory_graph](int value) {
return String::formatted("Allocated: {} KiB", value);
},
});
memory_graph.set_value_format(2, {
.line_color = Color::Red,
.background_color = Color::from_rgb(0xffaaaa),
.line_color = system_palette.syntax_preprocessor_value(),
.text_formatter = [&memory_graph](int value) {
return String::formatted("Kernel heap: {} KiB", value);
},
Expand Down

0 comments on commit e47af30

Please sign in to comment.