From cf72e340c76ae71c02314981f07aef81ff97d0c3 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 20 Jul 2026 14:41:09 +0300 Subject: [PATCH] refine radio button handling --- ui/src/api.hxx | 7 +++++++ ui/src/main_window.cxx | 7 +------ ui/src/main_window.hxx | 1 - ui/src/main_window.ui | 1 - 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ui/src/api.hxx b/ui/src/api.hxx index 56aecb5..1a1162c 100644 --- a/ui/src/api.hxx +++ b/ui/src/api.hxx @@ -42,6 +42,13 @@ using ffi::Mode; using ffi::ShapeArgs; using ffi::RedrawArgs; +/// Cast an integer to @c Mode, returning a fallback if the input is out of range. +inline static Mode modeFromInt(std::uint32_t mode) { + if (mode > (std::uint32_t)Mode::Mesh) + return Mode::Solid; + return (Mode)mode; +} + class MutCore { friend class BoxCore; diff --git a/ui/src/main_window.cxx b/ui/src/main_window.cxx index 91b312d..2325c55 100644 --- a/ui/src/main_window.cxx +++ b/ui/src/main_window.cxx @@ -37,7 +37,7 @@ void Hyperboloid::updateView() { m_ui->layersDown->setMaximum(max_layers); const auto color = m_ui->inBackground->color(); const ShapeArgs shape { - .mode = (Mode)m_ui->mode->checkedId(), + .mode = modeFromInt(m_ui->mode->checkedId()), .sides = (std::uint32_t)m_ui->sides->value(), .layers_up = (std::uint32_t)m_ui->layersUp->value(), .layers_down = (std::uint32_t)m_ui->layersDown->value(), @@ -57,9 +57,4 @@ void Hyperboloid::updateView() { m_ui->viewport->setView(args); } -void Hyperboloid::updateViewIf(bool update) { - if (update) - updateView(); -} - #include "moc_main_window.cpp" diff --git a/ui/src/main_window.hxx b/ui/src/main_window.hxx index 5614d9c..342f9c4 100644 --- a/ui/src/main_window.hxx +++ b/ui/src/main_window.hxx @@ -17,7 +17,6 @@ public: public slots: void updateModeUi(); void updateView(); - void updateViewIf(bool update); // for radio buttons private: const std::unique_ptr m_ui; diff --git a/ui/src/main_window.ui b/ui/src/main_window.ui index e5c3b28..ddac555 100644 --- a/ui/src/main_window.ui +++ b/ui/src/main_window.ui @@ -618,7 +618,6 @@ updateView() - updateViewIf(bool) updateModeUi()