ui: a signal's page shows gain and offset as aligned rows with a pencil each, replacing Calibrate

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino FerrariandClaude Opus 4.6 committed 2026-11-03 11:36:58 +01:00
1 parent 6ff7dd786e
commit bbef7faf3d
9 files changed
+185 -30

No files matched your search

+20 -8
View File
@@ -865,15 +865,21 @@ void on_info_clicked(GtkButton* button, gpointer user) {
void on_calibrate_apply(GtkButton*, gpointer user) {
CalibContext* ctx = static_cast<CalibContext*>(user);
ctx->app->model->set_calibration(ctx->signal, gtk_spin_button_get_value(GTK_SPIN_BUTTON(ctx->gain)),
gtk_spin_button_get_value(GTK_SPIN_BUTTON(ctx->offset)));
// A single-field dialog has only its own spin; the other half is the model's record, unchanged.
std::pair<double, double> cal = ctx->app->model->calibration(ctx->signal);
if (ctx->gain != nullptr) cal.first = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ctx->gain));
if (ctx->offset != nullptr) cal.second = gtk_spin_button_get_value(GTK_SPIN_BUTTON(ctx->offset));
ctx->app->model->set_calibration(ctx->signal, cal.first, cal.second);
schedule_layout_save(*ctx->app);
// The signal page quotes the calibration; refill it before the dialog goes.
signal_pages_sync(*ctx->app);
gtk_window_destroy(GTK_WINDOW(ctx->window));
}
void open_calibration(App& app, GtkWindow* parent, std::size_t signal) {
void open_calibration(App& app, GtkWindow* parent, std::size_t signal, CalibField field) {
const SignalInfo& sig = app.model->signals()[signal];
GtkWidget* window = dialog_window(GTK_WIDGET(parent), "Calibrate");
const char* heading = field == CalibField::Gain ? "Gain" : field == CalibField::Offset ? "Offset" : "Calibrate";
GtkWidget* window = dialog_window(GTK_WIDGET(parent), heading);
GtkWidget* box = gtk_window_get_child(GTK_WINDOW(window));
GtkWidget* title = gtk_label_new(sig.name.c_str());
gtk_widget_set_halign(title, GTK_ALIGN_START);
@@ -884,10 +890,16 @@ void open_calibration(App& app, GtkWindow* parent, std::size_t signal) {
// and the values are the model's record, so a signal that is not acquired still shows the
// calibration that will apply to it when it is.
const std::pair<double, double> cal = app.model->calibration(signal);
GtkWidget* gain = spin(-1.0e12, 1.0e12, 0.001, 6, cal.first);
GtkWidget* offset = spin(-1.0e12, 1.0e12, 0.001, 6, cal.second);
gtk_box_append(GTK_BOX(box), labeled_box("gain", gain));
gtk_box_append(GTK_BOX(box), labeled_box("offset", offset));
GtkWidget* gain = nullptr;
GtkWidget* offset = nullptr;
if (field != CalibField::Offset) {
gain = spin(-1.0e12, 1.0e12, 0.001, 6, cal.first);
gtk_box_append(GTK_BOX(box), labeled_box("gain", gain));
}
if (field != CalibField::Gain) {
offset = spin(-1.0e12, 1.0e12, 0.001, 6, cal.second);
gtk_box_append(GTK_BOX(box), labeled_box("offset", offset));
}
auto* ctx = new CalibContext{&app, signal, gain, offset, window};
GtkWidget* cancel = gtk_button_new_with_label("Cancel");