Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// SPDX-FileCopyrightText: 2026 Martino Ferrari
|
|
|
|
#include "source/registry.hpp"
|
|
#include "ui_app.hpp"
|
|
|
|
#include <adwaita.h>
|
|
|
|
#include <cstdio>
|
|
|
|
namespace udpscope {
|
|
namespace ui_impl {
|
|
|
|
void build_source_panels(App& app) {
|
|
if (app.slideover.stack == nullptr || app.acq == nullptr || app.acq->source() == nullptr) return;
|
|
SourceKind* kind = find_kind(app.source_kind);
|
|
if (kind == nullptr) return;
|
|
for (const SourcePanel& p : kind->make_panels(*app.acq->source())) {
|
|
if (p.widget == nullptr || p.id.empty()) {
|
|
std::fprintf(stderr, "[source] a '%s' panel was skipped: it has %s\n", app.source_kind.c_str(),
|
|
p.widget == nullptr ? "no widget" : "an empty id");
|
|
continue;
|
|
}
|
|
const std::string name = "source-" + p.id;
|
|
// The panel is a slide-over page now: the slide-over wraps it in its own scroller, and with two or
|
|
// more source pages it draws the segmented switch (the E-1608: Analog out, Digital I/O).
|
|
if (!slideover_add_page(app, name, p.title, p.widget)) continue;
|
|
app.source_panels.push_back({name, p.title, p.widget});
|
|
}
|
|
// Disconnected until the first Connected event says otherwise.
|
|
apply_source_panels(app, false);
|
|
}
|
|
|
|
void apply_source_panels(App& app, bool connected) {
|
|
for (const SourcePanelPage& p : app.source_panels) {
|
|
if (gtk_widget_get_sensitive(p.content) != (connected ? TRUE : FALSE)) {
|
|
gtk_widget_set_sensitive(p.content, connected);
|
|
}
|
|
}
|
|
}
|
|
|
|
void sync_source_panels(App& app) {
|
|
if (app.source_panels.empty() || app.model == nullptr) return;
|
|
apply_source_panels(app, app.model->stats().connected.load(std::memory_order_relaxed));
|
|
}
|
|
|
|
} // namespace ui_impl
|
|
} // namespace udpscope
|