Complete Modern desktop widgets and file libraries (by Codex)

This commit is contained in:
Codex committed 2026-10-26 00:08:50 +01:00
1 parent db89d889f7
commit 31bcf93205
43 files changed
+3134 -484

No files matched your search

+47 -1
View File
@@ -74,7 +74,7 @@ const std::vector<std::string> &desktop_routes() {
"camp", "training", "transfer", "tactics", "settings",
"scorers", "advertising", "stadium", "statistics", "environment",
"fairplay", "highscore", "contracts", "balance", "newplayer",
"news", "almanac"};
"news", "almanac"};
return value;
}
const std::vector<WidgetDefinition> &widget_definitions() {
@@ -144,6 +144,9 @@ bool valid_desktop(const Json &layout) {
for (const auto *key : {"x", "y", "w", "h"})
if (!o.at(key).is_number_integer() || o.at(key) < 0 || o.at(key) > 3840)
return false;
if (o.contains("z") &&
(!o.at("z").is_number_integer() || o.at("z") < 0 || o.at("z") > 9999))
return false;
if (!o.at("visible").is_boolean() || !o.at("pinned").is_boolean() ||
o.at("widget") != widget)
return false;
@@ -229,6 +232,7 @@ bool arrange_desktop(Json &layout) {
if (!valid_desktop(layout))
return false;
auto next = layout;
const bool original_grid = next.at("grid");
next["grid"] = true;
std::vector<std::string> loose;
for (auto &[id, o] : next["objects"].items())
@@ -248,6 +252,48 @@ bool arrange_desktop(Json &layout) {
return false;
o["visible"] = true;
}
next["grid"] = original_grid;
layout = std::move(next);
return true;
}
bool set_desktop_grid(Json &layout, bool enabled) {
if (!valid_desktop(layout))
return false;
auto next = layout;
next["grid"] = enabled;
if (enabled && !arrange_desktop(next))
return false;
layout = std::move(next);
return true;
}
bool add_desktop_widget(Json &layout, const std::string &id, int columns,
int rows) {
if (!valid_desktop(layout))
return false;
const auto it =
std::find_if(widget_definitions().begin(), widget_definitions().end(),
[&](const auto &d) { return d.id == id; });
if (it == widget_definitions().end() ||
layout.at("objects").at(id).at("visible") == true ||
std::find(it->sizes.begin(), it->sizes.end(), std::pair{columns, rows}) ==
it->sizes.end())
return false;
auto next = layout;
auto &o = next["objects"][id];
o["w"] = columns * pitch - gap;
o["h"] = rows * pitch - gap;
o["x"] = left;
o["y"] = top;
o["pinned"] = false;
if (!find_space(next, id, left, top, false)) {
if (next.at("grid") == true)
return false;
o["x"] = (3840 - o.at("w").get<int>()) / 2;
o["y"] = (2160 - o.at("h").get<int>()) / 2;
}
o["visible"] = true;
if (!valid_desktop(next))
return false;
layout = std::move(next);
return true;
}