Label and align row issue buttons

This commit is contained in:
Dandaedre 2026-11-03 17:44:42 +01:00
parent 12ae1f3985
commit 7f652f32b2
1 changed files with 78 additions and 37 deletions

View File

@ -49,6 +49,15 @@ fn diagnostic_name(code: &str) -> String {
}
}
fn diagnostic_button_name(code: &str) -> String {
let name = diagnostic_name(code).to_lowercase();
let mut chars = name.chars();
chars
.next()
.map(|first| first.to_uppercase().chain(chars).collect())
.unwrap_or_default()
}
/// Presentation only: retain source values and avoid treating plain numbers as times.
fn cell_text(cell: &crate::model::Cell) -> String {
if cell.time_style {
@ -1661,16 +1670,41 @@ impl App {
ui.visuals().text_color()
};
let modified = modified_row(row, &profile);
let issue_index = row.issues.iter().find(|i| !needs_information(&a.diagnostics[**i]))
.or_else(|| row.issues.first()).copied();
let issue_button = issue_index.map(|index| format!(
"{} - {}",
if error { "Error" } else { "Details" },
diagnostic_button_name(&a.diagnostics[index].code),
));
let can_ignore = !error && row.row > 0 && issue_index.is_some();
// Size every cell to the actual content, then lay it out from the top.
// Keep blank spreadsheet lines out of the preview, preserving the source.
let title = row.title.lines().map(str::trim).filter(|line| !line.is_empty()).collect::<Vec<_>>().join("\n");
let title_height = egui::WidgetText::from(title.as_str())
.into_galley(ui, Some(egui::TextWrapMode::Wrap), title_width, egui::TextStyle::Body)
.size().y;
let title_line_width = egui::WidgetText::from(title.as_str())
.into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::TextStyle::Body)
.size().x;
let button_text_width = issue_button.as_ref().map_or(0.0, |label| {
egui::WidgetText::from(label.as_str())
.into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::TextStyle::Button)
.size().x + 2.0 * ui.spacing().button_padding.x
});
let ignore_width = if can_ignore {
egui::WidgetText::from("Ignore")
.into_galley(ui, Some(egui::TextWrapMode::Extend), f32::INFINITY, egui::TextStyle::Button)
.size().x + 2.0 * ui.spacing().button_padding.x + ui.spacing().item_spacing.x
} else { 0.0 };
let inline_issue = issue_button.is_some()
&& !title.contains('\n')
&& title_line_width + button_text_width + ignore_width
+ ui.spacing().item_spacing.x <= title_width;
let timing_height = ui.text_style_height(&egui::TextStyle::Body)
* if compact { 3.0 } else { 1.0 }
+ if compact { 2.0 * ui.spacing().item_spacing.y } else { 0.0 };
let issue_height = if row.issues.is_empty() { 0.0 }
let issue_height = if row.issues.is_empty() || inline_issue { 0.0 }
else { ui.spacing().interact_size.y + ui.spacing().item_spacing.y };
let row_height = (title_height + issue_height).max(timing_height).max(ui.spacing().interact_size.y);
let response = ui.vertical(|ui| {
@ -1761,41 +1795,47 @@ impl App {
"Timed"
};
let explanation = row_hover_text(row, a, status);
if ui
.add(
egui::Label::new(RichText::new(&title).color(color))
.wrap()
.sense(egui::Sense::click()),
)
.on_hover_text(&explanation)
.double_clicked()
{
let mut title_double_clicked = false;
let mut issue_controls = |ui: &mut egui::Ui| {
if can_ignore && ui.small_button("Ignore")
.on_hover_text("Ignore this source row. Apply & recheck to update the schedule; restore it under All rows.")
.clicked() {
profile.row_kinds.insert(row.row, "ignore".into());
}
if let (Some(index), Some(label)) = (issue_index, &issue_button)
&& ui.small_button(RichText::new(label).color(color))
.on_hover_text(&explanation).clicked() {
if row.row > 0 { details = Some(row.row); }
else if let Some(key) = &row.gap_key { gap_details = Some(key.clone()); }
else { resolve = Some(index); }
}
};
if inline_issue {
ui.horizontal(|ui| {
title_double_clicked = ui
.add(egui::Label::new(RichText::new(&title).color(color))
.sense(egui::Sense::click()))
.on_hover_text(&explanation)
.double_clicked();
issue_controls(ui);
});
} else {
title_double_clicked = ui
.add(egui::Label::new(RichText::new(&title).color(color))
.wrap().sense(egui::Sense::click()))
.on_hover_text(&explanation)
.double_clicked();
if issue_button.is_some() {
ui.horizontal_wrapped(&mut issue_controls);
}
}
if title_double_clicked {
if row.row > 0 {
details = Some(row.row);
} else {
gap_details = row.gap_key.clone();
}
}
if !row.issues.is_empty() {
let index = row
.issues
.iter()
.find(|i| !needs_information(&a.diagnostics[**i]))
.unwrap_or(&row.issues[0]);
ui.horizontal_wrapped(|ui| {
if !error && row.row > 0 && ui.small_button("Ignore")
.on_hover_text("Ignore this source row. Apply & recheck to update the schedule; restore it under All rows.")
.clicked() {
profile.row_kinds.insert(row.row, "ignore".into());
}
if ui.small_button(RichText::new(if error { "Error" } else { "Details" }).color(color))
.on_hover_text(&explanation).clicked() {
if row.row > 0 { details = Some(row.row); }
else if let Some(key) = &row.gap_key { gap_details = Some(key.clone()); }
else { resolve = Some(*index); }
}
});
}
});
let controls = ui.vertical(|ui| {
ui.set_width(105.0);
@ -3034,8 +3074,7 @@ mod tests {
assert!(labels.iter().any(|(s, _)| s == "Auto (Event)"));
let resolve = labels
.iter()
.filter(|(s, _)| s == "Details")
.nth(1)
.find(|(s, _)| s == "Details - Row without a timing")
.unwrap()
.1
.center();
@ -3092,12 +3131,14 @@ mod tests {
let size = [860.0, 620.0];
render(&mut app, &ctx, size, vec![]);
let labels = render(&mut app, &ctx, size, vec![]);
let opening = labels
let overlap_button = labels
.iter()
.find(|(text, _)| text == "Opening")
.find(|(text, _)| text == "Error - Overlap")
.unwrap()
.1
.center();
.1;
let opening = labels.iter().find(|(text, _)| text == "Opening").unwrap().1;
assert!((opening.top() - overlap_button.top()).abs() <= 1.0);
let opening = opening.center();
render(
&mut app,
&ctx,
@ -3144,7 +3185,7 @@ mod tests {
configure_style(&ctx);
render(&mut app, &ctx, [860.0, 900.0], vec![]);
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
assert!(labels.iter().any(|(s, _)| s == "Error"));
assert!(labels.iter().any(|(s, _)| s.starts_with("Error - ")));
app.tables[0].rows[1][0].text = "invalid clock".into();
let a = pipeline::analyze(&app.tables[0], &profile, &AtomicBool::new(false), |_, _| {});
assert!(a.rundown.is_none());