Centralize legacy app preferences

This commit is contained in:
2026-06-04 14:18:18 +02:00
parent ca5b94b044
commit f8243566c4
9 changed files with 352 additions and 22 deletions

View File

@@ -1,5 +1,7 @@
#pragma once
#include "foundation/result.h"
#include <cstddef>
#include <span>
@@ -44,6 +46,18 @@ struct StoredBooleanPreferencePlan {
bool value = false;
};
class AppPreferenceServices {
public:
virtual ~AppPreferenceServices() = default;
virtual void apply_ui_scale(const ScaleApplicationPlan& plan) = 0;
virtual void apply_viewport_scale(const ScaleApplicationPlan& plan) = 0;
virtual void apply_interface_direction(const InterfaceDirectionPlan& plan) = 0;
virtual void apply_vr_controllers_preference(const StoredBooleanPreferencePlan& plan) = 0;
virtual void apply_timelapse_preference(const TimelapsePreferencePlan& plan) = 0;
virtual void apply_canvas_cursor_mode(const StoredIntegerPreferencePlan& plan) = 0;
};
[[nodiscard]] constexpr ScaleApplicationPlan plan_ui_scale(
float requested_scale,
float display_density) noexcept
@@ -111,4 +125,55 @@ struct StoredBooleanPreferencePlan {
return { mode };
}
[[nodiscard]] inline pp::foundation::Status execute_ui_scale_preference(
float requested_scale,
float display_density,
AppPreferenceServices& services)
{
services.apply_ui_scale(plan_ui_scale(requested_scale, display_density));
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_viewport_scale_preference(
float requested_scale,
float display_density,
AppPreferenceServices& services)
{
services.apply_viewport_scale(plan_viewport_scale(requested_scale, display_density));
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_interface_direction_preference(
bool right_to_left,
AppPreferenceServices& services)
{
services.apply_interface_direction(plan_interface_direction(right_to_left));
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_vr_controllers_preference(
bool enabled,
AppPreferenceServices& services)
{
services.apply_vr_controllers_preference(plan_vr_controllers_preference(enabled));
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_timelapse_preference(
bool enabled,
bool recording_running,
AppPreferenceServices& services)
{
services.apply_timelapse_preference(plan_timelapse_preference(enabled, recording_running));
return pp::foundation::Status::success();
}
[[nodiscard]] inline pp::foundation::Status execute_canvas_cursor_mode_preference(
int mode,
AppPreferenceServices& services)
{
services.apply_canvas_cursor_mode(plan_canvas_cursor_mode(mode));
return pp::foundation::Status::success();
}
}

View File

@@ -17,6 +17,7 @@
#include "app_core/app_status.h"
#include "app_core/main_toolbar.h"
#include "app_core/tools_menu.h"
#include "legacy_app_preference_services.h"
#include "legacy_app_shell_services.h"
#include "legacy_brush_ui_services.h"
#include "legacy_canvas_tool_services.h"
@@ -1095,7 +1096,11 @@ void App::init_menu_tools()
ui_scale->on_select = [ui_scale](Node* target, int index)
{
App::I->set_ui_scale(ui_scale->get_float(index));
const auto status = pp::panopainter::execute_legacy_ui_scale_preference(
*App::I,
ui_scale->get_float(index));
if (!status.ok())
LOG("UI scale preference failed: %s", status.message);
};
}
@@ -1112,10 +1117,11 @@ void App::init_menu_tools()
vp_scale->on_select = [vp_scale](Node* target, int index)
{
const auto plan = pp::app::plan_viewport_scale(vp_scale->get_float(index));
App::I->canvas->set_density(plan.scale);
Settings::set("vp-scale", Serializer::Float(plan.scale));
Settings::save();
const auto status = pp::panopainter::execute_legacy_viewport_scale_preference(
*App::I,
vp_scale->get_float(index));
if (!status.ok())
LOG("Viewport scale preference failed: %s", status.message);
};
}
@@ -1132,7 +1138,11 @@ void App::init_menu_tools()
rtl_btn->find<NodeCheckBox>("tools-rtl-check")->on_value_changed = [this, main](Node*, bool checked)
{
set_ui_rtl(checked);
const auto status = pp::panopainter::execute_legacy_interface_direction_preference(
*this,
checked);
if (!status.ok())
LOG("Interface direction preference failed: %s", status.message);
};
}
@@ -1178,10 +1188,11 @@ void App::init_menu_tools()
vr_btn->find<NodeCheckBox>("tools-vr-controllers-check")->on_value_changed = [this, main](Node* target, bool checked)
{
const auto plan = pp::app::plan_vr_controllers_preference(checked);
vr_controllers_enabled = plan.value;
Settings::set("vr-controllers-enabled", Serializer::Boolean(plan.value));
Settings::save();
const auto status = pp::panopainter::execute_legacy_vr_controllers_preference(
*this,
checked);
if (!status.ok())
LOG("VR controllers preference failed: %s", status.message);
};
}
@@ -1198,13 +1209,11 @@ void App::init_menu_tools()
btn->find<NodeCheckBox>("tools-timelapse-check")->on_value_changed = [this, main](Node*, bool checked)
{
const auto plan = pp::app::plan_timelapse_preference(checked, App::I->rec_running);
if (plan.recording_action == pp::app::TimelapseRecordingAction::stop_recording)
App::I->rec_stop();
else if (plan.recording_action == pp::app::TimelapseRecordingAction::start_recording)
App::I->rec_start();
Settings::set("auto-timelapse", Serializer::Boolean(plan.enabled));
Settings::save();
const auto status = pp::panopainter::execute_legacy_timelapse_preference(
*this,
checked);
if (!status.ok())
LOG("Timelapse preference failed: %s", status.message);
};
}
@@ -1214,10 +1223,11 @@ void App::init_menu_tools()
mode->on_select = [mode](Node* target, int index)
{
const auto plan = pp::app::plan_canvas_cursor_mode(index);
App::I->canvas->set_cursor_visibility((NodeCanvas::kCursorVisibility)plan.value);
Settings::set("show-cursor", Serializer::Integer(plan.value));
Settings::save();
const auto status = pp::panopainter::execute_legacy_canvas_cursor_mode_preference(
*App::I,
index);
if (!status.ok())
LOG("Cursor mode preference failed: %s", status.message);
};
}
};

