Edit gap distribution directly from schedule rows

This commit is contained in:
Dandaedre 2026-11-05 12:41:11 +01:00
parent 63e4aeb061
commit 0cffbe6201
2 changed files with 98 additions and 18 deletions

View File

@ -1259,12 +1259,8 @@ impl App {
} else if action == "add_to_next" {
options.direction = "following".into(); ui.label("Extend the following events equally");
} else {
egui::ComboBox::from_id_salt("gap_distribution_direction")
.selected_text(if options.direction == "following" { "Before following events" } else { "After previous events" })
.show_ui(ui, |ui| {
ui.selectable_value(&mut options.direction, "previous".into(), "After previous events");
ui.selectable_value(&mut options.direction, "following".into(), "Before following events");
});
ui.radio_value(&mut options.direction, "previous".into(), "After previous events");
ui.radio_value(&mut options.direction, "following".into(), "Before following events");
}
ui.small(if action == "create_event" { "Creates equal timed events interleaved with the selected neighbours." }
else if action == "keep" { "Places equal untimed gaps between the selected neighbours." }
@ -2472,9 +2468,8 @@ impl App {
} else {
0.0
};
let distribution = row.gap_key.as_ref().and_then(|key| profile.gap_options.get(key)).filter(|options| options.distribute);
let distribution_height = if distribution.is_some() {
ui.text_style_height(&egui::TextStyle::Body) + ui.spacing().item_spacing.y
let distribution_height = if row.gap_key.is_some() {
ui.spacing().interact_size.y + ui.spacing().item_spacing.y
} else { 0.0 };
let row_height = (title_height + issue_height)
.max(timing_height)
@ -2626,13 +2621,23 @@ impl App {
ui.set_width(controls_width);
ui.set_min_height(row_height);
if let Some(key) = &row.gap_key {
ui.push_id(("gap_row", row_index), |ui| Self::gap_resolution_control(ui, &mut profile, key));
if profile.gap_options.get(key).is_some_and(|options| options.distribute) {
let count = profile.gap_options[key].count;
ui.label(RichText::new(format!("Across {count} {}", if count == 1 { "event" } else { "events" }))
.color(if pending { PREVIEW_PENDING } else { PREVIEW_GAP }).strong())
.on_hover_text("This gap is distributed across neighbouring events. Double-click the row to change the count or direction.");
}
ui.push_id(("gap_row", row_index), |ui| {
Self::gap_resolution_control(ui, &mut profile, key);
let options = profile.gap_options.get(key);
let label = if let Some(options) = options.filter(|options| options.distribute) {
format!("Across {} {}", options.count, if options.count == 1 { "event" } else { "events" })
} else { "Distribute…".into() };
let popup_id = egui::Id::new(("inline_gap_distribution", key, row_index));
let response = ui.button(RichText::new(label).color(if pending { PREVIEW_PENDING } else { PREVIEW_GAP }).strong())
.on_hover_text("Set the split count and direction here, then Apply & recheck. No need to open the row editor.");
if response.clicked() {
ui.memory_mut(|memory| memory.toggle_popup(popup_id));
}
egui::popup::popup_below_widget(ui, popup_id, &response, egui::popup::PopupCloseBehavior::CloseOnClickOutside, |ui| {
ui.set_max_width(300.0);
Self::gap_distribution_controls(ui, &mut profile, key);
});
});
} else {
ui.push_id(("schedule_kind", row_index, row.row), |ui| {
let detected = if self.dirty {
@ -2871,6 +2876,79 @@ mod tests {
}
}
#[test]
fn distribute_gap_from_schedule_without_opening_row_editor() {
let mut app = sample();
app.tables[0].rows.last_mut().unwrap()[0].text = "09:20".into();
let profile = Profile {
untimed_as_notes: true,
..Default::default()
};
app.profile = serde_json::to_string(&profile).unwrap();
app.analyzed_profile = Some(profile.clone());
app.analysis = Some(pipeline::analyze(
&app.tables[0],
&profile,
&AtomicBool::new(false),
|_, _| {},
));
let key = app
.analysis
.as_ref()
.unwrap()
.rundown
.as_ref()
.unwrap()
.gaps[0]
.key();
app.row_filter = RowFilter::Gaps;
app.selected_row = None;
let ctx = egui::Context::default();
configure_style(&ctx);
let size = [1000.0, 900.0];
render(&mut app, &ctx, size, vec![]);
let labels = render(&mut app, &ctx, size, vec![]);
let button = labels
.iter()
.find(|(label, _)| label == "Distribute…")
.unwrap()
.1
.center();
click_size(&mut app, &ctx, button, size);
let labels = render(&mut app, &ctx, size, vec![]);
let toggle = labels
.iter()
.find(|(label, _)| label == "Distribute across neighbours")
.unwrap()
.1
.center();
click_size(&mut app, &ctx, toggle, size);
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
assert!(profile.gap_options[&key].distribute);
assert_eq!(profile.gap_options[&key].count, 2);
assert!(app.dirty);
assert!(!app.row_details);
let labels = render(&mut app, &ctx, size, vec![]);
assert!(labels.iter().any(|(label, _)| label == "Number of events"));
assert!(
labels
.iter()
.any(|(label, _)| label == "After previous events")
);
assert!(labels.iter().any(|(label, _)| label == "Across 2 events"));
let direction = labels
.iter()
.find(|(label, _)| label == "Before following events")
.unwrap()
.1
.center();
click_size(&mut app, &ctx, direction, size);
let profile: Profile = serde_json::from_str(&app.profile).unwrap();
assert_eq!(profile.gap_options[&key].direction, "following");
let labels = render(&mut app, &ctx, size, vec![]);
assert!(labels.iter().any(|(label, _)| label == "Number of events"));
}
fn render(
app: &mut App,
ctx: &egui::Context,

View File

@ -93,8 +93,10 @@ visually distinct from labels and ordinary actions; the active tab uses the stro
its title defaults to the named break, or “Break”, and can be edited in the gap editor.
Double-click the row or use **Edit gap…** for the additional options.
Distributed gaps show **Across N events** beneath the resolution dropdown in each
schedule row; the label uses the pending colour until Apply & recheck.
Click **Distribute…** directly beneath the gap resolution in the schedule to
enable distribution and change its event count and direction. Once enabled, this
control reads **Across N events** and remains clickable; it uses the pending colour
until Apply & recheck. The same options remain available in the gap editor.
**Distribute across neighbours** divides the gap equally across N contiguous events:
- Extend previous / Add to next lengthens each of the previous / following N timers.
- Keep gap inserts N untimed intervals, after previous events or before following events.