Extract app preference planning into app core

This commit is contained in:
2026-06-03 09:36:38 +02:00
parent 19cb14b5dc
commit a64a63def7
8 changed files with 431 additions and 22 deletions

View File

@@ -6,12 +6,15 @@
#include "node_progress_bar.h"
#include "node_dialog_picker.h"
#include "node_panel_floating.h"
#include "app_core/app_preferences.h"
#include "settings.h"
#include "serializer.h"
#include "font.h"
#include "node_remote_page.h"
#include "node_shorcuts.h"
#include <vector>
void App::title_update()
{
static char str[256];
@@ -924,10 +927,14 @@ void App::init_menu_tools()
if (auto ui_scale = popup_time->find<NodeComboBox>("tools-ui-scale"))
{
// set index to current zoom level (or at least the closest in list)
std::vector<float> scale_options;
scale_options.reserve(ui_scale->m_data.size());
for (int i = 0; i < ui_scale->m_data.size(); i++)
if (App::I->zoom >= ui_scale->get_float(i))
ui_scale->set_index(i);
scale_options.push_back(ui_scale->get_float(i));
const auto selection = pp::app::plan_scale_option_selection(App::I->zoom, scale_options);
if (selection.has_selection)
ui_scale->set_index(static_cast<int>(selection.index));
ui_scale->on_select = [ui_scale](Node* target, int index)
{
@@ -937,16 +944,20 @@ void App::init_menu_tools()
if (auto vp_scale = popup_time->find<NodeComboBox>("tools-vp-scale"))
{
// set index to current zoom level (or at least the closest in list)
std::vector<float> scale_options;
scale_options.reserve(vp_scale->m_data.size());
for (int i = 0; i < vp_scale->m_data.size(); i++)
if (App::I->canvas->m_density >= vp_scale->get_float(i))
vp_scale->set_index(i);
scale_options.push_back(vp_scale->get_float(i));
const auto selection = pp::app::plan_scale_option_selection(App::I->canvas->m_density, scale_options);
if (selection.has_selection)
vp_scale->set_index(static_cast<int>(selection.index));
vp_scale->on_select = [vp_scale](Node* target, int index)
{
float d = vp_scale->get_float(index);
App::I->canvas->set_density(d);
Settings::set("vp-scale", Serializer::Float(d));
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();
};
}
@@ -1010,8 +1021,9 @@ void App::init_menu_tools()
vr_btn->find<NodeCheckBox>("tools-vr-controllers-check")->on_value_changed = [this, main](Node* target, bool checked)
{
vr_controllers_enabled = checked;
Settings::set("vr-controllers-enabled", Serializer::Boolean(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();
};
}
@@ -1029,11 +1041,12 @@ void App::init_menu_tools()
btn->find<NodeCheckBox>("tools-timelapse-check")->on_value_changed = [this, main](Node*, bool checked)
{
if (!checked && App::I->rec_running)
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 (checked && !App::I->rec_running)
else if (plan.recording_action == pp::app::TimelapseRecordingAction::start_recording)
App::I->rec_start();
Settings::set("auto-timelapse", Serializer::Boolean(checked));
Settings::set("auto-timelapse", Serializer::Boolean(plan.enabled));
Settings::save();
};
}
@@ -1044,8 +1057,9 @@ void App::init_menu_tools()
mode->on_select = [mode](Node* target, int index)
{
App::I->canvas->set_cursor_visibility((NodeCanvas::kCursorVisibility)index);
Settings::set("show-cursor", Serializer::Integer(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();
};
}
@@ -1418,17 +1432,20 @@ void App::initLayout()
void App::set_ui_scale(float scale)
{
zoom = scale;
FontManager::change_scale(zoom * display_density);
Settings::set("ui-scale", Serializer::Float(zoom));
const auto plan = pp::app::plan_ui_scale(scale, display_density);
zoom = plan.scale;
FontManager::change_scale(plan.font_scale);
Settings::set("ui-scale", Serializer::Float(plan.scale));
Settings::save();
App::I->title_update();
}
void App::set_ui_rtl(bool rtl)
{
ui_rtl = rtl;
layout[main_id]->find("central-row")->SetRTL(rtl ? YGDirectionRTL : YGDirectionLTR);
const auto plan = pp::app::plan_interface_direction(rtl);
ui_rtl = plan.direction == pp::app::InterfaceDirection::right_to_left;
layout[main_id]->find("central-row")->SetRTL(
ui_rtl ? YGDirectionRTL : YGDirectionLTR);
}
bool App::get_ui_rtl() const