View File

@@ -0,0 +1,111 @@
#include "pch.h"
#include "legacy_app_preference_services.h"
#include "app.h"
#include "node_canvas.h"
#include "serializer.h"
#include "settings.h"
namespace pp::panopainter {
namespace {
class LegacyAppPreferenceServices final : public pp::app::AppPreferenceServices {
public:
explicit LegacyAppPreferenceServices(App& app) noexcept
: app_(app)
{
}
void apply_ui_scale(const pp::app::ScaleApplicationPlan& plan) override
{
app_.set_ui_scale(plan.scale);
}
void apply_viewport_scale(const pp::app::ScaleApplicationPlan& plan) override
{
if (!app_.canvas)
return;
app_.canvas->set_density(plan.scale);
Settings::set("vp-scale", Serializer::Float(plan.scale));
Settings::save();
}
void apply_interface_direction(const pp::app::InterfaceDirectionPlan& plan) override
{
app_.set_ui_rtl(plan.direction == pp::app::InterfaceDirection::right_to_left);
}
void apply_vr_controllers_preference(const pp::app::StoredBooleanPreferencePlan& plan) override
{
app_.vr_controllers_enabled = plan.value;
Settings::set("vr-controllers-enabled", Serializer::Boolean(plan.value));
Settings::save();
}
void apply_timelapse_preference(const pp::app::TimelapsePreferencePlan& plan) override
{
if (plan.recording_action == pp::app::TimelapseRecordingAction::stop_recording) {
app_.rec_stop();
} else if (plan.recording_action == pp::app::TimelapseRecordingAction::start_recording) {
app_.rec_start();
}
Settings::set("auto-timelapse", Serializer::Boolean(plan.enabled));
Settings::save();
}
void apply_canvas_cursor_mode(const pp::app::StoredIntegerPreferencePlan& plan) override
{
if (!app_.canvas)
return;
app_.canvas->set_cursor_visibility(static_cast<NodeCanvas::kCursorVisibility>(plan.value));
Settings::set("show-cursor", Serializer::Integer(plan.value));
Settings::save();
}
private:
App& app_;
};
} // namespace
pp::foundation::Status execute_legacy_ui_scale_preference(App& app, float requested_scale)
{
LegacyAppPreferenceServices services(app);
return pp::app::execute_ui_scale_preference(requested_scale, app.display_density, services);
}
pp::foundation::Status execute_legacy_viewport_scale_preference(App& app, float requested_scale)
{
LegacyAppPreferenceServices services(app);
return pp::app::execute_viewport_scale_preference(requested_scale, 1.0F, services);
}
pp::foundation::Status execute_legacy_interface_direction_preference(App& app, bool right_to_left)
{
LegacyAppPreferenceServices services(app);
return pp::app::execute_interface_direction_preference(right_to_left, services);
}
pp::foundation::Status execute_legacy_vr_controllers_preference(App& app, bool enabled)
{
LegacyAppPreferenceServices services(app);
return pp::app::execute_vr_controllers_preference(enabled, services);
}
pp::foundation::Status execute_legacy_timelapse_preference(App& app, bool enabled)
{
LegacyAppPreferenceServices services(app);
return pp::app::execute_timelapse_preference(enabled, app.rec_running, services);
}
pp::foundation::Status execute_legacy_canvas_cursor_mode_preference(App& app, int mode)
{
LegacyAppPreferenceServices services(app);
return pp::app::execute_canvas_cursor_mode_preference(mode, services);
}
} // namespace pp::panopainter

View File

@@ -0,0 +1,28 @@
#pragma once
#include "app_core/app_preferences.h"
class App;
namespace pp::panopainter {
[[nodiscard]] pp::foundation::Status execute_legacy_ui_scale_preference(
App& app,
float requested_scale);
[[nodiscard]] pp::foundation::Status execute_legacy_viewport_scale_preference(
App& app,
float requested_scale);
[[nodiscard]] pp::foundation::Status execute_legacy_interface_direction_preference(
App& app,
bool right_to_left);
[[nodiscard]] pp::foundation::Status execute_legacy_vr_controllers_preference(
App& app,
bool enabled);
[[nodiscard]] pp::foundation::Status execute_legacy_timelapse_preference(
App& app,
bool enabled);
[[nodiscard]] pp::foundation::Status execute_legacy_canvas_cursor_mode_preference(
App& app,
int mode);
} // namespace pp::panopainter