Show Tile swap's Swap rate as a slider, and let it go slower

A new ParamSpec::slider() marks an Int or Double param to be shown in
the interface as a Gtk::Scale with its minimum and maximum marked under
the ends, rather than a spin button; the command line and the project
file are unchanged. Swap rate uses it, and now runs from 0 to 5 in
steps of 0.01 (was 0 to 30 in steps of 0.1): with every tile swapping
on its own, even 0.1 swapped the canvas many times a second.

Version 0.8.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
simon
2026-09-30 23:44:27 +02:00
co-authored by Claude Opus 5.5
parent 5402a50742
commit ef8f728126
9 changed files with 120 additions and 17 deletions
+46
View File
@@ -7,6 +7,7 @@
#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <memory>
#include <string>
@@ -633,6 +634,50 @@ void testFont(Gtk::Window& window, const std::filesystem::path& dir) {
"a family chosen there is saved with the project");
}
void testSlider(Gtk::Window& window, const std::filesystem::path& dir) {
std::cout << "slider\n";
std::filesystem::create_directories(dir);
const auto path = dir / "swapping.json";
effector::Project project;
project.video.enabled = true;
effector::ChainStage stage{effector::effectByName("tileswap"), {}};
stage.values["tileswap_rate"] = 0.5;
project.stages.push_back(stage);
effector::saveProject(path.string(), project);
window.activate_action("win.open-recent",
Glib::Variant<Glib::ustring>::create(Glib::filename_to_uri(path.string())));
pump(300);
auto* chainList = named<Gtk::ListBox>(window, "chain-list");
if (chainList != nullptr && chainList->get_row_at_index(0) != nullptr) {
chainList->select_row(*chainList->get_row_at_index(0));
}
pump(100);
std::vector<Gtk::Scale*> scales;
collect<Gtk::Scale>(window, [](Gtk::Scale& s) { return s.is_drawable(); }, scales);
check(scales.size() == 1, "a param marked as a slider is shown as one");
if (scales.size() != 1) return;
auto* scale = scales.front();
auto adjustment = scale->get_adjustment();
// Written the way the locale writes numbers, as the interface does.
const auto mark = [](double at) {
return std::string(Glib::ustring::format(std::fixed, std::setprecision(2), at));
};
check(adjustment->get_lower() == 0.0 && adjustment->get_upper() == 5.0 &&
showsText(*scale, mark(0.0)) && showsText(*scale, mark(5.0)),
"with its range marked at both ends");
check(scale->get_value() == 0.5, "and shows the value saved");
scale->set_value(0.05);
pump(100);
window.activate_action("win.save-project");
pump(100);
const auto saved = effector::loadProject(path.string());
check(saved.stages.size() == 1 &&
std::abs(effector::paramDouble(saved.stages[0].values, "tileswap_rate", 0.0) - 0.05) < 1e-9,
"a value slid to is saved with the project");
}
bool actionEnabled(Gtk::Window& window, const std::string& name) {
auto action = dynamic_cast<Gtk::ApplicationWindow&>(window).lookup_action(name);
return action && action->get_enabled();
@@ -822,6 +867,7 @@ int main(int argc, char** argv) {
testRecentProjects(*window, dataDir / "projects");
testVideo(*window, dataDir / "video");
testFont(*window, dataDir / "font");
testSlider(*window, dataDir / "slider");
testHistory(*window, dataDir / "history");
testMemoryGuard(*window, dataDir / "memory");
app->remove_window(*window);