Hide UI preference keys behind adapter

This commit is contained in:
2026-06-12 17:53:57 +02:00
parent 9f1a52401a
commit 058997bd78
6 changed files with 105 additions and 21 deletions

View File

@@ -1107,7 +1107,9 @@ void App::init_menu_tools()
if (auto btn = popup_time->find<NodeButtonCustom>("tools-timelapse"))
{
NodeCheckBox* cb = btn->find<NodeCheckBox>("tools-timelapse-check");
cb->set_value(pp::panopainter::legacy_boolean_preference_or("auto-timelapse", true), false);
cb->set_value(
pp::panopainter::read_legacy_startup_preferences(vr_controllers_enabled).auto_timelapse,
false);
btn->on_click = [this, btn](Node* b)
{
@@ -1127,7 +1129,7 @@ void App::init_menu_tools()
if (auto mode = popup_time->find<NodeComboBox>("tools-show-cursor"))
{
mode->set_index(pp::panopainter::legacy_integer_preference_or("show-cursor", 0));
mode->set_index(pp::panopainter::read_legacy_canvas_preferences().cursor_mode);
mode->on_select = [mode](Node* target, int index)
{
@@ -1539,7 +1541,7 @@ void App::set_ui_scale(float scale)
const auto plan = pp::app::plan_ui_scale(scale, display_density);
zoom = plan.scale;
FontManager::change_scale(plan.font_scale);
pp::panopainter::save_legacy_float_preference("ui-scale", plan.scale);
pp::panopainter::save_legacy_ui_scale_preference(plan.scale);
App::I->title_update();
}
@@ -1604,8 +1606,7 @@ void App::ui_save()
}
d.set("drop-right", list_drop_right);
pp::panopainter::set_legacy_descriptor_preference("ui", d);
pp::panopainter::set_legacy_boolean_preference("ui-rtl", ui_rtl);
pp::panopainter::set_legacy_ui_state_preferences(d, ui_rtl);
save_platform_ui_state();
pp::panopainter::save_legacy_preferences();
@@ -1613,16 +1614,17 @@ void App::ui_save()
void App::ui_restore()
{
if (pp::panopainter::has_legacy_preference("ui-rtl"))
set_ui_rtl(pp::panopainter::legacy_integer_preference("ui-rtl"));
const auto preferences = pp::panopainter::read_legacy_ui_preferences();
if (preferences.has_rtl)
set_ui_rtl(preferences.rtl);
if (!pp::panopainter::has_legacy_preference("ui"))
if (!preferences.state)
return;
auto floatings = layout[main_id]->find_ref("floatings");
auto drop_left = layout[main_id]->find_ref("drop-left");
auto drop_right = layout[main_id]->find_ref("drop-right");
auto d = pp::panopainter::get_legacy_descriptor_preference("ui");
auto d = preferences.state;
for (auto const& l : d->get<Serializer::List>("floatings")->items)
{
auto ld = std::static_pointer_cast<Serializer::Descriptor>(l);

View File

@@ -21,6 +21,38 @@ LegacyStartupPreferenceSnapshot read_legacy_startup_preferences(bool default_vr_
};
}
LegacyCanvasPreferenceSnapshot read_legacy_canvas_preferences()
{
return {
Settings::value_or<Serializer::Float>("vp-scale", 1.0F),
Settings::value_or<Serializer::Integer>("show-cursor", 0),
};
}
LegacyUiPreferenceSnapshot read_legacy_ui_preferences()
{
LegacyUiPreferenceSnapshot snapshot;
snapshot.has_rtl = Settings::has("ui-rtl");
if (snapshot.has_rtl)
snapshot.rtl = Settings::value<Serializer::Integer>("ui-rtl");
if (Settings::has("ui"))
snapshot.state = Settings::get<Serializer::Descriptor>("ui");
return snapshot;
}
LegacyWindowPreferenceSnapshot read_legacy_window_preferences(int default_show_command)
{
LegacyWindowPreferenceSnapshot snapshot;
snapshot.has_ui_scale = Settings::has("ui-scale");
if (snapshot.has_ui_scale)
snapshot.ui_scale = Settings::value<Serializer::Float>("ui-scale");
snapshot.show_command = Settings::value_or<Serializer::Integer>("window-show-cmd", default_show_command);
snapshot.has_window_rect = Settings::has("window-rect");
if (snapshot.has_window_rect)
snapshot.window_rect = Settings::value<Serializer::IVec4>("window-rect");
return snapshot;
}
bool has_legacy_preference(const char* key)
{
return Settings::has(key);
@@ -86,6 +118,24 @@ void unset_legacy_preference(const char* key)
Settings::unset(key);
}
void save_legacy_ui_scale_preference(float scale)
{
Settings::set("ui-scale", Serializer::Float(scale));
Settings::save();
}
void set_legacy_ui_state_preferences(const Serializer::Descriptor& state, bool right_to_left)
{
Settings::set("ui", state);
Settings::set("ui-rtl", Serializer::Boolean(right_to_left));
}
void set_legacy_window_preferences(int show_command, const glm::ivec4& window_rect)
{
Settings::set("window-show-cmd", Serializer::Integer(show_command));
Settings::set("window-rect", Serializer::IVec4(window_rect));
}
void save_legacy_boolean_preference(const char* key, bool value)
{
set_legacy_boolean_preference(key, value);

View File

@@ -10,8 +10,30 @@ struct LegacyStartupPreferenceSnapshot {
bool vr_controllers_enabled = true;
};
struct LegacyCanvasPreferenceSnapshot {
float viewport_density = 1.0F;
int cursor_mode = 0;
};
struct LegacyUiPreferenceSnapshot {
bool has_rtl = false;
int rtl = 0;
std::shared_ptr<Serializer::Descriptor> state;
};
struct LegacyWindowPreferenceSnapshot {
bool has_ui_scale = false;
float ui_scale = 1.0F;
int show_command = 0;
bool has_window_rect = false;
glm::ivec4 window_rect {};
};
bool load_legacy_preferences();
LegacyStartupPreferenceSnapshot read_legacy_startup_preferences(bool default_vr_controllers_enabled);
LegacyCanvasPreferenceSnapshot read_legacy_canvas_preferences();
LegacyUiPreferenceSnapshot read_legacy_ui_preferences();
LegacyWindowPreferenceSnapshot read_legacy_window_preferences(int default_show_command);
bool has_legacy_preference(const char* key);
int legacy_integer_preference(const char* key);
int legacy_integer_preference_or(const char* key, int default_value);
@@ -25,6 +47,9 @@ void set_legacy_ivec4_preference(const char* key, const glm::ivec4& value);
void set_legacy_boolean_preference(const char* key, bool value);
void set_legacy_descriptor_preference(const char* key, const Serializer::Descriptor& value);
void unset_legacy_preference(const char* key);
void save_legacy_ui_scale_preference(float scale);
void set_legacy_ui_state_preferences(const Serializer::Descriptor& state, bool right_to_left);
void set_legacy_window_preferences(int show_command, const glm::ivec4& window_rect);
void save_legacy_boolean_preference(const char* key, bool value);
void save_legacy_float_preference(const char* key, float value);
bool save_legacy_preferences();

View File

@@ -617,8 +617,7 @@ void win32_save_window_state()
{
WINDOWPLACEMENT p;
GetWindowPlacement(hWnd, &p);
pp::panopainter::set_legacy_integer_preference("window-show-cmd", p.showCmd);
pp::panopainter::set_legacy_ivec4_preference("window-rect", {
pp::panopainter::set_legacy_window_preferences(p.showCmd, {
p.rcNormalPosition.left,
p.rcNormalPosition.top,
p.rcNormalPosition.right,
@@ -801,22 +800,22 @@ int main(int argc, char** argv)
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
App::I->display_density = (float)x / 96.f;
if (pp::panopainter::has_legacy_preference("ui-scale"))
App::I->zoom = pp::panopainter::legacy_float_preference("ui-scale");
const auto window_preferences = pp::panopainter::read_legacy_window_preferences(SW_NORMAL);
if (window_preferences.has_ui_scale)
App::I->zoom = window_preferences.ui_scale;
else
App::I->zoom = (float)x / 96.f;
int show_cmd = SW_NORMAL;
show_cmd = pp::panopainter::legacy_integer_preference_or("window-show-cmd", show_cmd);
int show_cmd = window_preferences.show_command;
DWORD wnd_style = WS_OVERLAPPEDWINDOW;
//if (show_cmd == SW_MAXIMIZE)
// wnd_style != WS_MAXIMIZE;
RECT clientRect = { 0, 0, (int)App::I->width * App::I->zoom, (int)App::I->height * App::I->zoom };
POINT clientPos = { CW_USEDEFAULT, CW_USEDEFAULT };
if (pp::panopainter::has_legacy_preference("window-rect"))
if (window_preferences.has_window_rect)
{
auto wnd_rect = pp::panopainter::legacy_ivec4_preference("window-rect");
auto wnd_rect = window_preferences.window_rect;
App::I->width = wnd_rect.z - wnd_rect.x;
App::I->height = wnd_rect.w - wnd_rect.y;
clientRect = { wnd_rect.x, wnd_rect.y, wnd_rect.z, wnd_rect.w };

View File

@@ -238,8 +238,9 @@ Node* NodeCanvas::clone_instantiate() const
void NodeCanvas::init()
{
m_density = pp::panopainter::legacy_float_preference_or("vp-scale", 1.f);
m_cursor_visibility = (kCursorVisibility)pp::panopainter::legacy_integer_preference_or("show-cursor", 0);
const auto preferences = pp::panopainter::read_legacy_canvas_preferences();
m_density = preferences.viewport_density;
m_cursor_visibility = (kCursorVisibility)preferences.cursor_mode;
m_mouse_ignore = false;
m_canvas = std::make_unique<Canvas>();