Redesign the page: a grid of panels with an instrument-panel look

Every colour, size, spacing and font now lives in crates/ui/src/theme.rs.
At 1100 px and wider the page is three columns of panels, at 700 px two,
below that one: a toolbar with the range as one segmented control, a
headline panel, six stat cards in one row, three panels side by side,
then Over time beside Speed, then Raw counters as key/value lines.

The type is Inter and JetBrains Mono (SIL Open Font License, licence
files beside the fonts). Tables size their columns to what they hold,
charts keep their time labels inside the plot and tint unrecorded time,
and the hit-rate bars leave the language table where there is no room.

Behaviour is unchanged: ranges, refresh, theme switch, Copy summary,
Export JSON, Zero stats with its question, the language filter and the
remembered settings work as before.
This commit is contained in:
swaits committed 2026-11-28 13:31:51 -07:00
1 parent 72fcf8f976
commit a7d836d45a
19 files changed
+2214 -979

No files matched your search

+521 -294
View File
@@ -6,6 +6,7 @@ use eframe::egui;
use sccache_dash_api::{Range, View};
use crate::fmt;
use crate::theme;
use crate::{cards, extras, net, overtime, problems, raw, speed, style, where_went};
/// Refresh intervals offered, in seconds; zero means off.
@@ -86,12 +87,7 @@ impl Dashboard {
};
let ctx = &cc.egui_ctx;
ctx.set_theme(dashboard.theme.preference());
ctx.all_styles_mut(|style| {
style
.text_styles
.insert(egui::TextStyle::Small, egui::FontId::proportional(11.5));
style.spacing.item_spacing = egui::vec2(8.0, 4.0);
});
theme::install(ctx);
dashboard
}
@@ -179,6 +175,10 @@ impl eframe::App for Dashboard {
}
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
// The whole window in the page colour first: the toolbar sits outside the
// scrolling panel, and the browser's own canvas colour must never show.
ui.painter()
.rect_filled(ui.max_rect(), 0.0, theme::ctx(ui.ctx()).page);
controls(self, ui);
if let (Some(view), Some(error)) = (&self.view, &self.error) {
lost_contact(
@@ -188,23 +188,31 @@ impl eframe::App for Dashboard {
ui.available_rect_before_wrap().width(),
);
}
egui::CentralPanel::default().show(ui, |ui| {
egui::ScrollArea::vertical()
.auto_shrink([false; 2])
.show(ui, |ui| {
ui.add_space(8.0);
let Self {
range,
view,
hidden_languages,
..
} = self;
match view {
None => waiting(ui, self.error.as_deref(), self.refresh_secs),
Some(view) => page(ui, view, *range, hidden_languages),
}
});
});
egui::CentralPanel::default()
.frame(
egui::Frame::NONE
.fill(theme::ctx(ui.ctx()).page)
.inner_margin(egui::Margin::symmetric(
theme::space::PAGE_MARGIN as i8,
theme::space::PAGE_MARGIN as i8,
)),
)
.show(ui, |ui| {
egui::ScrollArea::vertical()
.auto_shrink([false; 2])
.show(ui, |ui| {
let Self {
range,
view,
hidden_languages,
..
} = self;
match view {
None => waiting(ui, self.error.as_deref(), self.refresh_secs),
Some(view) => page(ui, view, *range, hidden_languages),
}
});
});
if self.asking_zero {
zero_question(self, ui.ctx());
@@ -237,114 +245,176 @@ fn remembered<T: serde::de::DeserializeOwned>(
storage.and_then(|storage| eframe::get_value(storage, key))
}
/// The row of controls that stays at the top of the page.
fn theme_labels() -> [&'static str; 3] {
ThemeChoice::ALL.map(|theme| theme.name())
}
/// About how wide the row of actions is, from the width of its labels.
fn actions_width(ui: &egui::Ui) -> f32 {
let medium = theme::medium(theme::px::BODY);
let label = |text: &str| style::text_width(ui, text, medium.clone()) + 22.0;
let gaps = theme::space::PANEL_GAP;
label(&fmt::refresh_label(30)) + label("Refresh")
+ theme_labels().iter().map(|text| style::text_width(ui, text, medium.clone()) + 2.0 * theme::space::CONTROL_PAD).sum::<f32>()
+ label("Copy summary") + label("Export JSON") + label("Zero stats")
+ theme::space::TOOLBAR_NOTE_WIDTH
+ gaps * 7.0
}
/// The row of controls that stays at the top of the page: the range as one
/// segmented control at the left; the actions at the right, on their own lines
/// where there is no room beside the range.
fn controls(dashboard: &mut Dashboard, ui: &mut egui::Ui) {
let ctx = ui.ctx().clone();
let now = Dashboard::now(&ctx);
egui::Panel::top("controls").show(ui, |ui| {
ui.add_space(6.0);
ui.horizontal_wrapped(|ui| {
for range in Range::ALL {
if ui
.add(egui::Button::selectable(
dashboard.range == range,
range.code(),
))
.clicked()
{
dashboard.range = range;
dashboard.settings_changed = true;
dashboard.send(&ctx, Ask::View);
}
}
let gap = theme::space::PANEL_GAP;
let margin = theme::space::PAGE_MARGIN;
ui.add_space(margin);
let width = ui.available_rect_before_wrap().width() - 2.0 * margin;
let medium = theme::medium(theme::px::BODY);
let range_width: f32 = Range::ALL
.iter()
.map(|range| style::text_width(ui, range.code(), medium.clone()) + 2.0 * theme::space::CONTROL_PAD)
.sum();
let beside = width >= theme::layout::TOOLBAR_TWO_LINES_BELOW;
let one_line = beside && range_width + gap + actions_width(ui) <= width;
let phone = width + 2.0 * theme::space::PAGE_MARGIN < theme::layout::TWO_COLUMNS_FROM;
ui.add_space(8.0);
let mut refresh_secs = dashboard.refresh_secs;
egui::ComboBox::from_id_salt("refresh")
.selected_text(fmt::refresh_label(refresh_secs))
.show_ui(ui, |ui| {
for secs in REFRESH_CHOICES {
ui.selectable_value(&mut refresh_secs, secs, fmt::refresh_label(secs));
}
});
if refresh_secs != dashboard.refresh_secs {
dashboard.refresh_secs = refresh_secs;
let labels: Vec<&str> = Range::ALL.iter().map(|range| range.code()).collect();
let chosen = Range::ALL.iter().position(|range| *range == dashboard.range).unwrap_or(0);
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = gap;
ui.add_space(margin);
if let Some(index) = style::segmented(ui, "range", &labels, chosen) {
if index != chosen {
dashboard.range = Range::ALL[index];
dashboard.settings_changed = true;
}
if ui.button("Refresh").clicked() {
dashboard.send(&ctx, Ask::View);
}
ui.add_space(8.0);
for theme in ThemeChoice::ALL {
if ui
.add(egui::Button::selectable(dashboard.theme == theme, theme.name()))
.clicked()
{
dashboard.theme = theme;
dashboard.settings_changed = true;
ctx.set_theme(theme.preference());
}
}
ui.add_space(8.0);
let online = dashboard.view.is_some();
let copy = ui.add_enabled(online, egui::Button::new("Copy summary"));
if copy.clicked() {
if let Some(view) = &dashboard.view {
ctx.copy_text(view.summary_markdown.clone());
}
dashboard.flash("Summary copied", now);
}
let export = ui.add_enabled(online, egui::Button::new("Export JSON"));
if export.clicked() {
let note = net::download("/api/export").map_or_else(
|error| format!("Export failed: {error}"),
|()| "Export started".to_owned(),
}
if one_line {
ui.add_space((ui.available_width() - actions_width(ui)).max(0.0));
ui.allocate_ui_with_layout(
egui::vec2(actions_width(ui), theme::layout::TOOLBAR_HEIGHT),
egui::Layout::left_to_right(egui::Align::Center),
|ui| actions(dashboard, ui, &ctx, now, gap),
);
}
});
if !one_line {
let height = theme::layout::TOOLBAR_HEIGHT;
ui.add_space(margin);
let room = ui.available_rect_before_wrap().width();
let group_width = if phone { room } else { actions_width(ui).min(room) };
// On a phone the actions wrap at the left; on a narrower window they sit
// on a second line, at the right.
let layout = if phone {
egui::Layout::left_to_right(egui::Align::Center).with_main_wrap(true)
} else {
egui::Layout::right_to_left(egui::Align::Center)
};
ui.allocate_ui_with_layout(egui::vec2(room, height), layout, |ui| {
if !phone {
ui.allocate_ui_with_layout(
egui::vec2(group_width, height),
egui::Layout::left_to_right(egui::Align::Center),
|ui| actions(dashboard, ui, &ctx, now, gap),
);
dashboard.flash(note, now);
} else {
ui.spacing_mut().item_spacing = egui::vec2(gap, gap);
actions(dashboard, ui, &ctx, now, gap);
}
let zeroing = dashboard
});
}
ui.add_space(gap - theme::space::LINE);
}
/// Refresh, theme, Copy summary, Export JSON, Zero stats, and the message slot.
fn actions(dashboard: &mut Dashboard, ui: &mut egui::Ui, ctx: &egui::Context, now: f64, gap: f32) {
ui.spacing_mut().item_spacing.x = gap;
let mut refresh_secs = dashboard.refresh_secs;
egui::ComboBox::from_id_salt("refresh")
.selected_text(fmt::refresh_label(refresh_secs))
.show_ui(ui, |ui| {
for secs in REFRESH_CHOICES {
ui.selectable_value(&mut refresh_secs, secs, fmt::refresh_label(secs));
}
});
if refresh_secs != dashboard.refresh_secs {
dashboard.refresh_secs = refresh_secs;
dashboard.settings_changed = true;
}
if ui.button("Refresh").clicked() {
dashboard.send(ctx, Ask::View);
}
let theme_chosen = ThemeChoice::ALL
.iter()
.position(|theme| *theme == dashboard.theme)
.unwrap_or(0);
if let Some(index) = style::segmented(ui, "theme", &theme_labels(), theme_chosen) {
let theme = ThemeChoice::ALL[index];
dashboard.theme = theme;
dashboard.settings_changed = true;
ctx.set_theme(theme.preference());
}
let online = dashboard.view.is_some();
let copy = ui.add_enabled(online, egui::Button::new("Copy summary"));
if copy.clicked() {
if let Some(view) = &dashboard.view {
ctx.copy_text(view.summary_markdown.clone());
}
dashboard.flash("Summary copied", now);
}
let export = ui.add_enabled(online, egui::Button::new("Export JSON"));
if export.clicked() {
let note = net::download("/api/export").map_or_else(
|error| format!("Export failed: {error}"),
|()| "Export started".to_owned(),
);
dashboard.flash(note, now);
}
let zeroing = dashboard
.pending
.as_ref()
.is_some_and(|(ask, _)| *ask == Ask::Zero);
let zero = ui.add_enabled(online && !zeroing, egui::Button::new("Zero stats"));
if zero.clicked() {
dashboard.asking_zero = true;
}
// A fixed-size slot, so that messages come and go without moving the controls.
ui.allocate_ui_with_layout(
egui::vec2(theme::space::TOOLBAR_NOTE_WIDTH, theme::layout::TOOLBAR_HEIGHT),
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
if dashboard
.pending
.as_ref()
.is_some_and(|(ask, _)| *ask == Ask::Zero);
let zero = ui.add_enabled(online && !zeroing, egui::Button::new("Zero stats"));
if zero.clicked() {
dashboard.asking_zero = true;
.is_some_and(|(ask, _)| *ask == Ask::View)
{
ui.spinner();
ui.add(egui::Label::new(theme::small(ui, "Updating")).truncate());
} else if let Some((note, _)) = &dashboard.note {
ui.add(egui::Label::new(theme::small(ui, note.clone())).truncate());
}
// A fixed-size slot, so that messages come and go without moving the controls.
ui.add_space(8.0);
ui.allocate_ui_with_layout(
egui::vec2(120.0, 20.0),
egui::Layout::left_to_right(egui::Align::Center),
|ui| {
if dashboard
.pending
.as_ref()
.is_some_and(|(ask, _)| *ask == Ask::View)
{
ui.spinner();
ui.label(egui::RichText::new("Updating").small());
} else if let Some((note, _)) = &dashboard.note {
ui.add(egui::Label::new(egui::RichText::new(note).small()).truncate());
}
},
);
});
ui.add_space(6.0);
});
},
);
}
/// Ask before zeroing: it can't be undone.
fn zero_question(dashboard: &mut Dashboard, ctx: &egui::Context) {
let modal = egui::Modal::new(egui::Id::unique("zero-stats-question")).show(ctx, |ui| {
ui.set_max_width(360.0);
ui.label(egui::RichText::new("Zero sccache's stats?").strong());
ui.add(egui::Label::new(
ui.add(egui::Label::new(theme::strong("Zero sccache's stats?")).wrap());
ui.add_space(theme::space::ITEM);
ui.add(egui::Label::new(theme::body(
"The counters go back to zero. The saved history stays, so the charts keep their \
older data. This can't be undone.",
).wrap());
))
.wrap());
ui.add_space(theme::space::PANEL_GAP);
ui.horizontal(|ui| {
if ui.button("Zero stats").clicked() {
Some(true)
@@ -368,7 +438,7 @@ fn zero_question(dashboard: &mut Dashboard, ctx: &egui::Context) {
/// What the page says while no view has arrived yet.
fn waiting(ui: &mut egui::Ui, error: Option<&str>, refresh_secs: u64) {
let [_, _, bad] = style::marks(ui.visuals().dark_mode);
let p = theme::ui(ui);
let retry = if refresh_secs > 0 {
format!("Trying again every {refresh_secs} seconds.")
} else {
@@ -380,86 +450,213 @@ fn waiting(ui: &mut egui::Ui, error: Option<&str>, refresh_secs: u64) {
format!(
"{error}.\n\nCheck that sccache-dash is running on this machine. {retry}"
),
bad,
p.bad,
),
None => (
"Waiting for the first figures".to_owned(),
"Asking the server for your cache numbers.".to_owned(),
ui.visuals().text_color(),
p.text,
),
};
// The same height the headline and cards take, so the page doesn't jump when they arrive.
ui.allocate_ui_with_layout(
egui::vec2(ui.available_rect_before_wrap().width(), 250.0),
egui::Layout::centered_and_justified(egui::Direction::TopDown),
|ui| {
ui.vertical(|ui| {
ui.label(egui::RichText::new(heading).size(20.0).color(color));
ui.add(egui::Label::new(body).wrap());
});
},
let width = ui.available_rect_before_wrap().width();
let height = theme::layout::HEADLINE_HEIGHT + theme::space::PANEL_GAP + theme::layout::CARD_HEIGHT * 2.0;
let (rect, _) = ui.allocate_exact_size(egui::vec2(width, height), egui::Sense::hover());
let mut place = ui.new_child(
egui::UiBuilder::new()
.max_rect(rect)
.layout(egui::Layout::centered_and_justified(egui::Direction::TopDown)),
);
place.vertical(|ui| {
ui.add(egui::Label::new(theme::strong(heading).color(color)).wrap());
ui.add(egui::Label::new(theme::small(ui, body)).wrap());
});
}
/// The whole page below the controls.
/// A notice that the server can't be reached, shown over the page rather than
/// in it, so what is already on screen keeps its place and height.
fn lost_contact(ctx: &egui::Context, error: &str, from: i64, page_width: f32) {
let [_, _, bad] = style::marks(ctx.theme() == egui::Theme::Dark);
let p = theme::ctx(ctx);
let when = fmt::moment_text(from + fmt::local_offset());
egui::Area::new(egui::Id::unique("lost-contact"))
.anchor(egui::Align2::RIGHT_TOP, egui::vec2(-8.0, 52.0))
.anchor(
egui::Align2::RIGHT_TOP,
egui::vec2(-theme::space::PAGE_MARGIN, theme::layout::TOOLBAR_HEIGHT + 2.0 * theme::space::PAGE_MARGIN),
)
.order(egui::Order::Foreground)
.show(ctx, |ui| {
let width = (page_width - 16.0).min(440.0);
let width = (page_width - 2.0 * theme::space::PAGE_MARGIN).min(440.0);
egui::Frame::NONE
.fill(bad.gamma_multiply(0.25))
.stroke(egui::Stroke::new(1.0, bad))
.corner_radius(6.0)
.inner_margin(8.0)
.fill(p.panel)
.stroke(egui::Stroke::new(1.0, p.bad))
.corner_radius(theme::space::PANEL_RADIUS)
.inner_margin(theme::space::PANEL_PADDING)
.show(ui, |ui| {
ui.set_max_width(width);
ui.set_max_width(width - 2.0 * theme::space::PANEL_PADDING);
ui.add(
egui::Label::new(
egui::RichText::new(format!(
theme::strong(format!(
"Can't reach the server: {error}. These figures are from {when}."
))
.strong(),
)
.wrap(),
.color(p.bad),
),
);
});
});
}
/// The rectangles of one row of the grid: each entry of `spans` is how many
/// columns that panel takes; all are at least `height` tall.
fn row(ui: &egui::Ui, height: f32, spans: &[usize]) -> Vec<egui::Rect> {
style::cells(ui, height, spans)
}
/// Close the row: the cursor moves below the tallest of its panels.
fn close_row(ui: &mut egui::Ui, taken: &[egui::Rect]) {
style::end_row(ui, taken);
}
/// One panel across the whole page, as tall as what it holds.
fn single(ui: &mut egui::Ui, title: &str, body: impl FnOnce(&mut egui::Ui)) {
let [rect] = row(ui, 0.0, &[1]).try_into().expect("one panel");
let (_, taken) = style::panel(ui, rect, title, body);
close_row(ui, &[taken]);
}
/// How tall the row of "Where compiles went", "By language" and "Problems" is:
/// enough for the tallest of the three, and never less than the usual height.
fn triptych_height(view: &View) -> f32 {
use theme::layout as l;
let languages = l::LANGUAGES_FIXED_HEIGHT + view.languages.len() as f32 * theme::space::ROW + 2.0 * theme::space::PANEL_PADDING;
let problems = l::PROBLEMS_FIXED_HEIGHT + view.problems.len() as f32 * l::PROBLEM_HEIGHT + 2.0 * theme::space::PANEL_PADDING;
l::TRIPTYCH_HEIGHT
.max(where_went::height(view.not_cached.len()))
.max(languages)
.max(problems)
}
/// How tall a panel with `histograms` build-time histograms in it is.
fn speed_height(view: &View) -> f32 {
use theme::layout as l;
let with_histograms = view
.build_times
.iter()
.filter(|times| times.compiles > 0 && !times.bins.is_empty())
.count() as f32;
l::SPEED_FIXED_HEIGHT + with_histograms * l::HISTOGRAM_HEIGHT
}
fn problems_height(view: &View) -> f32 {
use theme::layout as l;
if view.problems.is_empty() {
88.0
} else {
l::PROBLEMS_FIXED_HEIGHT + view.problems.len() as f32 * l::PROBLEM_HEIGHT + 2.0 * theme::space::PANEL_PADDING
}
}
/// The whole page below the controls: a grid of panels.
fn page(ui: &mut egui::Ui, view: &View, asked: Range, hidden_languages: &mut Vec<String>) {
let dark = ui.visuals().dark_mode;
let [_, _, bad] = style::marks(dark);
let p = theme::ui(ui);
use theme::layout as l;
if let Some(error) = &view.server.error {
style::banner(ui, format!("sccache is not working: {error}"), bad);
style::banner(ui, egui::RichText::new(format!("sccache is not working: {error}")), p.bad);
ui.add_space(theme::space::PANEL_GAP);
}
let columns = theme::columns(ui.available_rect_before_wrap().width());
headline(ui, view, asked);
// Six cards in one row on a wide screen; three in the two-column layout; two on a phone.
let per_row = match columns {
3 => 6,
2 => 3,
_ => 2,
};
cards::row(ui, view, per_row);
match columns {
3 => {
let [a, b, c] = row(ui, triptych_height(view), &[1, 1, 1]).try_into().expect("three panels");
let (_, a) = style::panel(ui, a, "Where compiles went", |ui| where_went::section(ui, view));
let (_, b) = style::panel(ui, b, "By language", |ui| where_went::languages(ui, view));
let (_, c) = style::panel(ui, c, "Problems", |ui| problems::section(ui, view));
close_row(ui, &[a, b, c]);
let [a, b] = row(ui, l::CHARTS_HEIGHT, &[2, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Over time", |ui| overtime::section(ui, view, hidden_languages));
let (_, b) = style::panel(ui, b, "Speed", |ui| speed::section(ui, view));
close_row(ui, &[a, b]);
}
2 => {
let height = triptych_height(view);
let [a, b] = row(ui, height, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Where compiles went", |ui| where_went::section(ui, view));
let (_, b) = style::panel(ui, b, "By language", |ui| where_went::languages(ui, view));
close_row(ui, &[a, b]);
let height = l::TRIPTYCH_HEIGHT.min(360.0).max(problems_height(view)).max(speed_height(view));
let [a, b] = row(ui, height, &[1, 1]).try_into().expect("two panels");
let (_, a) = style::panel(ui, a, "Problems", |ui| problems::section(ui, view));
let (_, b) = style::panel(ui, b, "Speed", |ui| speed::section(ui, view));
close_row(ui, &[a, b]);
let [a] = row(ui, l::CHARTS_HEIGHT, &[2]).try_into().expect("one panel");
let (_, a) = style::panel(ui, a, "Over time", |ui| overtime::section(ui, view, hidden_languages));
close_row(ui, &[a]);
}
_ => {
// One column: the phone's order, each panel as tall as what it holds.
single(ui, "Problems", |ui| problems::section(ui, view));
single(ui, "Where compiles went", |ui| where_went::section(ui, view));
single(ui, "By language", |ui| where_went::languages(ui, view));
single(ui, "Over time", |ui| overtime::section(ui, view, hidden_languages));
single(ui, "Speed", |ui| speed::section(ui, view));
}
}
extras(ui, view);
let open = ui
.ctx()
.data_mut(|data| data.get_temp::<bool>(egui::Id::unique("raw-counters-open")))
.unwrap_or(true);
let full = style::span_width(ui, columns, columns);
let [rect] = row(ui, raw::height(view, full, open), &[columns]).try_into().expect("one panel");
let taken = raw::section(ui, view, rect);
close_row(ui, &[taken]);
ui.add_space(theme::space::PAGE_MARGIN);
}
/// The "Extras" panels, side by side where there are several.
fn extras(ui: &mut egui::Ui, view: &View) {
if view.extras.is_empty() {
return;
}
let columns = theme::columns(ui.available_rect_before_wrap().width());
let per_row = columns.min(view.extras.len()).max(1);
for line in view.extras.chunks(per_row) {
let spans: Vec<usize> = line.iter().map(|_| 1).collect();
let height = theme::space::ROW * (line.iter().map(|extra| extra.rows.len()).max().unwrap_or(0) + 1) as f32
+ theme::space::PANEL_PADDING * 2.0 + theme::space::UNDER_TITLE + 12.0;
let cells = style::cells(ui, height, &spans);
let mut taken = Vec::with_capacity(cells.len());
for (rect, extra) in cells.iter().zip(line) {
let title: &str = Box::leak(extra.title.clone().into_boxed_str());
let (_, rect) = style::panel(ui, *rect, title, |ui| extras::section(ui, view));
taken.push(rect);
}
close_row(ui, &taken);
}
headline(ui, view, asked, dark);
ui.add_space(10.0);
cards::row(ui, view, dark);
problems::section(ui, view, dark);
where_went::section(ui, view, dark);
overtime::section(ui, view, hidden_languages, dark);
speed::section(ui, view);
extras::section(ui, view);
raw::section(ui, view);
ui.add_space(12.0);
}
/// One of the three big figures.
struct Figure<'a> {
value: String,
/// How big the figure is written: 30 for numbers, less for words.
/// The size of the figure's text: a number, or words at the card size.
size: f32,
color: egui::Color32,
caption: String,
/// Smaller print under the figure.
small: String,
/// A second line of smaller print, kept so the block's height never changes.
/// A second line of smaller print; the block keeps its height when it is empty.
small2: String,
/// A trend line and the value it is drawn against.
trend: Option<(&'a [Option<f64>], f64)>,
@@ -469,25 +666,27 @@ struct Figure<'a> {
impl Figure<'_> {
/// Draw in a column `width` wide and always the same height.
fn draw(self, ui: &mut egui::Ui, width: f32) {
let gap = ui.spacing().item_spacing.y;
let gap = theme::space::LINE;
let block = ui.allocate_ui_with_layout(
egui::vec2(width, FIGURE_HEIGHT),
egui::vec2(width, theme::layout::FIGURE_HEIGHT),
egui::Layout::top_down(egui::Align::Min),
|ui| {
ui.set_width(width);
ui.add(
egui::Label::new(
egui::RichText::new(&self.value).size(self.size).color(self.color),
)
.truncate(),
);
ui.add(egui::Label::new(egui::RichText::new(&self.caption).small()).truncate());
ui.spacing_mut().item_spacing = egui::vec2(gap, gap);
let value = egui::Label::new(
egui::RichText::new(&self.value)
.font(theme::number_font(self.size))
.color(self.color),
)
.truncate();
ui.add(value.sense(egui::Sense::hover())).on_hover_text(&self.value);
ui.add(egui::Label::new(theme::small(ui, self.caption.clone())).truncate());
match self.trend {
Some((values, top)) => style::sparkline(ui, TREND_HEIGHT, values, top, self.color),
None => ui.add_space(TREND_HEIGHT + gap),
Some((values, top)) => style::sparkline(ui, theme::drawing::SPARKLINE, values, top, self.color),
None => ui.add_space(theme::drawing::SPARKLINE + gap),
}
ui.add(egui::Label::new(egui::RichText::new(&self.small).small().weak()).truncate());
ui.add(egui::Label::new(egui::RichText::new(&self.small2).small().weak()).truncate());
ui.add(egui::Label::new(theme::small(ui, self.small.clone())).truncate());
ui.add(egui::Label::new(theme::small(ui, self.small2.clone())).truncate());
},
);
if let Some(hover) = self.hover {
@@ -496,14 +695,11 @@ impl Figure<'_> {
}
}
const TREND_HEIGHT: f32 = 22.0;
const FIGURE_HEIGHT: f32 = 120.0;
/// The big numbers, what they mean, and where the cache lives.
fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
fn headline(ui: &mut egui::Ui, view: &View, asked: Range) {
let range = view.range.unwrap_or(asked);
let totals = &view.totals;
let text_color = ui.visuals().text_color();
let p = theme::ui(ui);
let rates: Vec<Option<f64>> = view
.buckets
@@ -520,135 +716,166 @@ fn headline(ui: &mut egui::Ui, view: &View, asked: Range, dark: bool) {
let problems = view.problems.len();
let worst = view.problems.first();
let problem_color = match worst.map(|problem| problem.severity) {
Some(sccache_dash_api::Severity::Error) => style::marks(dark)[2],
Some(sccache_dash_api::Severity::Warning) => style::marks(dark)[1],
None => text_color,
Some(sccache_dash_api::Severity::Error) => p.bad,
Some(sccache_dash_api::Severity::Warning) => p.warn,
None => p.text,
};
ui.label(egui::RichText::new(range.label().to_uppercase()).strong());
let width = ui.available_rect_before_wrap().width();
let spacing = ui.spacing().item_spacing.x;
// Side by side where there is room; one under another on a phone.
let columns = if width >= 600.0 { 3.0 } else { 1.0 };
let column = (width - spacing * (columns - 1.0)) / columns;
ui.horizontal_wrapped(|ui| {
Figure {
value: fmt::percent(totals.hit_rate()),
size: 30.0,
color: style::hit_rate_color(totals.hit_rate(), dark),
caption: "from cache".into(),
small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())),
trend: Some((&rates, 1.0)),
hover: None,
small2: String::new(),
}
.draw(ui, column);
// A saving is never written in milliseconds; and when no language's build time is
// known yet, the figure says so instead of showing nothing.
let seconds = view.time_saved.seconds;
let left_out = view.time_saved.hits_left_out;
let left_out_line = if left_out > 0 {
format!("{} hits left out of this figure", fmt::count(left_out))
} else {
"every hit counted".to_owned()
};
let interval = view
.time_saved
.interval_90
.map(|(low, high)| format!("{} – {} (90% range)", fmt::duration(low), fmt::duration(high)));
let (value, size, small, small2) = if seconds >= 1.0 {
(format!("~{}", fmt::duration(seconds)), 30.0, interval.unwrap_or_default(), left_out_line)
} else if seconds > 0.0 {
("~under 1 s".to_owned(), 30.0, interval.unwrap_or_default(), left_out_line)
} else if left_out > 0 {
(
"not enough data yet".to_owned(),
22.0,
String::new(),
format!(
"{} hits not counted: no build time known yet for their language",
fmt::count(left_out)
),
)
} else {
("nothing saved yet".to_owned(), 22.0, String::new(), String::new())
};
Figure {
value,
size,
color: text_color,
caption: "saved (rough)".into(),
small,
small2,
trend: Some((&saved, saved_top)),
hover: Some(view.time_saved.note.clone()),
}
.draw(ui, column);
Figure {
value: if problems == 1 {
"1 problem".into()
} else if problems == 0 {
"No problems".into()
} else {
format!("{} problems", fmt::count(problems as u64))
},
size: 30.0,
color: problem_color,
caption: worst
.map(|problem| problem.title.clone())
.unwrap_or_else(|| "Nothing needs attention".into()),
small: String::new(),
small2: String::new(),
trend: None,
hover: None,
}
.draw(ui, column);
});
// Timeouts, cache errors and forced recaches are inside the built count, as sccache counts them.
let built = totals.misses;
ui.add(egui::Label::new(format!(
let counts = format!(
"{} compiles · {} from cache · {} built",
fmt::count(totals.requests),
fmt::count(totals.hits),
fmt::count(built)
)).wrap());
let server = &view.server;
let mut parts = Vec::new();
if let Some(location) = &server.cache_location {
// sccache words it `Local disk: "/home/me/.cache/sccache"`; the kind is enough here.
let kind = location.split(':').next().unwrap_or(location);
let kind = if kind.eq_ignore_ascii_case("LOCAL DISK") {
"local disk".to_owned()
} else {
kind.to_owned()
};
parts.push(kind);
}
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
parts.push(format!("{} of {}", fmt::bytes(size), fmt::bytes(max)));
}
if let Some(version) = server.version.as_deref().or(server.client_version.as_deref()) {
parts.push(format!("sccache {version}"));
}
parts.push(
match server.status {
sccache_dash_api::Status::Running => "running",
sccache_dash_api::Status::Idle => "idle",
sccache_dash_api::Status::NotRunning => "not running",
}
.to_owned(),
fmt::count(totals.misses)
);
let line = format!("Cache: {}", parts.join(" · "));
let response = ui.add(egui::Label::new(line).wrap());
if let Some(location) = &server.cache_location {
response.on_hover_text(location.clone());
}
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
let full = if max > 0 { size as f64 / max as f64 } else { 0.0 };
let color = if full >= 0.95 { style::marks(dark)[2] } else { style::CACHE };
style::meter(ui, 6.0, full, color);
}
let title_text = theme::title(ui, range.label()).text().to_owned();
let counts_text = counts.clone();
let width = ui.available_rect_before_wrap().width();
let rect = egui::Rect::from_min_size(
ui.cursor().min,
egui::vec2(width, theme::layout::HEADLINE_HEIGHT),
);
let (_, taken) = style::panel_titled(
ui,
rect,
|ui| {
ui.horizontal(|ui| {
ui.add(egui::Label::new(theme::title(ui, title_text)).truncate());
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.add(egui::Label::new(theme::small(ui, counts_text)).truncate());
});
});
},
|ui| {
let width = ui.available_rect_before_wrap().width();
let spacing = theme::space::PANEL_GAP;
// Side by side where there is room; one under another on a phone.
let side_by_side = width >= 600.0;
let columns = if side_by_side { 3.0 } else { 1.0 };
let column = (width - spacing * (columns - 1.0)) / columns;
let draw = |ui: &mut egui::Ui, figure: Figure<'_>| figure.draw(ui, column);
// Timeouts, cache errors and forced recaches are inside the built count, as sccache counts them.
let first = Figure {
value: fmt::percent(totals.hit_rate()),
size: theme::px::HEADLINE,
color: theme::hit_rate_color(totals.hit_rate(), p),
caption: "from cache".into(),
small: format!("{} of all compiler calls", fmt::percent(totals.hit_rate_of_all())),
trend: Some((&rates, 1.0)),
hover: None,
small2: String::new(),
};
// A saving is never written in milliseconds; and when no language's build time is
// known yet, the figure says so instead of showing nothing.
let seconds = view.time_saved.seconds;
let left_out = view.time_saved.hits_left_out;
let left_out_line = if left_out > 0 {
format!("{} hits left out of this figure", fmt::count(left_out))
} else {
"every hit counted".to_owned()
};
let interval = view
.time_saved
.interval_90
.map(|(low, high)| format!("{} – {} (90% range)", fmt::duration(low), fmt::duration(high)));
let (value, size, small, small2) = if seconds >= 1.0 {
(format!("~{}", fmt::duration(seconds)), theme::px::HEADLINE, interval.unwrap_or_default(), left_out_line)
} else if seconds > 0.0 {
("~under 1 s".to_owned(), theme::px::HEADLINE, interval.unwrap_or_default(), left_out_line)
} else if left_out > 0 {
(
"not enough data yet".to_owned(),
theme::px::CARD_NUMBER,
String::new(),
format!(
"{} hits not counted: no build time known yet for their language",
fmt::count(left_out)
),
)
} else {
("nothing saved yet".to_owned(), theme::px::CARD_NUMBER, String::new(), String::new())
};
let second = Figure {
value,
size,
color: p.text,
caption: "saved (rough)".into(),
small,
small2,
trend: Some((&saved, saved_top)),
hover: Some(view.time_saved.note.clone()),
};
let third = Figure {
value: if problems == 1 {
"1 problem".into()
} else if problems == 0 {
"No problems".into()
} else {
format!("{} problems", fmt::count(problems as u64))
},
size: theme::px::CARD_NUMBER,
color: problem_color,
caption: worst
.map(|problem| problem.title.clone())
.unwrap_or_else(|| "Nothing needs attention".into()),
small: String::new(),
small2: String::new(),
trend: None,
hover: None,
};
if side_by_side {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = spacing;
draw(ui, first);
draw(ui, second);
draw(ui, third);
});
} else {
draw(ui, first);
draw(ui, second);
draw(ui, third);
}
style::rule(ui);
ui.add_space(theme::space::PANEL_GAP);
let server = &view.server;
let mut parts = Vec::new();
if let Some(location) = &server.cache_location {
// sccache words it `Local disk: "/home/me/.cache/sccache"`; the kind is enough here.
let kind = location.split(':').next().unwrap_or(location);
let kind = if kind.eq_ignore_ascii_case("LOCAL DISK") {
"local disk".to_owned()
} else {
kind.to_owned()
};
parts.push(kind);
}
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
parts.push(format!("{} of {}", fmt::bytes(size), fmt::bytes(max)));
}
if let Some(version) = server.version.as_deref().or(server.client_version.as_deref()) {
parts.push(format!("sccache {version}"));
}
parts.push(
match server.status {
sccache_dash_api::Status::Running => "running",
sccache_dash_api::Status::Idle => "idle",
sccache_dash_api::Status::NotRunning => "not running",
}
.to_owned(),
);
let line = format!("Cache: {}", parts.join(" · "));
let response = ui.add(egui::Label::new(theme::small(ui, line)).wrap());
if let Some(location) = &server.cache_location {
response.on_hover_text(location.clone());
}
if let (Some(size), Some(max)) = (server.cache_size, server.max_cache_size) {
let full = if max > 0 { size as f64 / max as f64 } else { 0.0 };
let color = if full >= theme::state::CACHE_FULL { p.bad } else { p.from_cache };
style::meter(ui, theme::drawing::USAGE_BAR, full, color);
}
},
);
ui.allocate_rect(taken, egui::Sense::hover());
ui.add_space(theme::space::PANEL_GAP);
}