Skip to content

Commit 33f86db

Browse files
authored
SystemCPUView: code style cleanup (#460)
* SystemCPUView: code style cleanup * Use overlay and box as appropriate
1 parent c82f6e8 commit 33f86db

File tree

2 files changed

+57
-55
lines changed

2 files changed

+57
-55
lines changed

src/Views/SystemView/SystemCPUView.vala

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,7 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource {
1212
private LabelRoundy cpu_frequency_label;
1313
private LabelRoundy cpu_temperature_label;
1414

15-
private Gtk.Grid grid_temperature_info = new Gtk.Grid ();
16-
17-
private Gee.ArrayList<Gtk.Label ? > core_label_list;
18-
19-
construct {
20-
core_label_list = new Gee.ArrayList<Gtk.Label> ();
21-
22-
cpu_frequency_label = new LabelRoundy (_("Frequency"));
23-
cpu_frequency_label.margin = 6;
24-
cpu_frequency_label.margin_top = 2;
25-
26-
cpu_temperature_label = new LabelRoundy (_("Temperature"));
27-
cpu_temperature_label.margin = 6;
28-
cpu_temperature_label.margin_top = 2;
29-
30-
cpu_frequency_chart = new Chart (1);
31-
cpu_frequency_chart.set_serie_color (0, Utils.Colors.get_rgba_color (Utils.Colors.LIME_500));
32-
cpu_frequency_chart.height_request = -1;
33-
cpu_frequency_chart.config.y_axis.fixed_max = 5.0;
34-
35-
var grid_frequency_info = new Gtk.Grid ();
36-
grid_frequency_info.attach (cpu_frequency_label, 0, 0, 1, 1);
37-
grid_frequency_info.attach (cpu_frequency_chart, 0, 0, 1, 1);
38-
39-
grid_temperature_info.attach (cpu_temperature_label, 0, 0, 1, 1);
40-
41-
42-
43-
var smol_charts_container = new Gtk.Grid ();
44-
smol_charts_container.width_request = 200;
45-
smol_charts_container.hexpand = false;
46-
smol_charts_container.halign = Gtk.Align.START;
47-
smol_charts_container.attach (grid_frequency_info, 0, 0, 1, 1);
48-
smol_charts_container.attach (grid_temperature_info, 0, 1, 1, 1);
49-
smol_charts_container.row_spacing = 6;
50-
smol_charts_container.margin_start = 6;
51-
52-
add_charts_container (smol_charts_container);
53-
}
15+
private Gee.ArrayList<Gtk.Label ?> core_label_list;
5416

5517
public SystemCPUView (CPU _cpu) {
5618
cpu = _cpu;
@@ -61,33 +23,68 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource {
6123
cpu_utilization_chart = new Chart (cpu.core_list.size, MonitorApp.settings.get_boolean ("smooth-lines-state"), 1.0);
6224
cpu_utilization_chart.config.y_axis.tick_interval = 100;
6325
cpu_utilization_chart.config.y_axis.fixed_max = 100.0 * cpu.core_list.size;
64-
set_main_chart (cpu_utilization_chart);
6526

27+
set_main_chart (cpu_utilization_chart);
6628
set_main_chart_overlay (grid_core_labels ());
29+
}
6730

68-
cpu_temperature_chart = new Chart (1);
31+
construct {
32+
cpu_temperature_chart = new Chart (1) {
33+
height_request = -1
34+
};
6935
cpu_temperature_chart.set_serie_color (0, Utils.Colors.get_rgba_color (Utils.Colors.LIME_500));
7036

71-
cpu_temperature_chart.height_request = -1;
72-
grid_temperature_info.attach (cpu_temperature_chart, 0, 0, 1, 1);
37+
core_label_list = new Gee.ArrayList<Gtk.Label> ();
38+
39+
cpu_frequency_label = new LabelRoundy (_("Frequency")) {
40+
margin_top = 2,
41+
margin_end = 6,
42+
margin_bottom = 6,
43+
margin_start = 6
44+
};
45+
46+
cpu_temperature_label = new LabelRoundy (_("Temperature")) {
47+
margin_top = 2,
48+
margin_end = 6,
49+
margin_bottom = 6,
50+
margin_start = 6
51+
};
52+
53+
cpu_frequency_chart = new Chart (1) {
54+
height_request = -1
55+
};
56+
cpu_frequency_chart.set_serie_color (0, Utils.Colors.get_rgba_color (Utils.Colors.LIME_500));
57+
cpu_frequency_chart.config.y_axis.fixed_max = 5.0;
58+
59+
var freq_info_overlay = new Gtk.Overlay () {
60+
child = cpu_frequency_chart
61+
};
62+
freq_info_overlay.add_overlay (cpu_frequency_label);
63+
64+
var temp_info_overlay = new Gtk.Overlay () {
65+
child = cpu_temperature_chart
66+
};
67+
temp_info_overlay.add_overlay (cpu_temperature_label);
68+
69+
var small_charts_box = new Gtk.Box (VERTICAL, 6) {
70+
hexpand = false,
71+
width_request = 200
72+
};
73+
small_charts_box.add (freq_info_overlay);
74+
small_charts_box.add (temp_info_overlay);
75+
76+
add_charts_container (small_charts_box);
7377
}
7478

7579
public void update () {
7680
cpu_frequency_chart.update (0, cpu.frequency);
7781

78-
// int temperature_index = 0;
79-
// foreach (var temperature in cpu.paths_temperatures.values) {
80-
// debug (temperature.input);
81-
// cpu_temperature_chart.update (temperature_index, int.parse (temperature.input) / 1000);
82-
// temperature_index++;
83-
// }]
8482
cpu_temperature_chart.update (0, cpu.temperature_mean);
8583
cpu_temperature_label.text = ("%.2f %s").printf (cpu.temperature_mean, _(""));
8684

8785
double cpu_prev_util = 0;
8886

8987
for (int i = 0; i < cpu.core_list.size; i++) {
90-
9188
// must reverse to render layers in the right order
9289
int reversed_i = cpu.core_list.size - i - 1;
9390

@@ -109,12 +106,12 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource {
109106
core_label_list[i].get_style_context ().remove_class ("core_badge-strong-warning");
110107
core_label_list[i].get_style_context ().remove_class ("core_badge-critical-warning");
111108

112-
113109
if (core_percentage > 75.0) {
114110
core_label_list[i].get_style_context ().add_class ("core_badge-mild-warning");
115111
core_label_list[i].get_style_context ().remove_class ("core_badge-strong-warning");
116112
core_label_list[i].get_style_context ().remove_class ("core_badge-critical-warning");
117113
}
114+
118115
if (core_percentage > 85.0) {
119116
core_label_list[i].get_style_context ().add_class ("core_badge-strong-warning");
120117
core_label_list[i].get_style_context ().remove_class ("core_badge-mild-warning");
@@ -127,6 +124,7 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource {
127124
core_label_list[i].get_style_context ().remove_class ("core_badge-strong-warning");
128125
}
129126
}
127+
130128
label_vertical_main_metric = ("%d%%").printf (cpu.percentage);
131129
cpu_frequency_label.text = ("%.2f %s").printf (cpu.frequency, _("GHz"));
132130
}
@@ -135,14 +133,18 @@ public class Monitor.SystemCPUView : Monitor.WidgetResource {
135133
Gtk.Grid grid = new Gtk.Grid () {
136134
column_spacing = 8,
137135
row_spacing = 4,
138-
margin = 6
136+
margin_top = 6,
137+
margin_bottom = 6,
138+
margin_start = 6,
139+
margin_end = 6,
139140
};
140141

141142
int column = 0;
142143
int row = 0;
143144
for (int i = 0; i < cpu.core_list.size; i++) {
144-
var core_label = new Gtk.Label (Utils.NO_DATA);
145-
core_label.set_width_chars (4);
145+
var core_label = new Gtk.Label (Utils.NO_DATA) {
146+
width_chars = 4
147+
};
146148
core_label.get_style_context ().add_class ("core_badge");
147149
// core_label.set_text (Utils.NO_DATA);
148150
core_label_list.add (core_label);

src/Widgets/WidgetResource/WidgetResource.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Monitor.WidgetResource : Gtk.Box {
2121
}
2222
}
2323

24-
private Gtk.Box charts_container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
24+
private Gtk.Box charts_container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
2525

2626
private Gtk.Grid grid_main_chart_container;
2727
private Gtk.Grid grid_main_onchart_info_container;

0 commit comments

Comments
 (0)