ui: the events pane's frame is a .ui file

src/ui/events-pane.ui holds the pane: the GtkRevealer that slides it in, the header with
the way back to the live stream, the Compare and Accumulate actions, and the list inside
its scroller. The rows stay in code -- one per latched event, rebuilt whenever the cache
changes -- and their sensitivity stays with update_group_buttons(), which is why the file
only starts the two actions insensitive.

Two statements moved into the file along with the widgets, because they are about what the
pane is for rather than about a default: multiple selection, and activation on *double*
click. With single-click activation the plain click that builds a selection would replay
the event instead.

Read back as `events pane: compare=1 accumulate=1 list=1 revealer=1 nested=1`, where
`nested` is the list being inside the revealer -- the one thing a lost id cannot show. The
[events] probe is the other half and drives the pane end to end: recording, trigger, the
history button, a row click and the replay, then Compare and Accumulate, so the file's
buttons are read by being clicked. check_ui: 13 ok, 0 failed.
This commit is contained in:
Martino Ferrari committed 2026-10-12 16:27:56 +02:00
1 parent c86d2117fb
commit 148d1168d6
5 files changed
+139 -67

No files matched your search

+20 -67
View File
@@ -769,84 +769,37 @@ void on_event_row_activated(GtkListBox*, GtkListBoxRow* row, gpointer user) {
/// toolbar's history button, which is itself only there while trigger mode and recording are both
/// on (`sync_events_availability()`).
GtkWidget* build_events_pane(App& app) {
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
// A floor, not a width: the divider sets the width and this is what the pane needs to stay usable at
// its narrowest.
gtk_widget_set_size_request(box, 170, -1);
gtk_widget_set_margin_start(box, 6);
gtk_widget_set_margin_end(box, 6);
gtk_widget_set_margin_top(box, 6);
// The pane's frame -- the revealer that slides it in, the header with the way back to the live stream, the
// two actions that read the selection, and the list inside its scroller -- is a UI file. The rows are not:
// there is one per latched event, and the whole list is rebuilt whenever the cache changes. The two
// buttons' sensitivity is `update_group_buttons()`'s, which is why the file only starts them insensitive.
GtkBuilder* ui = ui_load(app, "/org/udpscope/ui/events-pane.ui");
app.events_revealer = GTK_WIDGET(gtk_builder_get_object(ui, "events_pane"));
app.events_compare = GTK_WIDGET(gtk_builder_get_object(ui, "events_compare"));
app.events_accumulate = GTK_WIDGET(gtk_builder_get_object(ui, "events_accumulate"));
GtkWidget* live = GTK_WIDGET(gtk_builder_get_object(ui, "events_live"));
app.events_list = GTK_WIDGET(gtk_builder_get_object(ui, "events_list"));
if (app.events_revealer == nullptr || app.events_compare == nullptr ||
app.events_accumulate == nullptr || live == nullptr || app.events_list == nullptr) {
// A missing id is a mistake in the `.ui`: the pane comes up empty rather than taking the window with it,
// and `[udpscope] events pane:` reads the difference.
return app.events_revealer != nullptr ? app.events_revealer : gtk_revealer_new();
}
GtkWidget* head = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
GtkWidget* title = gtk_label_new(nullptr);
gtk_label_set_markup(GTK_LABEL(title), "<b>Events</b>");
gtk_widget_set_hexpand(title, TRUE);
gtk_widget_set_halign(title, GTK_ALIGN_START);
gtk_box_append(GTK_BOX(head), title);
// The two group actions, under the header and above the list they read: what they act on is the
// selection, so they belong where the selection is.
GtkWidget* actions = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
app.events_compare = gtk_button_new_with_label("Compare");
gtk_widget_set_tooltip_text(app.events_compare,
"the two selected events in two plots side by side, with the axes "
"synchronised");
gtk_widget_set_hexpand(app.events_compare, TRUE);
gtk_widget_set_sensitive(app.events_compare, FALSE);
// What the pane *does*, which a file cannot hold: the two group actions read the selection, the list
// replays an event on a double click, and the header's button goes back to the live stream.
g_signal_connect(app.events_compare, "clicked", G_CALLBACK(on_group_clicked), &app);
gtk_box_append(GTK_BOX(actions), app.events_compare);
app.events_accumulate = gtk_button_new_with_label("Accumulate");
gtk_widget_set_tooltip_text(app.events_accumulate,
"up to four selected events overlaid in the same traces, translucent, "
"so where they agree the trace is brighter");
gtk_widget_set_hexpand(app.events_accumulate, TRUE);
gtk_widget_set_sensitive(app.events_accumulate, FALSE);
g_signal_connect(app.events_accumulate, "clicked", G_CALLBACK(on_group_clicked), &app);
gtk_box_append(GTK_BOX(actions), app.events_accumulate);
gtk_box_append(GTK_BOX(box), actions);
GtkWidget* live = gtk_button_new_with_label("Live");
gtk_widget_add_css_class(live, "flat");
gtk_widget_set_tooltip_text(live, "go back to the live stream after replaying a stored event");
g_signal_connect(live, "clicked", G_CALLBACK(+[](GtkButton*, gpointer user) {
go_live_again(*static_cast<App*>(user));
}),
&app);
gtk_box_append(GTK_BOX(head), live);
gtk_box_append(GTK_BOX(box), head);
app.events_list = gtk_list_box_new();
// The decoded pictures live as long as the list does.
g_object_set_data_full(G_OBJECT(app.events_list), "udpscope-event-thumbs", new EventThumbCache,
[](gpointer p) {
auto* cache = static_cast<EventThumbCache*>(p);
for (const auto& entry : *cache) {
if (entry.second != nullptr) g_object_unref(entry.second);
}
delete cache;
});
// Multiple, and activation on *double* click: the list's other job is choosing which events to
// compare or accumulate, and with single-click activation a plain click -- the gesture that builds a
// selection -- would replay the event instead.
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(app.events_list), FALSE);
gtk_list_box_set_selection_mode(GTK_LIST_BOX(app.events_list), GTK_SELECTION_MULTIPLE);
g_signal_connect(app.events_list, "row-activated", G_CALLBACK(on_event_row_activated), &app);
g_signal_connect(app.events_list, "selected-rows-changed", G_CALLBACK(+[](GtkListBox*,
gpointer user) {
g_signal_connect(app.events_list, "selected-rows-changed",
G_CALLBACK(+[](GtkListBox*, gpointer user) {
update_group_buttons(*static_cast<App*>(user));
}),
&app);
GtkWidget* scroll = gtk_scrolled_window_new();
gtk_widget_set_vexpand(scroll, TRUE);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scroll), app.events_list);
gtk_box_append(GTK_BOX(box), scroll);
app.events_revealer = gtk_revealer_new();
gtk_revealer_set_transition_type(GTK_REVEALER(app.events_revealer),
GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
gtk_revealer_set_child(GTK_REVEALER(app.events_revealer), box);
return app.events_revealer;
}