From 42b728d4ea4414639bf32854c9db2453e41dae32 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 23 Oct 2026 19:43:15 +0200 Subject: [PATCH] Center native controls and preserve dropdown editing and focus (by Codex) --- assets/modern/icons/arrow-diagonal.svg | 2 + assets/modern/icons/calendar.svg | 2 + assets/modern/theme.rcss | 19 ++- docs/architecture.md | 8 + docs/new_ui/NATIVE_STATUS.md | 3 + docs/new_ui/README.md | 1 + docs/new_ui/typography-qa.md | 58 +++++++ src/app/main.cpp | 24 +-- src/modern/ui/CMakeLists.txt | 15 +- src/modern/ui/controls.hpp | 59 ++++++++ src/modern/ui/controls.inc | 99 ++++++++---- src/modern/ui/screens.inc | 29 +++- src/modern/ui/view.cpp | 87 +++++++++-- tests/modern_control_layout_tests.cpp | 199 +++++++++++++++++++++++++ 14 files changed, 541 insertions(+), 64 deletions(-) create mode 100644 assets/modern/icons/arrow-diagonal.svg create mode 100644 assets/modern/icons/calendar.svg create mode 100644 docs/new_ui/typography-qa.md create mode 100644 src/modern/ui/controls.hpp create mode 100644 tests/modern_control_layout_tests.cpp diff --git a/assets/modern/icons/arrow-diagonal.svg b/assets/modern/icons/arrow-diagonal.svg new file mode 100644 index 0000000..4b3680d --- /dev/null +++ b/assets/modern/icons/arrow-diagonal.svg @@ -0,0 +1,2 @@ + + diff --git a/assets/modern/icons/calendar.svg b/assets/modern/icons/calendar.svg new file mode 100644 index 0000000..b3d32fe --- /dev/null +++ b/assets/modern/icons/calendar.svg @@ -0,0 +1,2 @@ + + diff --git a/assets/modern/theme.rcss b/assets/modern/theme.rcss index 78f8bd6..8672671 100644 --- a/assets/modern/theme.rcss +++ b/assets/modern/theme.rcss @@ -25,6 +25,9 @@ body.matchday { #canvas {position:absolute;width:3840dp;height:2160dp;overflow:hidden;} button,input,select,textarea {font-family:Modern;color:var(--text);font-size:32dp;} button {padding:16dp 26dp;background-color:var(--soft);border:2dp var(--border);border-radius:14dp;cursor:pointer;text-align:center;tab-index:auto;} +.control-button {display:flex;align-items:center;justify-content:center;} +.control-label {display:block;} +.choice.control-button {justify-content:flex-start;} button:hover {background-color:var(--hover);} button:disabled,button[disabled] {opacity:0.4;cursor:default;tab-index:none;} button:focus-visible,input:focus-visible,select:focus-visible {border-color:var(--accent);} @@ -35,7 +38,9 @@ select {width:520dp;padding-right:45dp;} select selectvalue {padding-right:24dp;} select selectarrow {width:10dp;height:10dp;margin-right:-12dp;margin-top:6dp;border-bottom:2dp var(--muted);border-right:2dp var(--muted);transform:rotate(45deg);} select selectbox {padding:8dp;border:2dp var(--border);border-radius:12dp;background-color:var(--strong);max-height:760dp;} -select option {font-size:32dp;padding:12dp 20dp;min-height:42dp;} +select option {font-size:1em;padding:12dp 20dp;min-height:42dp;} +#manager-country,#manager-league,#manager-strength {height:88dp;font-size:30dp;} +#manager-strength {width:100%;} select option:hover,select option:checked {background-color:var(--selected);} scrollbarvertical {width:18dp;} scrollbarhorizontal {height:18dp;} @@ -71,13 +76,14 @@ h3 {font-size:31dp;font-weight:bold;} .brand span {color:#a9d5c9;} .main-options {position:absolute;left:308dp;top:764dp;width:1250dp;} .main-options button {display:block;width:100%;height:128dp;margin-bottom:18dp;padding:18dp 38dp;background-color:transparent;border-color:transparent;text-align:left;font-size:59dp;font-weight:normal;color:#d3dfe7;} +.main-options button {display:flex;align-items:center;justify-content:flex-start;} .main-options button:hover,.main-options button:focus {background-color:#b5dbd51a;border-color:#c6e3df26;color:#ecf9f4;} .main-options button:disabled {color:#7a8f9e;} .main-options small {font-size:25dp;margin-left:36dp;} .front-footer {position:absolute;left:346dp;right:180dp;bottom:140dp;display:flex;align-items:flex-end;justify-content:space-between;color:#bacdd7;} .front-footer p {font-size:29dp;} .front-footer small {font-size:22dp;color:#849dad;} -.window {position:absolute;left:560dp;top:60dp;width:2720dp;height:2040dp;overflow:hidden;border:2dp var(--border);border-radius:30dp;decorator:linear-gradient(155deg,var(--menu-top),var(--menu-bottom));backdrop-filter:blur(36dp);box-shadow:0dp 24dp 70dp #0008;} +.window {position:absolute;left:560dp;top:60dp;width:2720dp;height:2040dp;overflow:hidden;border:2dp var(--border);border-radius:30dp;decorator:linear-gradient(155deg,var(--menu-top),var(--menu-bottom));backdrop-filter:blur(36dp);box-shadow:0dp 12dp 36dp #0008;} .titlebar {position:absolute;left:0;top:0;width:100%;height:108dp;display:flex;align-items:center;padding:0 28dp;border-bottom:2dp var(--border);background-color:var(--soft);} .titlebar h1 {flex:1;text-align:center;margin-right:76dp;} .close {width:76dp;height:76dp;padding:0;border-width:0;background-color:transparent;} @@ -96,11 +102,15 @@ h3 {font-size:31dp;font-weight:bold;} .table .tr.odd {background-color:var(--soft);} .table .tr:hover {background-color:var(--hover);} .table button {background-color:transparent;border-width:0;padding:0;text-align:left;font-size:36dp;} +.table .control-button {justify-content:flex-start;} +.table .th.center .control-button {justify-content:center;} +.table .th button {font-size:30dp;} .club-label {display:flex;align-items:center;gap:20dp;} .club-label img {flex-shrink:0;} .rank {width:75dp;text-align:right;color:var(--muted);} .info-bar {position:absolute;left:0;top:0;width:100%;height:148dp;display:flex;align-items:center;gap:64dp;padding:0 64dp;border-bottom:2dp var(--border);decorator:linear-gradient(145deg,var(--desk-top),var(--desk-bottom));backdrop-filter:blur(48dp);} .identity {display:flex;align-items:center;gap:26dp;min-width:650dp;padding:0;background-color:transparent;border-width:0;text-align:left;} +.identity {justify-content:flex-start;} .identity strong {font-size:38dp;} .identity small {display:block;font-size:27dp;color:var(--muted);margin-top:8dp;} .info-date {margin-left:auto;min-width:430dp;font-size:34dp;} @@ -112,10 +122,14 @@ h3 {font-size:31dp;font-weight:bold;} .desktop-card.pinned {border-color:var(--border);} .card-heading {position:absolute;left:30dp;right:30dp;top:22dp;color:var(--muted);font-size:25dp;} .card-button {position:absolute;background-color:transparent;border-width:0;padding:0;} +.calendar-link {display:flex;align-items:center;gap:18dp;padding:18dp 28dp;justify-content:flex-start;} +.calendar-arrow {margin-left:auto;} .desktop-app {position:absolute;width:224dp;height:224dp;padding:0;background-color:transparent;border-width:0;text-align:center;} .app-tile {position:absolute;left:25dp;top:0;width:174dp;height:174dp;padding:12dp;border:2dp #e3efff59;border-radius:42dp;decorator:linear-gradient(140deg,#597d8e,#274956);box-shadow:0dp 12dp 25dp #0005;} .app-name {position:absolute;left:-20dp;top:190dp;width:264dp;font-size:29dp;color:#f6f8fa;} .desktop-app:hover .app-tile {background-color:#ffffff20;} +body.matchday .app-tile {border-radius:32dp;border-color:#dbdfe33d;} +body.silver .app-tile {border-color:#edf7ff99;} .pin-dot {position:absolute;right:16dp;top:16dp;width:14dp;height:14dp;border-radius:7dp;background-color:var(--accent);} .field-row {display:flex;align-items:center;justify-content:space-between;gap:28dp;min-height:112dp;padding:20dp 0;border-bottom:2dp var(--border);} .field-row label {flex:1;font-size:32dp;} @@ -133,6 +147,7 @@ h3 {font-size:31dp;font-weight:bold;} #toast {position:absolute;left:50%;bottom:20dp;width:1100dp;margin-left:-550dp;padding:18dp 30dp;border:2dp var(--border);border-radius:18dp;background-color:var(--strong);text-align:center;font-size:27dp;display:none;z-index:250;} #desktop-context {display:none;position:absolute;width:280px;padding:6px;border:1px var(--border);border-radius:12px;background-color:var(--strong);z-index:180;box-shadow:0px 8px 24px #0005;} #desktop-context button {display:block;width:100%;padding:9px 12px;border:0px;border-radius:6px;background-color:transparent;text-align:left;font-size:15px;} +#desktop-context .control-button {display:flex;justify-content:flex-start;} #desktop-context button:hover {background-color:var(--selected);} #desktop-context .separator {height:1px;margin:5px;background-color:var(--border);} .gallery-card {position:absolute;width:800dp;height:440dp;padding:30dp;} diff --git a/docs/architecture.md b/docs/architecture.md index 0f4e2b7..e6f8c6a 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -13,11 +13,19 @@ OpenBMH is a C++20 engine with graphical and console frontends. The implementati | `src/cli` | Command language, structured protocol, console windows and multi-client seat routing | | `src/audio` | Bank decoding, synthesis, playback and cues, without authority to change gameplay | | `src/launch` | RmlUI launcher, portable mod library, child processes and legacy installation discovery | +| `src/modern/ui` | Opt-in native Modern UI with a read-only world catalogue and a replaceable presentation data source | | `src/content` | Sealed OBW content, native career containers and personal preferences | | `src/import` | Legacy installation and save-layout conversion; original readers are used here | `bmhcore` contains the format and game layers. `bmhui`, `openbmh_audio` and the application session provide reusable pieces above it. Frontends should translate actions and display results; they should not introduce independent transfer, calendar or financial rules. +The experimental Modern frontend uses namespace `bmh::modern_ui`, preserving +the Modern season fork's existing lookup of `bmh::ui`. Its current `DemoSource` +owns presentation-only fixtures and separate JSON checkpoints; it neither +constructs a career nor starts matches. See [native UI status](new_ui/NATIVE_STATUS.md) +for the implemented slice and outstanding HTML transfers. Shared archive/image +helpers live in `bmh_asset_io`, without linking the editor GUI or MCP server. + ## Session boundary `CareerSession` owns the live game, the two random streams and progression state. Requests identify the manager and the revision they observed. Shared actions validate that identity, stage state and random effects, and publish supported results together. Rejected requests must not leave partial transactions. diff --git a/docs/new_ui/NATIVE_STATUS.md b/docs/new_ui/NATIVE_STATUS.md index 1c50f7c..26b181a 100644 --- a/docs/new_ui/NATIVE_STATUS.md +++ b/docs/new_ui/NATIVE_STATUS.md @@ -90,6 +90,9 @@ Synthetische Tests prüfen Katalog, HQ-Bildauswahl, ausländische Übernahmesper Revisionsschutz, Desktop-Grenzen/Fixierung/Größen und atomare Demostand- Wiederherstellung. Drei fensterlose RmlUI-Tests prüfen den Eintrittspreis in allen Themes, einschließlich doppelter Pixeldichte und abgewiesener Übernahme. +Die [dedizierte Schrift-QA](typography-qa.md) prüft zusätzlich Buttons und +Dropdowns gegen das HTML-Mockup, einschließlich tatsächlicher Textmitten, +Pixeldichten sowie Escape- und Fokusverhalten. Ein nativer Linux-/OpenGL-Durchlauf mit externem Diamond-Datensatz führt über das Hauptmenü, die Managerwahl und Auslosung zum Desktop, verändert den diff --git a/docs/new_ui/README.md b/docs/new_ui/README.md index 357c04d..545d407 100644 --- a/docs/new_ui/README.md +++ b/docs/new_ui/README.md @@ -9,6 +9,7 @@ Implementierung in der Spiel-Engine. |---|---| | Umsetzung | [Abgestimmter Umfang der nativen UI bis zum Anstoß](PLAN.md) | | Nativer Stand | [Unterbau, erster Durchlauf und noch offene Übertragungen](NATIVE_STATUS.md) | +| Schrift-QA | [Button-/Dropdown-Ausrichtung und unabhängiger Vergleich](typography-qa.md) | | Ressourcen | [GUI-Assets, Weltbilder und spätere Paketbereinigung](assets.md) | | Desktop | [Statusleiste, Gestaltung und Fenster](desktop/README.md) | | Eintrittspreis | [Kompakter Schieberegler im Konto-Widget](desktop/entry-price/README.md) | diff --git a/docs/new_ui/typography-qa.md b/docs/new_ui/typography-qa.md new file mode 100644 index 0000000..5b0d25f --- /dev/null +++ b/docs/new_ui/typography-qa.md @@ -0,0 +1,58 @@ +# Native Beschriftungen · Vergleich mit dem HTML-Mockup + +Stand: 23. Oktober 2026. Zwei dedizierte Sol-High-Agenten vergleichen Buttons +und Dropdowns unabhängig mit dem privaten HTML-Mockup. Die Prüfung betrifft +die bereits übertragenen nativen Ansichten; sie nimmt noch ausstehende Menüs +nicht vorweg. + +## Behobene Abweichungen + +Bei Full HD lagen die Fontboxen der acht Plus-/Minus-Buttons 8,4 Pixel über +der Mitte, die Footerbeschriftungen etwa 4,9 Pixel und die Lagerregionen +2,9 Pixel. Dropdowns mit vorgegebener Höhe zeigten denselben Fehler: +3,9 Pixel in Toolbars, 5,9 Pixel im Tabellenfooter. Die horizontalen +Ausrichtungen waren überwiegend bereits korrekt. + +- Einfache Buttonbeschriftungen bekommen ein ausdrückliches Text-`span` und + werden als Flexelement zentriert. Listen, Kontextmenüs und Hauptmenü bleiben + wie die Referenz linksbündig. Foto-/Themekarten behalten ihren eigenen Aufbau. +- RmlUI benötigt das ausdrückliche Textelement: Flex auf einem Button mit + anonymem Text lässt dessen Beschriftung in der verwendeten Version verschwinden. +- Dropdownbeschriftung und Pfeil richten sich nach der tatsächlichen Höhe + des Inhaltsbereichs. Der gemeinsame Helfer arbeitet nach dem RmlUI-Layout + mit physischen Pixeln und bleibt von Fenstergröße und Pixeldichte unabhängig. + Popupzeilen übernehmen die Schriftgröße des zugehörigen Auswahlfeldes. +- Die internen `selectvalue`-/`selectarrow`-Elemente sind keine DOM-Kinder. + Der Helfer berücksichtigt sie ausdrücklich; `QuerySelector` erreicht sie nicht. +- Escape schließt zuerst eine offene Auswahlliste und verwirft deren Entwurf. + Der übergeordnete Dialog bleibt offen. Pfeiltasten dürfen mehrere Optionen + durchlaufen; erst beim Schließen wird die Auswahl an die Ansicht übergeben. + Anschließend kehrt der Fokus zum Auswahlfeld zurück. +- Die Manager-Auswahlfelder entsprechen mit 88 logischen Pixeln Höhe und + 30 Pixeln Schrift der Referenz. Das Stärke-Feld nutzt die volle Spaltenbreite. +- Das fehlende Kalendersymbol für den diagonalen Pfeil wird durch ein eigenes + SVG ersetzt und hängt nicht mehr von der installierten Schrift ab. + +## Prüfungen und Grenzen + +Die dedizierte Button-Prüfung umfasst sechs Ansichten in allen drei Themes, +jeweils bei 1280 × 720 und 1920 × 1080: 36 native OpenGL-Aufnahmen vor und +nach der Korrektur. 144 Zielbeschriftungen liegen nach der Korrektur geometrisch +mittig; die 24 Beschriftungen der Einstellungsnavigation wurden zusätzlich +nachgeprüft. Die Dropdown-Prüfung umfasst Managerwahl, Einstellungen und +Tabellen in derselben Größen-/Themematrix, einschließlich langen Ligabezeichnungen, +Escape, mehrfacher Pfeiltasten-Auswahl und Fokus nach der Übernahme. + +`modern_control_layout_tests` verwendet den tatsächlichen Button-Helfer und +das Produktions-RCSS mit synthetischen Daten. Der Test misst Text-/Pfeilmitten, +prüft sichtbare Textzeilen, unveränderte Bildkarten und Popup-Schriftgrößen in +drei Themes bei vier Pixeldichten. Er ergänzt den echten Renderer-/HTML- +Vergleich und ersetzt ihn nicht. + +Screenshots, DOM-Ausgaben, Messdaten und Wiederholungsabläufe liegen im privaten +Mockup-Repository unter `docs/qa/native-rmlui-2026-10-23`. Die native Abnahme +unter Windows und macOS steht noch aus. Als weiterer Vergleichspunkt bleibt +das Platzieren kleiner Dropdown-Popups an der Glasfenstergrenze offen; RmlUI +berücksichtigt bisher die Bildschirmgrenze. +Die eigene Markierungsspalte für die ausgewählte Popupzeile ist ebenfalls noch +an die HTML-Vorlage anzugleichen. diff --git a/src/app/main.cpp b/src/app/main.cpp index 99b81f8..ea2948a 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -99,7 +99,7 @@ int main(int argc, char** argv) { const std::vector args = launch::utf8_arguments(argc, argv); // (file names beyond the code page) fs::path data, save_directory; #ifdef OPENBMH_MODERN_UI - modern_ui::Config modern_ui; + modern_ui::Config modern_config; bool modern_demo = false; #endif uint32_t seed = uint32_t(std::chrono::system_clock::now().time_since_epoch().count()); @@ -119,26 +119,26 @@ int main(int argc, char** argv) { if (is("--modern-ui-demo")) { modern_demo = true; } else if (is("--gui-assets") && value) { - modern_ui.gui_assets = launch::path_from_utf8(args[++i]); + modern_config.gui_assets = launch::path_from_utf8(args[++i]); } else if (is("--ui-scene") && value) { - modern_ui.scene = args[++i]; + modern_config.scene = args[++i]; } else if (is("--ui-theme") && value) { - modern_ui.theme = args[++i]; + modern_config.theme = args[++i]; } else if (is("--ui-screenshot") && value) { - modern_ui.screenshot = launch::path_from_utf8(args[++i]); + modern_config.screenshot = launch::path_from_utf8(args[++i]); modern_demo = true; } else if (is("--ui-script") && value) { - modern_ui.commands = launch::path_from_utf8(args[++i]); + modern_config.commands = launch::path_from_utf8(args[++i]); modern_demo = true; } else if (is("--ui-state") && value) { - modern_ui.state = launch::path_from_utf8(args[++i]); + modern_config.state = launch::path_from_utf8(args[++i]); } else if (is("--ui-size") && value) { const auto size = args[++i]; const auto separator = size.find('x'); if (separator == std::string::npos) throw std::runtime_error("--ui-size requires WIDTHxHEIGHT"); - modern_ui.width = std::stoi(size.substr(0, separator)); - modern_ui.height = std::stoi(size.substr(separator + 1)); - if (modern_ui.width < 960 || modern_ui.width > 7680 || modern_ui.height < 540 || modern_ui.height > 4320) + modern_config.width = std::stoi(size.substr(0, separator)); + modern_config.height = std::stoi(size.substr(separator + 1)); + if (modern_config.width < 960 || modern_config.width > 7680 || modern_config.height < 540 || modern_config.height > 4320) throw std::runtime_error("Unsupported Modern UI preview size"); } else #endif @@ -211,8 +211,8 @@ int main(int argc, char** argv) { throw FormatError("Spielstand konnte nicht übernommen werden: " + error); }; #ifdef OPENBMH_MODERN_UI - modern_ui.world = data; - return modern_ui::run(executable, migrate, modern_ui); + modern_config.world = data; + return modern_ui::run(executable, migrate, modern_config); #else return launch::run_launcher(executable, migrate); #endif diff --git a/src/modern/ui/CMakeLists.txt b/src/modern/ui/CMakeLists.txt index 8a370fb..3e144d7 100644 --- a/src/modern/ui/CMakeLists.txt +++ b/src/modern/ui/CMakeLists.txt @@ -6,7 +6,7 @@ add_library(bmh_modern_ui STATIC view.cpp ticket_popover.cpp) target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET}) if(MSVC) target_compile_options(bmh_modern_ui_core PRIVATE /W4 /utf-8) - target_compile_options(bmh_modern_ui PRIVATE /W4 /utf-8) + target_compile_options(bmh_modern_ui PRIVATE /W4 /utf-8 /bigobj) else() target_compile_options(bmh_modern_ui_core PRIVATE -Wall -Wextra -Wpedantic) target_compile_options(bmh_modern_ui PRIVATE -Wall -Wextra -Wpedantic) @@ -17,7 +17,12 @@ file(MAKE_DIRECTORY "${modern_assets}") foreach(asset modern.rml theme.rcss ticket.rcss) configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY) endforeach() -file(COPY "${CMAKE_SOURCE_DIR}/assets/modern/icons" DESTINATION "${modern_assets}") +file(GLOB modern_icons CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/icons/*.svg") +file(MAKE_DIRECTORY "${modern_assets}/icons") +foreach(icon ${modern_icons}) + get_filename_component(icon_name "${icon}" NAME) + configure_file("${icon}" "${modern_assets}/icons/${icon_name}" COPYONLY) +endforeach() foreach(weight Regular Bold) configure_file("${rmlui_SOURCE_DIR}/Samples/assets/LatoLatin-${weight}.ttf" "${modern_assets}/LatoLatin-${weight}.ttf" COPYONLY) @@ -44,3 +49,9 @@ endif() foreach(theme midnight silver matchday) add_test(NAME modern_ticket_${theme} COMMAND modern_ticket_document_tests "${modern_assets}" ${theme}) endforeach() +add_executable(modern_control_layout_tests ../../../tests/modern_control_layout_tests.cpp) +target_link_libraries(modern_control_layout_tests PRIVATE bmh_modern_ui_core RmlUi::Core) +if(MSVC) + target_compile_options(modern_control_layout_tests PRIVATE /utf-8) +endif() +add_test(NAME modern_control_layout_tests COMMAND modern_control_layout_tests "${modern_assets}") diff --git a/src/modern/ui/controls.hpp b/src/modern/ui/controls.hpp new file mode 100644 index 0000000..f655f34 --- /dev/null +++ b/src/modern/ui/controls.hpp @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include "modern/ui/catalog.hpp" +#include +#include + +namespace bmh::modern_ui { +inline Rml::Element *select_part(Rml::Element &select, const std::string &tag) { + // WidgetDropDown appends these as non-DOM children. QuerySelector excludes + // them. + for (int i = 0; i < select.GetNumChildren(true); ++i) + if (auto *child = select.GetChild(i); child->GetTagName() == tag) + return child; + return nullptr; +} +inline std::string button_markup(const std::string &action, + const std::string &label, + const std::string &css = {}, + const std::string &attributes = {}) { + // RmlUI needs an explicit flex item for text; anonymous text disappears. + const bool plain = label.find('<') == std::string::npos; + return ""; +} +inline bool center_selects(Rml::ElementDocument &document) { + bool changed = false; + Rml::ElementList controls; + document.QuerySelectorAll(controls, "select"); + const auto set_pixels = [&](Rml::Element *element, const char *name, + float value) { + const auto *old = element->GetLocalProperty(name); + if (old && old->unit == Rml::Unit::PX && + std::abs(old->Get() - value) < .02f) + return; + element->SetProperty(name, std::to_string(value) + "px"); + changed = true; + }; + for (auto *select : controls) { + if (!select->IsVisible(true)) + continue; + auto *caption = select_part(*select, "selectvalue"), + *arrow = select_part(*select, "selectarrow"); + const float height = select->GetBox().GetSize(Rml::BoxArea::Content).y; + if (height <= 0 || !caption || !arrow) + continue; + // WidgetDropDown fixes both offsets at the content-box top. A flex + // selectvalue loses its text in pinned RmlUI; center its line instead. + set_pixels(caption, "line-height", height); + set_pixels(arrow, "margin-top", + std::max(0.f, (height - + arrow->GetBox().GetSize(Rml::BoxArea::Border).y) / + 2)); + } + return changed; +} +} // namespace bmh::modern_ui diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index 88717ee..469e4ff 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -196,6 +196,18 @@ void App::ProcessEvent(Rml::Event &event) try { } } if (key == Rml::Input::KI_ESCAPE) { + Rml::ElementList selects; + doc_->QuerySelectorAll(selects, "select"); + for (auto *node : selects) + if (auto *select = dynamic_cast(node); + select && select->IsSelectBoxVisible()) { + select->CancelSelectBox(); + select->Focus(true); + event.StopImmediatePropagation(); + dirty_ = true; + return; + } + if (context_open_) { context_open_ = false; dirty_ = true; @@ -615,32 +627,39 @@ void App::dispatch(const std::string &action, Rml::Element *target) { message("Die Dateiauswahl konnte nicht geöffnet werden."); return; } - try { - auto candidate = Catalog::open(editor::path(chosen.get())); - std::string name = candidate->title(); - launch::ModLibrary::validate_name(name); - const auto destination = root_ / "mods" / editor::path(name); - if (fs::exists(destination)) - throw std::runtime_error( - "Eine Mod mit diesem Namen ist bereits vorhanden."); - fs::create_directories(destination.parent_path()); - const auto staging = destination.parent_path() / - (".ui-import-" + std::to_string(SDL_GetTicks64())); - fs::create_directory(staging); - try { - fs::copy_file(editor::path(chosen.get()), staging / "content.obw"); - (void)Catalog::open(staging / "content.obw"); - fs::rename(staging, destination); - } catch (...) { - fs::remove_all(staging); - throw; - } - collect_mods(); - selected_mod_ = name; - refresh(); - } catch (const std::exception &e) { - message(e.what()); - } + const auto file = editor::path(chosen.get()); + auto candidate = Catalog::open(file); + auto initial = candidate->title(); + for (char &c : initial) + if (std::string("/\\:*?\"<>|").find(c) != std::string::npos) + c = '-'; + if (initial.empty()) + initial = "Modern"; + text_dialog("Bezeichnung der neuen Mod", initial, + [this, file](const std::string &name) { + launch::ModLibrary::validate_name(name); + const auto destination = root_ / "mods" / editor::path(name); + if (fs::exists(destination)) + throw editor::Error( + "Eine Mod mit diesem Namen ist bereits vorhanden."); + fs::create_directories(destination.parent_path()); + const auto staging = + destination.parent_path() / + (".ui-import-" + std::to_string(SDL_GetTicks64())); + if (!fs::create_directory(staging)) + throw editor::Error("Import wird bereits vorbereitet."); + try { + fs::copy_file(file, staging / "content.obw"); + (void)Catalog::open(staging / "content.obw"); + fs::rename(staging, destination); + } catch (...) { + fs::remove_all(staging); + throw; + } + collect_mods(); + selected_mod_ = name; + refresh(); + }); return; } if (action == "import-classic") { @@ -660,11 +679,16 @@ void App::dispatch(const std::string &action, Rml::Element *target) { request.name = game.family == launch::GameFamily::english ? "FTDL-classic" : "BMH-classic"; request.migrate = false; - launch::ModLibrary library(root_); - library.add(request, migrate_); - collect_mods(); - selected_mod_ = request.name; - refresh(); + text_dialog("Bezeichnung der neuen Mod", request.name, + [this, request](const std::string &name) mutable { + launch::ModLibrary::validate_name(name); + request.name = name; + launch::ModLibrary library(root_); + library.add(request, migrate_); + collect_mods(); + selected_mod_ = name; + refresh(); + }); } catch (const std::exception &e) { message(e.what()); } @@ -1032,6 +1056,19 @@ void App::change(Rml::Element *target) { if (!control) return; const auto value = control->GetValue(); + if (auto *select = dynamic_cast(target); + select && select->IsSelectBoxVisible()) { + pending_selects_.insert(target->GetId()); + return; + } + if ((kind == "manager-country" || kind == "table-country") && + value == country_) + return; + if ((kind == "manager-league" || kind == "table-league") && value == league_) + return; + if (kind == "manager-country" || kind == "manager-league" || + kind == "table-country" || kind == "table-league") + focus_after_render_ = target->GetId(); if (kind == "manager-country" || kind == "manager-league") { if (!manager_picker_) selections_["manager-name"] = field("manager-name"); diff --git a/src/modern/ui/screens.inc b/src/modern/ui/screens.inc index 69fe958..c054245 100644 --- a/src/modern/ui/screens.inc +++ b/src/modern/ui/screens.inc @@ -34,7 +34,12 @@ std::string App::widget(const std::string &id, const Json &o) { "style=\"font-size:240dp;line-height:1.1;\">" + std::to_string(std::stoi(day)) + "

" + esc(date) + "

" + - btn("open:calendar", "Kalender öffnen ↗", "card-button", + btn("open:calendar", + glyph("calendar", 32) + + "Kalender öffnen" + + glyph("arrow-diagonal", 30) + "", + "card-button calendar-link", "style=\"left:0;bottom:0;width:100%;height:90dp;border-top:2dp " "var(--border);font-size:25dp;color:var(--muted);\""); } @@ -203,10 +208,25 @@ std::string App::render_desktop() { ""; else { const auto route = id.substr(4); + const std::array colors = { + "#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0", + "#517d71", "#668a98", "#af6860", "#6b809c", "#657cb3", "#507b9c", + "#559b76", "#a7474e", "#967d50", "#648f91", "#54856b", "#558f93", + "#6379a3", "#788598", "#8d7856", "#a66d64", "#748474", "#6887a2", + "#6b9270", "#7c8b9c", "#ac8b52", "#7783a4", "#648f83", "#927d9d", + "#ac5e63"}; + const auto i = std::find(routes.begin(), routes.end(), route); + const auto color = colors[size_t(i - routes.begin())]; + const auto top = theme_ == "matchday" ? mixed_color(color, "#27282e", .55) + : mixed_color(color, "#c5ddf1", .1); + const auto bottom = + theme_ == "matchday" ? "#272a30" : mixed_color(color, "#07111e", .38); out += ""; + return button_markup(action, label, css, attrs); } const std::array routes = { "tables", "league", "strengths", "lineup", "achievements", @@ -84,6 +96,14 @@ std::string title(const std::string &route) { const auto i = std::find(routes.begin(), routes.end(), route); if (i != routes.end()) return titles[size_t(i - routes.begin())]; + if (route == "widgets") + return "Widget hinzufügen"; + if (route == "view-save") + return "Ansicht speichern"; + if (route == "view-load") + return "Ansicht laden"; + if (route == "background") + return "Hintergrundbild ändern"; if (route == "newgame") return "Neues Spiel"; if (route == "mods") @@ -149,13 +169,22 @@ public: return {}; raster = editor::images::decode(bytes.first, bytes.second, pixels); } else if (key.starts_with("icon.")) { - const auto name = key.substr(5); + auto name = key.substr(5); + const bool ink = name.ends_with("-ink"); + if (ink) + name.resize(name.size() - 4); if (name.empty() || name.find_first_not_of("abcdefghijklmnopqrstuvwxyz-") != name.npos) return {}; - raster = editor::images::decode( - editor::read_file(assets_ / "icons" / (name + ".svg")), ".svg", - pixels); + auto svg = editor::read_file(assets_ / "icons" / (name + ".svg")); + if (ink) { + size_t at = 0; + while ((at = svg.find("#dceae7", at)) != std::string::npos) { + svg.replace(at, 7, "#426071"); + at += 7; + } + } + raster = editor::images::decode(svg, ".svg", pixels); } else if (gui_.contains(key)) raster = gui_.decode(key, pixels); else if (key == "background") @@ -244,6 +273,8 @@ class App final : public Rml::EventListener { std::unique_ptr source_; std::unique_ptr ticket_; bool focus_ticket_ = false; + std::set pending_selects_; + std::string focus_after_render_; float device_ratio_ = 1.f; Json desktop_ = Json::object(), saved_desktop_ = Json::object(), options_ = Json::object(); @@ -334,7 +365,8 @@ class App final : public Rml::EventListener { return c ? img(c->value("crest", ""), size, size, true) : ""; } std::string glyph(const std::string &name, double size) { - return img("icon." + name, size, size, false, false, int(size)); + return img("icon." + name + (theme_ == "silver" ? "-ink" : ""), size, size, + false, false, int(size)); } std::string label(const Json *c, double size = 40) { return c ? "" + crest(c, size) + "" + @@ -466,7 +498,9 @@ class App final : public Rml::EventListener { {"exit", "Beenden"}}}; for (const auto &[key, name] : actions) out += btn( - key, esc(name) + (key == "network" ? "Demnächst" : ""), + key, + (key == "network" ? "" + esc(name) + "" : esc(name)) + + (key == "network" ? "Demnächst" : ""), {}, key == "network" || (key == "new" && !m && !world_) ? "disabled" : ""); @@ -534,6 +568,19 @@ class App final : public Rml::EventListener { std::string render_menu(const std::string &); void dispatch(const std::string &, Rml::Element *); void change(Rml::Element *); + void flush_selects() { + std::vector ready; + for (const auto &id : pending_selects_) { + auto *select = dynamic_cast(element(id)); + if (!select || !select->IsSelectBoxVisible()) + ready.push_back(id); + } + for (const auto &id : ready) { + pending_selects_.erase(id); + if (auto *select = element(id)) + change(select); + } + } void input(Rml::Element *); void resize() { int w, h, pw, ph; @@ -594,6 +641,11 @@ class App final : public Rml::EventListener { n->Focus(); focus_ticket_ = false; } + if (!focus_after_render_.empty()) { + if (auto *node = element(focus_after_render_)) + node->Focus(true); + focus_after_render_.clear(); + } } void render_popup() { if (popup_.empty()) { @@ -626,6 +678,7 @@ class App final : public Rml::EventListener { button->Focus(); } void frame() { + flush_selects(); if (ticket_) ticket_->update(); if (needs_render_) @@ -633,6 +686,8 @@ class App final : public Rml::EventListener { render_popup(); render_context(); context_->Update(); + if (center_selects(*doc_)) + context_->Update(); renderer_.Clear(); renderer_.BeginFrame(); context_->Render(); @@ -728,12 +783,15 @@ public: {"click", "dblclick", "change", "input", "keydown", "mousedown", "mouseup", "mousemove", "contextmenu"}) doc_->AddEventListener(event, this); - if(!config_.theme.empty())theme_ = config_.theme; - if(theme_!="midnight"&&theme_!="silver"&&theme_!="matchday")throw editor::Error("Unbekanntes Modern-Theme."); + if (!config_.theme.empty()) + theme_ = config_.theme; + if (theme_ != "midnight" && theme_ != "silver" && theme_ != "matchday") + throw editor::Error("Unbekanntes Modern-Theme."); collect_mods(); if (!mods_.empty()) active_mod_ = mods_.front().name; if (!config_.world.empty()) { + active_mod_.clear(); load_world(config_.world); scene_ = config_.scene; if (scene_ != "main" && scene_ != "newgame" && scene_ != "manager" && @@ -745,10 +803,13 @@ public: if (!config_.state.empty() && source_) { desktop_ = source_->load(config_.state); saved_desktop_ = desktop_; - if(config_.theme.empty())theme_ = snap().state.at("preferences").value("theme", theme_); + if (config_.theme.empty()) + theme_ = snap().state.at("preferences").value("theme", theme_); } - if(source_&&!config_.theme.empty()){ - auto preferences=snap().state.at("preferences");preferences["theme"]=theme_;apply("preferences",preferences); + if (source_ && !config_.theme.empty()) { + auto preferences = snap().state.at("preferences"); + preferences["theme"] = theme_; + apply("preferences", preferences); } if (scene_ == "manager" && selections_["manager-name"].empty()) selections_["manager-name"] = "Alex Berger"; diff --git a/tests/modern_control_layout_tests.cpp b/tests/modern_control_layout_tests.cpp new file mode 100644 index 0000000..948f572 --- /dev/null +++ b/tests/modern_control_layout_tests.cpp @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Exercise the production control builder and stylesheet with synthetic labels. +#include "modern/ui/controls.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace bmh::modern_ui; +namespace { +void require(bool value, const char *message) { + if (!value) + throw std::runtime_error(message); +} +struct Renderer final : Rml::RenderInterface { + Rml::CompiledGeometryHandle CompileGeometry(Rml::Span, + Rml::Span) override { + return 1; + } + void RenderGeometry(Rml::CompiledGeometryHandle, Rml::Vector2f, + Rml::TextureHandle) override {} + void ReleaseGeometry(Rml::CompiledGeometryHandle) override {} + Rml::TextureHandle LoadTexture(Rml::Vector2i &, + const Rml::String &) override { + return 0; + } + Rml::TextureHandle GenerateTexture(Rml::Span, + Rml::Vector2i) override { + return 1; + } + void ReleaseTexture(Rml::TextureHandle) override {} + void EnableScissorRegion(bool) override {} + void SetScissorRegion(Rml::Rectanglei) override {} +}; +void text_centers(Rml::Element &node, float cx, float cy, bool horizontal, + size_t &lines) { + if (auto *text = dynamic_cast(&node)) { + const auto origin = text->GetAbsoluteOffset(); + const auto metrics = Rml::GetFontEngineInterface()->GetFontMetrics( + text->GetFontFaceHandle()); + for (const auto &line : text->GetLines()) { + if (line.text.empty()) + continue; + ++lines; + const float x = origin.x + line.position.x + line.width / 2.f; + const float y = origin.y + line.position.y - metrics.ascent + + (metrics.ascent + metrics.descent) / 2.f; + require(std::abs(y - cy) <= .8f, + "Control text is not vertically centered"); + if (horizontal) + require(std::abs(x - cx) <= .8f, + "Control text is not horizontally centered"); + } + } + for (int i = 0; i < node.GetNumChildren(); ++i) + text_centers(*node.GetChild(i), cx, cy, horizontal, lines); +} +void centered_text(Rml::Element &text_root, Rml::Element &control, + bool horizontal = true) { + const auto p = control.GetAbsoluteOffset(Rml::BoxArea::Border), + s = control.GetBox().GetSize(Rml::BoxArea::Border); + size_t lines = 0; + text_centers(text_root, p.x + s.x / 2, p.y + s.y / 2, horizontal, lines); + require(lines == 1, "A control label disappeared or wrapped"); +} +} // namespace +int main(int argc, char **argv) try { + require(argc == 2, "Pass the Modern asset directory"); + const auto root = std::filesystem::path(argv[1]); + Renderer renderer; + Rml::SystemInterface system; + Rml::SetRenderInterface(&renderer); + Rml::SetSystemInterface(&system); + require(Rml::Initialise(), "Rml initialization"); + require(Rml::LoadFontFace((root / "LatoLatin-Regular.ttf").string(), "Modern", + Rml::Style::FontStyle::Normal, + Rml::Style::FontWeight::Normal), + "Font missing"); + require(Rml::LoadFontFace((root / "LatoLatin-Bold.ttf").string(), "Modern", + Rml::Style::FontStyle::Normal, + Rml::Style::FontWeight::Bold), + "Bold font missing"); + std::ifstream input(root / "theme.rcss"); + std::ostringstream css; + css << input.rdbuf(); + for (const auto *theme : {"midnight", "silver", "matchday"}) + for (float density : {1.f / 3, .5f, 1.f, 2.f}) { + auto *context = Rml::CreateContext( + "controls", {int(3840 * density), int(2160 * density)}); + require(context, "Context missing"); + context->SetDensityIndependentPixelRatio(density); + const auto select = [](const std::string &id) { + return ""; + }; + std::string content = + button_markup("decrease", "−", {}, + "id='step' " + "style='position:absolute;left:40dp;top:40dp;width:" + "94dp;height:124dp;font-size:72dp;padding:0;' "); + content += button_markup( + "region", "Region", {}, + "id='region' " + "style='position:absolute;left:200dp;top:40dp;min-height:86dp;' "); + content += button_markup("list", "Sample slot", "choice", + "id='list' " + "style='position:absolute;left:40dp;top:220dp;" + "width:600dp;height:120dp;text-align:left;' "); + content += button_markup( + "rich", + "
Image

Portrait

", + "choice", + "id='rich' " + "style='position:absolute;left:700dp;top:40dp;width:250dp;height:" + "260dp;' "); + content += + "
" + + select("natural") + + "
" + + select("toolbar") + + "
" + + select("manager-strength") + "
" + + button_markup("continue", "Continue", {}, "id='footer'") + + select("tall") + "
"; + auto *doc = context->LoadDocumentFromMemory( + "" + content + ""); + require(doc, "Document missing"); + doc->Show(); + context->Update(); + context->Render(); + for (int i = 0; i < 3; ++i) { + if (center_selects(*doc)) + context->Update(); + context->Render(); + } + require(!center_selects(*doc), "Control centering does not settle"); + for (const auto *id : {"step", "region", "footer"}) { + auto *button = doc->GetElementById(id); + require(button, "Button missing"); + centered_text(*button, *button); + } + auto *list = doc->GetElementById("list"); + centered_text(*list, *list, false); + auto *rich = doc->GetElementById("rich"); + require(!rich->IsClassSet("control-button"), + "Rich card became a horizontal text control"); + require(rich->QuerySelector(".caption")->GetAbsoluteOffset().y > + rich->QuerySelector(".picture")->GetAbsoluteOffset().y, + "Rich card stacking changed"); + for (const auto *id : + {"natural", "toolbar", "tall", "manager-strength"}) { + auto *control = doc->GetElementById(id); + auto *caption = select_part(*control, "selectvalue"), + *arrow = select_part(*control, "selectarrow"); + require(caption && arrow, "Select parts missing"); + centered_text(*caption, *control, false); + const auto y = control->GetAbsoluteOffset(Rml::BoxArea::Border).y + + control->GetBox().GetSize(Rml::BoxArea::Border).y / 2; + require(std::abs(arrow->GetAbsoluteOffset(Rml::BoxArea::Border).y + + arrow->GetBox().GetSize(Rml::BoxArea::Border).y / 2 - + y) < .8f, + "Dropdown arrow is off center"); + auto *select_control = + dynamic_cast(control); + select_control->ShowSelectBox(); + context->Update(); + context->Render(); + auto *option = select_control->GetOption(0); + require(option->GetComputedValues().font_size() == + control->GetComputedValues().font_size(), + "Dropdown popup font differs from its caption"); + require(option->GetComputedValues().line_height().value < + control->GetBox().GetSize(Rml::BoxArea::Content).y || + std::string(id) == "natural", + "Caption centering leaked into popup rows"); + select_control->CancelSelectBox(); + context->Update(); + } + doc->Close(); + Rml::RemoveContext("controls"); + } + Rml::Shutdown(); + std::cout << "Control text, dropdown arrows, popup fonts and rich cards " + "passed in 3 themes at 4 densities\n"; +} catch (const std::exception &e) { + std::cerr << e.what() << '\n'; + return 1; +}