Unify Modern dropdown menus with Gold layout and safe keyboard selection (by Codex)

This commit is contained in:
Codex committed 2026-10-26 13:45:19 +01:00
1 parent e81ecf95f2
commit fff2cc2f0b
18 files changed
+1361 -17

No files matched your search

+2 -2
View File
@@ -52,9 +52,9 @@ jobs:
- name: Configure opt-in UI without external assets
run: cmake -S . -B build-ui -G Ninja -DCMAKE_BUILD_TYPE=Release -DOPENBMH_BUILD_MODERN_UI=ON -DOPENBMH_BUILD_EDITOR=OFF -DBMH_DATA=
- name: Compile native frontend and synthetic checks
run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_stadium_ui_tests modern_statistics_ui_tests modern_news_ui_tests modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests modern_mods_ui_tests modern_entry_ui_tests modern_opening_ui_tests --parallel 2
run: cmake --build build-ui --target openbmh_play modern_ui_core_tests modern_ticket_document_tests modern_control_layout_tests modern_reports_tests modern_planning_tests modern_almanac_ui_tests modern_finance_ui_tests modern_environment_ui_tests modern_advertising_ui_tests modern_toto_ui_tests modern_lineup_ui_tests modern_transfer_ui_tests modern_career_reports_tests modern_rankings_tests modern_stadium_ui_tests modern_statistics_ui_tests modern_news_ui_tests modern_settings_ui_tests modern_desktop_ui_tests modern_files_ui_tests modern_mods_ui_tests modern_entry_ui_tests modern_opening_ui_tests modern_select_menu_tests --parallel 2
- name: Check controls, fonts, density and draft cancellation
run: ctest --test-dir build-ui -R "^modern_(ui_|ticket_|control_|reports_|planning_|almanac_ui_|finance_ui_|environment_ui_|advertising_ui_|toto_ui_|lineup_ui_|transfer_ui_|career_reports_|rankings_|stadium_ui_|statistics_ui_|news_ui_|settings_ui_|desktop_ui_|files_ui_|mods_ui_|entry_ui_|opening_ui_)" --output-on-failure --output-junit modern-ui-results.xml
run: ctest --test-dir build-ui -R "^modern_(ui_|ticket_|control_|reports_|planning_|almanac_ui_|finance_ui_|environment_ui_|advertising_ui_|toto_ui_|lineup_ui_|transfer_ui_|career_reports_|rankings_|stadium_ui_|statistics_ui_|news_ui_|settings_ui_|desktop_ui_|files_ui_|mods_ui_|entry_ui_|opening_ui_|select_menu_)" --output-on-failure --output-junit modern-ui-results.xml
- name: Upload test report
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+1 -1
View File
@@ -1,6 +1,6 @@
<rml>
<head><title>OpenBMH</title><link type="text/rcss" href="theme.rcss"/><link type="text/rcss" href="ticket.rcss"/><link type="text/rcss" href="sports.rcss"/><link type="text/rcss" href="calendar.rcss"/><link type="text/rcss" href="reports.rcss"/><link type="text/rcss" href="report_details.rcss"/><link type="text/rcss" href="report_pickers.rcss"/><link type="text/rcss" href="indoor.rcss"/><link type="text/rcss" href="planning.rcss"/><link type="text/rcss" href="almanac.rcss"/><link type="text/rcss" href="finance.rcss"/>
<link type="text/rcss" href="bank.rcss"/><link type="text/rcss" href="contracts.rcss"/><link type="text/rcss" href="amount.rcss"/><link type="text/rcss" href="environment.rcss"/><link type="text/rcss" href="advertising.rcss"/><link type="text/rcss" href="toto.rcss"/><link type="text/rcss" href="lineup.rcss"/><link type="text/rcss" href="transfer.rcss"/><link type="text/rcss" href="career_reports.rcss"/><link type="text/rcss" href="rankings.rcss"/><link type="text/rcss" href="stadium.rcss"/><link type="text/rcss" href="statistics.rcss"/><link type="text/rcss" href="news.rcss"/><link type="text/rcss" href="settings.rcss"/><link type="text/rcss" href="widgets.rcss"/><link type="text/rcss" href="files.rcss"/><link type="text/rcss" href="front.rcss"/><link type="text/rcss" href="entry.rcss"/><link type="text/rcss" href="opening.rcss"/></head>
<link type="text/rcss" href="bank.rcss"/><link type="text/rcss" href="contracts.rcss"/><link type="text/rcss" href="amount.rcss"/><link type="text/rcss" href="environment.rcss"/><link type="text/rcss" href="advertising.rcss"/><link type="text/rcss" href="toto.rcss"/><link type="text/rcss" href="lineup.rcss"/><link type="text/rcss" href="transfer.rcss"/><link type="text/rcss" href="career_reports.rcss"/><link type="text/rcss" href="rankings.rcss"/><link type="text/rcss" href="stadium.rcss"/><link type="text/rcss" href="statistics.rcss"/><link type="text/rcss" href="news.rcss"/><link type="text/rcss" href="settings.rcss"/><link type="text/rcss" href="widgets.rcss"/><link type="text/rcss" href="files.rcss"/><link type="text/rcss" href="front.rcss"/><link type="text/rcss" href="entry.rcss"/><link type="text/rcss" href="opening.rcss"/><link type="text/rcss" href="select_menu.rcss"/></head>
<body class="midnight">
<div id="background"></div>
<div id="canvas"></div>
+18
View File
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/* The visible trigger is the real RmlUI select. Only its list is adapted. */
body {--select-popup:#293744;--select-league-popup:#293744fa;--select-popup-border:#d9e8f13d;--select-popup-hover:#6286a855;}
body.silver {--select-popup:#f3f7fcfc;--select-league-popup:#f3f7fcfc;--select-popup-border:var(--border);--select-popup-hover:var(--hover);}
body.matchday {--select-popup:#303037fc;--select-league-popup:#303037fc;--select-popup-border:var(--border);--select-popup-hover:var(--hover);}
select {border-radius:12dp;}
select selectvalue {white-space:nowrap;}
select selectarrow {width:10dp;height:10dp;border-bottom:2dp var(--muted);border-right:2dp var(--muted);transform:rotate(45deg);}
.native-select-menu {position:absolute;z-index:1000;display:block;width:360dp;max-height:480dp;padding:10dp;overflow-y:auto;overflow-x:hidden;border:2dp var(--select-popup-border);border-radius:16dp;background-color:var(--select-popup);box-shadow:0dp 18dp 55dp #0008;color:var(--text);}
.native-select-menu.league {padding:10dp;border-radius:18dp;background-color:var(--select-league-popup);max-height:740dp;}
.native-select-menu>.native-select-option {display:flex;align-items:center;justify-content:flex-start;gap:12dp;width:100%;min-height:72dp;margin:0;padding:10dp 14dp;border:0dp;border-radius:8dp;background-color:transparent;color:var(--text);text-align:left;font-size:1em;line-height:1.3;tab-index:none;}
.native-select-menu.league>.native-select-option {gap:12dp;padding:10dp 14dp;border-radius:10dp;}
.native-select-menu>.native-select-option:hover,.native-select-menu>.native-select-option.is-cursor,.native-select-menu>.native-select-option:focus {background-color:var(--select-popup-hover);}
.native-select-menu>.native-select-option:disabled {opacity:0.4;cursor:default;background-color:transparent;}
.native-select-check {display:flex;align-items:center;justify-content:center;width:28dp;min-width:28dp;flex-shrink:0;color:var(--accent);}
.native-select-menu.league .native-select-check {width:34dp;min-width:34dp;}
.native-select-check>.image-frame {flex-shrink:0;}
.native-select-text {display:block;min-width:0;flex:1;white-space:nowrap;}
+1 -1
View File
@@ -105,7 +105,7 @@ body.silver .desk-calendar-month {background-color:#b76264;}body.matchday .desk-
.gallery-preview-card {position:absolute;transform-origin:50% 50%;pointer-events:none;backdrop-filter:none;}
.gallery-description {padding:22dp 6dp 16dp;}.gallery-description>small {display:block;font-size:21dp;color:var(--muted);}.gallery-description h2 {font-size:31dp;font-weight:bold;margin:10dp 0;}.gallery-description p {font-size:24dp;color:var(--muted);margin:0;line-height:1.3;}
.gallery-actions {position:absolute;left:24dp;right:24dp;bottom:24dp;display:flex;align-items:center;justify-content:space-between;gap:14dp;}
.gallery-actions select {width:200dp;font-size:25dp;padding:14dp 18dp;height:64dp;}
.gallery-actions select {width:200dp;font-size:28dp;padding:14dp 18dp;height:64dp;}
.gallery-actions button {display:flex;align-items:center;justify-content:center;gap:12dp;width:420dp;padding:14dp 18dp;font-size:25dp;height:64dp;}
.gallery-actions button>span {display:block;flex-shrink:0;}
.widget-gallery-empty {padding:180dp 50dp;text-align:center;font-size:34dp;color:var(--muted);}
+3
View File
@@ -7,6 +7,9 @@ wird ausdrücklich mit `OPENBMH_BUILD_MODERN_UI=ON` gebaut.
## Vorhanden
- [Gemeinsame Auswahlmenüs](controls/selects/README.md) für alle bestehenden
nativen Selects: echte Werte, getrennte Cursorwahl, bestätigter Commit,
Abbrechen ohne Änderung und drei Popup-Paletten.
- Gemeinsamer SDL2-/RmlUI-Unterbau mit den vorhandenen OpenGL-/Direct3D-
Renderern, den drei Farbpaletten und dem 2720 × 2040 großen 4:3-Fenster.
- Schreibgeschützter OBW-Katalog für Diamond Modern: Vereine, Ligen, Spieler,
+1
View File
@@ -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) |
| Auswahlmenüs | [Gemeinsame Listen, Tastatur und Übernahme](controls/selects/README.md) |
| Schrift-QA | [Button-/Dropdown-Ausrichtung und unabhängiger Vergleich](typography-qa.md) |
| Menü-QA | [Wiederholbarer Gesamtkatalog und Meilenstein-Abnahme](menu-qa.md) |
| QA-Befunde | [Offene Abweichungen zur HTML-Referenz](qa-findings.md) |
+78
View File
@@ -0,0 +1,78 @@
# Gemeinsame Auswahlmenüs
Die native Modern-UI behält ihre sichtbaren `ElementFormControlSelect`-Felder
als einzige Wertquelle. Der neue `SelectMenu`-Adapter stellt ausschließlich die
geöffnete Liste als RmlUI-Elemente im bestehenden Canvas dar, entsprechend dem
privaten HTML-Mockup `scaled-select.js`. Es gibt keine versteckten zweiten
Formulare, keine zusätzliche Laufzeitbibliothek und keinen eigenen Grafikrenderer.
Classic und Editor bleiben unverändert.
## Darstellung und Grenzen
Schriftgröße und Wert stammen aus dem echten Feld. Die Liste verwendet eine
feste Auswahlspalte, die vorhandene SVG-Checkmarkierung, gekapselte Textspans,
Hover-/Fokuszeilen und die tatsächlich angewandten Midnight-/Silver-/Matchday-
Farben. Optionstexte werden einmal als RML dekodiert und anschließend sicher
als Text ausgegeben; Zeichen wie `&`, `<` und Anführungszeichen bleiben erhalten.
Managerfelder verwenden die Maße der HTML-League-Picker: Auswahlspalte 34,
Radius 18 und höchstens 740 logische Einheiten. Die übrigen Listen verwenden
Auswahlspalte 28, Radius 16 und höchstens 480. Zeilen sind mindestens 72 hoch.
Aufstellungsschützen begrenzen die Liste zusätzlich auf 280. Die Widget-
Größenauswahl verwendet die Referenzschriftgröße 28. Popupbreite und Öffnungsrichtung
richten sich nach dem verfügbaren Fensterplatz; die Liste kann nach oben öffnen.
Sie bleibt innerhalb des Fensters und kann lange Optionslisten scrollen.
## Eingabe und Übernahme
Pfeile, Pos1, Ende und Typeahead bewegen nur den Cursor. Enter, Leertaste oder
Mausklick bestätigen. Escape, Tab und Außenklick verwerfen die Cursorwahl;
Rechtsklick schließt zuerst nur die Liste. Gesperrte Optionen werden übersprungen.
Typeahead verarbeitet die tatsächlichen Textinput-Ereignisse und die gängigen
lateinischen Groß-/Kleinbuchstaben einschließlich Umlauten. Das Eingabesystem
wird während einer offenen Liste aktiviert und beim Schließen an normale
Textfelder zurückgegeben.
Erst beim Commit setzt der Adapter den echten Select-Wert. Ein geänderter
Index erzeugt dessen vorhandenes `change` genau einmal. Eine ausdrückliche
Neuwahl desselben Eintrags wird getrennt gemeldet; programmatisches Befüllen
und Abbrechen zählen nicht als Benutzercommit. Im Managerformular setzt die
Neuwahl eines Landes die erste Liga und den ersten freien Verein; eine
Liga-Neuwahl wählt deren ersten freien Verein. Im Vereinspicker bleibt dies
Browsing, bis tatsächlich ein Verein angeklickt wird. Ausländische Vereine
bleiben wie vereinbart gesperrt.
Vor DOM-Neuaufbau, bei verschwundenem/gesperrtem Besitzer oder veralteten
Optionen wird die Liste ohne Übernahme geschlossen. Sie hält beobachtete
Elementreferenzen statt ungesicherter DOM-Zeiger. Tab entfernt sein Ereignisziel
erst nach der laufenden Ereignisverarbeitung. Ein Beenden-Dialog hat Vorrang
vor der Managerwahl und hält den Tastaturfokus in seinen eigenen Buttons.
## Bestehende Fachverträge
Alle neun Select-Erzeuger nutzen denselben Adapter: Managerwahl, Einstellungen,
Spielertraining, Banklaufzeit, Aufstellungsschützen, Transferangebote/-filter,
Abwerben und Widgetgrößen. Die bereits angepassten Button-Picker der Tabellen,
Statistiken und Kalender bleiben erhalten.
Einstellungen ändern zunächst ihren Entwurf und werden erst mit Anwenden
veröffentlicht. Gleiches gilt für Transferangebote und Suchfilter. Bei Training,
Schützen und Kreditlaufzeit bleibt der bisherige direkte UI-Democommit nach
bestätigter Wahl erhalten. Eine Widgetgröße ändert zunächst nur die Galerie-
Auswahl. Browsen und Abbrechen ändern diese Werte nicht. Der Adapter berechnet
keine Spielregel und ruft keine Engine auf.
## Prüfung
`modern_select_menu_tests` verwendet echte RmlUI-Eingaben und Produktionsstyles
in drei Themes bei vier Dichten. Geprüft werden Ereigniszählung, Commit/Neuwahl,
Abbruch, Unicode-Eingaben, Fokus, Scrollen, Fenstergrenzen, Schriftgrößen,
Textspalten und die Lebensdauer der Elemente. Der Anfang langer Listen wird
lokal gescrollt; der generische SDK-Scrollpfad hatte bei größeren Dichten die
erste Zeile hinter den Rand geschoben.
Private Browser-/Native-Aufnahmen, passende UI-Zustände und reale Eingaben
liegen unter `docs/qa/selects-batch-2026-10-26` im Mockup-Repository. Die sechs
Kernfälle und fünf Zusatzmenüs prüfen die tatsächliche Anwendung der Themes.
Ein zusätzlicher Linux-Lauf verwendet physische X11-/SDL-Text- und Fensterevents;
Komponententests ersetzen keine grafische Windows-/macOS-Abnahme.
+12 -2
View File
@@ -7,8 +7,6 @@ Bedienungsnachweise bleiben im privaten QA-Paket.
| Bereich | Priorität | Noch offen |
|---|---|---|
| Weitere native Dropdowns | P2 | Die neuen HTML-nahen Footerpicker gelten für Tabellen, Stärken, Ligaspiele, übrige Spiele, Kalender und Freundschaftsspiele. Manager und weitere Auswahlfelder verwenden noch den bisherigen Select-Unterbau. |
| Länder-Picker außerhalb des Berichtpakets | P2 | Bewusste Neuwahl derselben Nation setzt in HTML auf deren erste Liga zurück. In Berichtmenüs, Kalender und Freundschaftsspielen umgesetzt; Manager noch gesondert angleichen. Abbrechen muss die Unterliga erhalten. |
| Desktop/Rahmen | P2 | Vollständiger Bild-, Widgetinhalt- und Glasvergleich noch ausstehend; aktuelle Teilprüfungen betreffen einzelne Komponenten. |
| Weitere Untermenüs | Offen | Noch nicht portierte Routen im Gesamtkatalog bleiben ausdrücklich `UNIMPLEMENTED`. |
| Stadionperipherie | Zurückgestellt | Auf ausdrücklichen Nutzerwunsch vom Stadionpaket ausgenommen. Größeres Redesign folgt; das vorhandene Panorama ist nur Ansicht, seine Ausbau-Schaltfläche bleibt gesperrt. |
@@ -146,3 +144,15 @@ Standardansichts-Vorschau nach abgebrochener Managerwahl ist ebenfalls behoben:
beim Neubinden des Renderers wird das gehaltene Vorschaubild entwertet.
Die tatsächliche Nachprüfung erhält Quelle, Revision und Layout und zeigt
dieselbe Vorschau vor und nach Abbrechen.
Im [Auswahlmenüpaket](controls/selects/README.md) sind die bisher offenen
Select-Listen übertragen. Sichtbare echte Selects behalten ihre Werte,
Ereignisse und Fachhandler; der gemeinsame RmlUI-Popup ersetzt ihre geöffnete
SDK-Liste. Manager-Neuwahl und Abbrechen sind ausdrücklich getrennt, sodass
Escape die Unterliga erhält. Die frühere Widget-Trigger-Schriftgröße und
Abstände im Managerpopup wurden an die gemessene Goldvorlage angeglichen.
Ein lokaler Scrollpfad hält Pos1/Ende-Zeilen auch bei hoher Dichte sichtbar.
Beenden-Dialoge können aus der Managerwahl per Tab/Enter/Escape bedient werden,
ohne die darunterliegende Auswahl zu verändern. Die historischen Hinweise
auf noch native Popupdarstellung beschreiben den damaligen Stand.
+14 -2
View File
@@ -13,9 +13,21 @@ else()
target_compile_options(bmh_modern_ui_mods PRIVATE -Wall -Wextra -Wpedantic)
endif()
add_test(NAME modern_mods_ui_tests COMMAND modern_mods_ui_tests)
add_library(bmh_modern_ui_select_menu STATIC select_menu.cpp)
target_link_libraries(bmh_modern_ui_select_menu PUBLIC bmh_modern_ui_core RmlUi::Core)
add_executable(modern_select_menu_tests ../../../tests/modern_select_menu_tests.cpp)
target_link_libraries(modern_select_menu_tests PRIVATE bmh_modern_ui_select_menu)
if(MSVC)
target_compile_options(bmh_modern_ui_select_menu PRIVATE /W4 /utf-8)
target_compile_options(modern_select_menu_tests PRIVATE /W4 /utf-8)
else()
target_compile_options(bmh_modern_ui_select_menu PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(modern_select_menu_tests PRIVATE -Wall -Wextra -Wpedantic)
endif()
add_test(NAME modern_select_menu_tests COMMAND modern_select_menu_tests "${CMAKE_BINARY_DIR}/assets/modern")
find_package(Threads REQUIRED)
add_library(bmh_modern_ui STATIC view.cpp ticket_popover.cpp)
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE Threads::Threads bmh_modern_ui_mods bmh_rmlui bmh_launcher nfd::nfd ${BMH_SDL_TARGET})
target_link_libraries(bmh_modern_ui PUBLIC bmh_modern_ui_core PRIVATE Threads::Threads bmh_modern_ui_mods bmh_modern_ui_select_menu 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 /bigobj)
@@ -26,7 +38,7 @@ endif()
set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern")
FetchContent_GetProperties(rmlui)
file(MAKE_DIRECTORY "${modern_assets}")
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss)
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss career_reports.rcss rankings.rcss stadium.rcss statistics.rcss news.rcss settings.rcss widgets.rcss files.rcss front.rcss entry.rcss opening.rcss select_menu.rcss)
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
endforeach()
+1 -1
View File
@@ -969,7 +969,7 @@ void App::script() {
{"transfer_view", transfer_view_}, {"transfer_dialog", transfer_dialog_}, {"transfer_draft", transfer_draft_},
{"career_view", career_view_}, {"rankings_view", rankings_view_},
{"stadium_view", stadium_view_},
{"entry_view", entry_snapshot()}, {"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
{"select_menu", select_menu_ ? select_menu_->snapshot() : Json()}, {"entry_view", entry_snapshot()}, {"front_view",front_snapshot_view()}, {"files_view",{{"mode",files_mode_},{"selected",files_selected_},{"name",files_name_},{"feedback",files_feedback_}}}, {"widget_view",{{"query",widget_query_},{"notice",widget_notice_}}}, {"ui_preferences",ui_preferences_}, {"settings_draft",settings_draft_}, {"settings_category",settings_category_}, {"settings_query",settings_query_}, {"settings_notice",settings_notice_},
{"statistics_view", statistics_view_}, {"statistics_trophy", statistics_trophy_},
{"statistics_scrolls", statistics_scrolls_},
{"news_view", news_view_}, {"news_dialog", news_dialog_},
+6 -5
View File
@@ -216,7 +216,7 @@ void App::entry_confirm() {
refresh();
}
bool App::entry_action(const std::string &action, Rml::Element *target) {
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty())
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty() || menu_ == "quit")
return false;
const auto id =
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
@@ -339,7 +339,7 @@ bool App::entry_action(const std::string &action, Rml::Element *target) {
refresh();
return true;
}
bool App::entry_change(Rml::Element *target) {
bool App::entry_change(Rml::Element *target, bool user_reselected) {
if (scene_ != "manager" || manager_confirm_ || manager_success_)
return false;
const auto kind = target->GetAttribute<Rml::String>("data-change", "");
@@ -357,16 +357,17 @@ bool App::entry_change(Rml::Element *target) {
if (!manager_picker_)
selections_["manager-name"] = field("manager-name");
if (kind == "manager-country") {
if (value == country_)
if (value == country_ && !user_reselected)
return true;
country_ = value;
league_.clear();
} else {
if (value == league_)
if (value == league_ && !user_reselected)
return true;
league_ = value;
}
club_search_.clear();
if (!manager_picker_ && user_reselected) selected_club_.clear();
if (manager_picker_) {
const auto leagues = entry_world()->leagues(country_);
if (std::none_of(leagues.begin(), leagues.end(),
@@ -406,7 +407,7 @@ bool App::entry_input(Rml::Element *target) {
return true;
}
bool App::entry_event(Rml::Event &event) {
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty())
if ((scene_ != "newgame" && scene_ != "manager") || !popup_.empty() || menu_ == "quit")
return false;
const auto type = event.GetType();
auto *target = event.GetTargetElement();
+1
View File
@@ -159,6 +159,7 @@ std::string App::render_manager() {
const std::vector<std::pair<std::string, std::string>> &rows,
const std::string &value) {
auto out = select(id, rows, value, id);
out.insert(out.find('>'), " data-select-style=\"league\"");
if (full)
out.insert(out.find('>'), " disabled");
return out;
+1 -1
View File
@@ -204,7 +204,7 @@ std::string App::render_lineup() {
return "<span class=\"lineup-option-mark\" aria-hidden=\"true\"><span class=\"lineup-option-check\"></span></span><span class=\"lineup-option-text\">"+esc(name)+"</span>";
};
for (int i=0;i<3;++i) {
out+="<label class=\"lineup-taker-label\" style=\"left:"+scalar(i*(lineup_taker_width_dp+18.0))+"dp;\"><span>"+std::string(labels[size_t(i)])+"</span><select class=\"lineup-taker\" id=\"lineup-taker-"+std::to_string(i)+"\" data-lineup-taker=\""+std::to_string(i)+"\" aria-label=\""+std::string(labels[size_t(i)])+"schütze\"><option value=\"\" "+std::string(l.at("takers")[size_t(i)]==""?"selected=\"selected\"":"")+">"+option_text("AUTO")+"</option>";
out+="<label class=\"lineup-taker-label\" style=\"left:"+scalar(i*(lineup_taker_width_dp+18.0))+"dp;\"><span>"+std::string(labels[size_t(i)])+"</span><select class=\"lineup-taker\" data-select-max-height=\"280\" id=\"lineup-taker-"+std::to_string(i)+"\" data-lineup-taker=\""+std::to_string(i)+"\" aria-label=\""+std::string(labels[size_t(i)])+"schütze\"><option value=\"\" "+std::string(l.at("takers")[size_t(i)]==""?"selected=\"selected\"":"")+">"+option_text("AUTO")+"</option>";
for (size_t r=0;r<std::min(size_t(11),rows.size());++r) {
const auto id=rows[r].at("id").get<std::string>();
out+="<option value=\""+esc(id)+"\" "+std::string(l.at("takers")[size_t(i)]==id?"selected=\"selected\"":"")+">"+option_text(rows[r].at("name").get<std::string>())+"</option>";
+548
View File
@@ -0,0 +1,548 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/select_menu.hpp"
#include <RmlUi/Core.h>
#include <RmlUi/Core/ElementText.h>
#include <RmlUi/Core/Elements/ElementFormControlSelect.h>
#include <RmlUi/Core/StringUtilities.h>
#include <algorithm>
#include <chrono>
#include <cmath>
#include <utility>
#include <vector>
namespace bmh::modern_ui {
namespace {
using Select = Rml::ElementFormControlSelect;
using Clock = std::chrono::steady_clock;
std::string plain_text(Rml::Element *node) {
if (auto *text = dynamic_cast<Rml::ElementText *>(node))
return Rml::StringUtilities::DecodeRml(text->GetText());
std::string text;
for (int i = 0; i < node->GetNumChildren(); ++i)
text += plain_text(node->GetChild(i));
return text;
}
std::string tidy(std::string text) {
std::string out;
bool space = false;
for (const auto c : text) {
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
space = !out.empty();
continue;
}
if (space)
out += ' ';
space = false;
out += c;
}
return out;
}
// Country/league labels use Latin scripts. Keep UTF-8 intact and support their
// common accented capitals, rather than lowercasing individual non-ASCII bytes.
std::string folded(std::string text) {
for (size_t i = 0; i < text.size(); ++i) {
const auto c = static_cast<unsigned char>(text[i]);
if (c >= 'A' && c <= 'Z')
text[i] = char(c + ('a' - 'A'));
else if (c == 0xc3 && i + 1 < text.size()) {
const auto next = static_cast<unsigned char>(text[i + 1]);
if (next >= 0x80 && next <= 0x9e && next != 0x97)
text[++i] = char(next + 0x20);
}
}
return text;
}
bool within(Rml::Element *node, const Rml::Element *root) {
for (; node; node = node->GetParentNode())
if (node == root)
return true;
return false;
}
Select *native_select(Rml::Element *node) {
for (; node; node = node->GetParentNode())
if (auto *select = dynamic_cast<Select *>(node))
return select;
return nullptr;
}
bool supported(Select *select) {
return select && !select->GetId().empty() &&
!select->HasAttribute("multiple");
}
bool available(Select *select) {
if (!supported(select) || select->IsDisabled() || !select->IsVisible(true))
return false;
for (auto *node = select->GetParentNode(); node; node = node->GetParentNode())
if (node->HasAttribute("inert") || node->HasAttribute("hidden"))
return false;
return true;
}
bool pixels(Rml::Element &node, Rml::PropertyId property, float value) {
const auto *old = node.GetLocalProperty(property);
if (old && old->unit == Rml::Unit::PX &&
std::abs(old->Get<float>() - value) < .02f)
return false;
node.SetProperty(property, Rml::Property(value, Rml::Unit::PX));
return true;
}
} // namespace
struct SelectMenu::Impl {
struct Option {
std::string text, value;
bool disabled = false;
bool operator==(const Option &) const = default;
};
Rml::Context &context;
Rml::ElementDocument &document;
CheckMarkupFn check;
CommitFn on_commit;
Rml::ObserverPtr<Rml::Element> anchor, canvas, popup;
std::vector<Option> options;
std::string id, typed;
Clock::time_point typed_at{};
int cursor = -1, selected = -1;
bool open = false, league = false, reveal_cursor = false,
focus_cursor = false;
bool suppress_right_release = false, suppress_context_menu = false;
Clock::time_point right_dismissed_at{};
float max_height = 0;
Impl(Rml::Context &c, Rml::ElementDocument &d, CheckMarkupFn glyph,
CommitFn commit)
: context(c), document(d), check(std::move(glyph)),
on_commit(std::move(commit)) {}
Select *control() const { return dynamic_cast<Select *>(anchor.get()); }
std::vector<Option> read_options(Select &select) const {
std::vector<Option> rows;
const int count = select.GetNumOptions();
rows.reserve(size_t(std::max(0, count)));
for (int i = 0; i < count; ++i) {
auto *node = select.GetOption(i);
rows.push_back({tidy(plain_text(node)),
node->GetAttribute<Rml::String>("value", ""),
node->HasAttribute("disabled")});
}
return rows;
}
void remove_popup() {
if (popup)
if (auto *parent = popup->GetParentNode())
parent->RemoveChild(popup.get());
popup.reset();
}
void close(bool focus) {
auto old = anchor;
if (auto *select = control()) {
select->HideSelectBox();
if (select->GetAttribute<Rml::String>("aria-expanded", "") != "false")
select->SetAttribute("aria-expanded", "false");
select->RemoveAttribute("aria-controls");
}
// An ongoing Tab event can still hold its original popup-row target.
// Hide now, but destroy only at the next safe layout/render boundary.
if (popup)
popup->SetProperty("display", "none");
open = false;
anchor.reset();
canvas.reset();
id.clear();
options.clear();
typed.clear();
cursor = selected = -1;
max_height = 0;
reveal_cursor = focus_cursor = false;
if (focus)
if (auto *select = dynamic_cast<Select *>(old.get()); available(select))
select->Focus(true);
}
int endpoint(bool last) const {
if (last) {
for (int i = int(options.size()) - 1; i >= 0; --i)
if (!options[size_t(i)].disabled)
return i;
} else {
for (size_t i = 0; i < options.size(); ++i)
if (!options[i].disabled)
return int(i);
}
return -1;
}
void mark_cursor(bool focus) {
if (!popup)
return;
for (int i = 0; i < popup->GetNumChildren(); ++i) {
auto *row = popup->GetChild(i);
const bool active = i == cursor;
if (row->IsClassSet("is-cursor") != active)
row->SetClass("is-cursor", active);
}
if (cursor >= 0)
if (auto *row = popup->GetChild(cursor)) {
if (focus)
focus_cursor = true;
reveal_cursor = true;
}
}
bool show(Select &select, bool last) {
close(false);
remove_popup();
if (!available(&select))
return false;
auto rows = read_options(select);
if (rows.empty() || std::none_of(rows.begin(), rows.end(),
[](const auto &o) { return !o.disabled; }))
return false;
auto *stage = document.GetElementById("canvas");
if (!stage)
return false;
anchor = select.GetObserverPtr();
canvas = stage->GetObserverPtr();
id = select.GetId();
options = std::move(rows);
selected = select.GetSelection();
league =
select.GetAttribute<Rml::String>("data-select-style", "") == "league";
cursor = last ? endpoint(true) : selected;
if (cursor < 0 || cursor >= int(options.size()) ||
options[size_t(cursor)].disabled)
cursor = endpoint(false);
std::string rml;
const auto marker = check ? check(league ? 28.f : 24.f) : std::string();
for (size_t i = 0; i < options.size(); ++i) {
const auto &option = options[i];
rml += "<button type=\"button\" class=\"native-select-option\" "
"id=\"native-select-option-" +
std::to_string(i) +
"\" role=\"option\" tabindex=\"-1\" data-index=\"" +
std::to_string(i) + "\" aria-selected=\"" +
(int(i) == selected ? "true" : "false") + "\" " +
(option.disabled ? "disabled" : "") +
"><span class=\"native-select-check\" aria-hidden=\"true\">" +
(int(i) == selected ? marker : "") +
"</span><span class=\"native-select-text\">" +
editor::escaped(option.text) + "</span></button>";
}
auto layer = document.CreateElement("div");
layer->SetId("native-select-menu");
layer->SetClassNames(std::string("native-select-menu") +
(league ? " league" : ""));
layer->SetAttribute("role", "listbox");
layer->SetAttribute("aria-label", select.GetAttribute<Rml::String>(
"aria-label", "Auswahl"));
layer->SetAttribute("data-select-id", id);
layer->SetInnerRML(rml);
popup = stage->AppendChild(std::move(layer))->GetObserverPtr();
select.HideSelectBox();
select.SetAttribute("aria-haspopup", "listbox");
select.SetAttribute("aria-expanded", "true");
select.SetAttribute("aria-controls", "native-select-menu");
open = true;
mark_cursor(true);
layout();
return true;
}
void commit(int index) {
if (!open)
return;
if (!fresh()) {
close(false);
return;
}
if (index < 0 || index >= int(options.size()) ||
options[size_t(index)].disabled)
return;
auto old = anchor;
const auto committed_id = id;
const bool reselected = index == selected;
close(true);
if (auto *select = dynamic_cast<Select *>(old.get()); available(select)) {
// A changed index sends the native change itself. Reselection sends none.
if (!reselected)
select->SetSelection(index);
if (on_commit)
on_commit(committed_id, index, reselected);
}
}
void move(int direction) {
if (options.empty())
return;
int next = cursor;
for (size_t tried = 0; tried < options.size(); ++tried) {
next = (next + direction + int(options.size())) % int(options.size());
if (!options[size_t(next)].disabled) {
cursor = next;
mark_cursor(true);
return;
}
}
}
void type(const std::string &text) {
if (text.empty())
return;
const auto now = Clock::now();
typed =
now - typed_at < std::chrono::milliseconds(700) ? typed + text : text;
typed_at = now;
const auto prefix = folded(typed);
for (size_t i = 0; i < options.size(); ++i)
if (!options[i].disabled && folded(options[i].text).starts_with(prefix)) {
cursor = int(i);
mark_cursor(true);
return;
}
}
bool fresh() const {
auto *select = control();
return available(select) && canvas && popup &&
document.GetElementById(id) == select &&
document.GetElementById("canvas") == canvas.get() &&
select->GetSelection() == selected &&
read_options(*select) == options;
}
void layout() {
if (!open) {
remove_popup();
return;
}
if (!fresh()) {
close(false);
remove_popup();
return;
}
auto *select = control();
select->HideSelectBox();
const float ratio =
std::max(.001f, context.GetDensityIndependentPixelRatio());
Rml::Element *owner = select->GetParentNode();
while (owner && !owner->IsClassSet("window"))
owner = owner->GetParentNode();
if (!owner)
owner = canvas.get();
const auto owner_at = owner->GetAbsoluteOffset(Rml::BoxArea::Border);
const auto at = select->GetAbsoluteOffset(Rml::BoxArea::Border);
const auto size = select->GetBox().GetSize(Rml::BoxArea::Border);
const auto stage_at = canvas->GetAbsoluteOffset(Rml::BoxArea::Border);
const auto border_origin =
owner->GetBox().GetPosition(Rml::BoxArea::Padding);
const float left_edge = owner_at.x + border_origin.x,
top_edge = owner_at.y + border_origin.y;
const float right_edge = left_edge + owner->GetClientWidth();
const float bottom_edge = top_edge + owner->GetClientHeight();
const float padding = 20 * ratio, gap = (league ? 12.f : 8.f) * ratio;
const float width =
std::min(std::max(0.f, right_edge - left_edge - 2 * padding),
std::max(size.x, 360 * ratio));
const float left =
std::clamp(at.x, left_edge + padding,
std::max(left_edge + padding, right_edge - padding - width));
const float above = std::max(0.f, at.y - top_edge - padding),
below = std::max(0.f, bottom_edge - at.y - size.y - padding);
float cap_dp = league ? 740.f : 480.f;
const float custom =
select->GetAttribute<float>("data-select-max-height", cap_dp);
if (std::isfinite(custom) && custom > 0)
cap_dp = std::min(cap_dp, custom);
const float cap = cap_dp * ratio;
const float desired =
std::min(float(options.size()) * 58 * ratio + 20 * ratio, cap);
const bool down = below >= std::min(desired, 220 * ratio) || below >= above;
max_height = std::min(cap, std::max(0.f, (down ? below : above) - gap));
bool changed = pixels(*popup.get(), Rml::PropertyId::Width, width);
changed |= pixels(*popup.get(), Rml::PropertyId::FontSize,
select->GetComputedValues().font_size());
changed |= pixels(*popup.get(), Rml::PropertyId::MaxHeight, max_height);
changed |= pixels(*popup.get(), Rml::PropertyId::Left, left - stage_at.x);
if (changed)
context.Update();
const float height = popup->GetBox().GetSize(Rml::BoxArea::Border).y;
const float top = down ? at.y + size.y + gap : at.y - height - gap;
if (pixels(*popup.get(), Rml::PropertyId::Top, top - stage_at.y))
context.Update();
if (reveal_cursor && cursor >= 0) {
if (auto *row = popup->GetChild(cursor)) {
if (focus_cursor)
row->Focus(true);
// Match the HTML list's local scroll adjustment. Pinned RmlUI's
// generic ScrollIntoView adds the popup border to the start offset,
// which clips the first row at larger density factors.
const float row_top = row->GetAbsoluteOffset(Rml::BoxArea::Border).y;
const float row_bottom =
row_top + row->GetBox().GetSize(Rml::BoxArea::Border).y;
const float view_top =
popup->GetAbsoluteOffset(Rml::BoxArea::Border).y +
popup->GetClientTop();
const float view_bottom = view_top + popup->GetClientHeight();
const float scroll = popup->GetScrollTop();
if (row_top < view_top)
popup->SetScrollTop(scroll + row_top - view_top);
else if (row_bottom > view_bottom)
popup->SetScrollTop(scroll + row_bottom - view_bottom);
}
reveal_cursor = focus_cursor = false;
}
}
Rml::Element *row(Rml::Element *target) const {
for (auto *node = target; node && node != popup.get();
node = node->GetParentNode())
if (node->IsClassSet("native-select-option") && within(node, popup.get()))
return node;
return nullptr;
}
bool event(Rml::Event &event) {
const auto type = event.GetType();
auto *target = event.GetTargetElement();
const auto consume = [&] {
event.StopImmediatePropagation();
return true;
};
auto *select = native_select(target);
if (!suppress_right_release &&
Clock::now() - right_dismissed_at > std::chrono::milliseconds(500))
suppress_context_menu = false;
if (type == "contextmenu") {
if (open) {
close(true);
suppress_context_menu = false;
return consume();
}
if (suppress_context_menu) {
suppress_context_menu = false;
return consume();
}
}
if (type == "mouseup" && event.GetParameter<int>("button", 0) == 1 &&
suppress_right_release) {
suppress_right_release = false;
right_dismissed_at = Clock::now();
return consume();
}
if (type == "mousedown") {
if (event.GetParameter<int>("button", 0) == 1 && open) {
close(true);
suppress_right_release = suppress_context_menu = true;
right_dismissed_at = Clock::now();
return consume();
}
if (event.GetParameter<int>("button", 0) != 1)
suppress_context_menu = false;
if (auto *choice = open ? row(target) : nullptr) {
const int index = choice->GetAttribute<int>("data-index", -1);
if (index >= 0 && index < int(options.size()) &&
!options[size_t(index)].disabled) {
cursor = index;
mark_cursor(true);
}
return consume();
}
if (supported(select) && event.GetParameter<int>("button", 0) == 0) {
if (open && anchor == select)
close(true);
else
show(*select, false);
return consume();
}
if (open && !within(target, popup.get()))
close(false);
} else if (type == "click") {
if (auto *choice = open ? row(target) : nullptr) {
commit(choice->GetAttribute<int>("data-index", -1));
return consume();
}
if (supported(select))
return consume(); // Never let the native list open.
} else if (type == "textinput" && open) {
typeahead_event(event);
return consume();
} else if (type == "keydown") {
// A keyboard context-menu request starts a new gesture.
if (!suppress_right_release)
suppress_context_menu = false;
const auto key = Rml::Input::KeyIdentifier(
event.GetParameter<int>("key_identifier", 0));
if (open) {
if (key == Rml::Input::KI_TAB) {
close(true);
return false;
}
if (key == Rml::Input::KI_ESCAPE || key == Rml::Input::KI_F4) {
close(true);
return consume();
}
if (key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN) {
move(key == Rml::Input::KI_UP ? -1 : 1);
return consume();
}
if (key == Rml::Input::KI_HOME || key == Rml::Input::KI_END) {
cursor = endpoint(key == Rml::Input::KI_END);
mark_cursor(true);
return consume();
}
if (key == Rml::Input::KI_RETURN || key == Rml::Input::KI_NUMPADENTER ||
key == Rml::Input::KI_SPACE) {
commit(cursor);
return consume();
}
// Printable input is handled by textinput, including UTF-8. Consuming
// keydown prevents native widget navigation or menu-level shortcuts.
if (!event.GetParameter<int>("ctrl_key", 0) &&
!event.GetParameter<int>("alt_key", 0) &&
!event.GetParameter<int>("meta_key", 0))
return consume();
} else if (available(select) &&
(key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN ||
key == Rml::Input::KI_RETURN ||
key == Rml::Input::KI_NUMPADENTER ||
key == Rml::Input::KI_SPACE || key == Rml::Input::KI_F4)) {
show(*select, key == Rml::Input::KI_UP);
return consume();
}
}
return false;
}
void typeahead_event(Rml::Event &event) {
type(event.GetParameter<Rml::String>("text", ""));
}
};
SelectMenu::SelectMenu(Rml::Context &context, Rml::ElementDocument &document,
CheckMarkupFn check, CommitFn commit)
: impl_(std::make_unique<Impl>(context, document, std::move(check),
std::move(commit))) {}
SelectMenu::~SelectMenu() {
impl_->close(false);
impl_->remove_popup();
}
bool SelectMenu::process_event(Rml::Event &event) {
return impl_->event(event);
}
void SelectMenu::before_render() {
impl_->close(false);
impl_->remove_popup();
}
void SelectMenu::after_layout() { impl_->layout(); }
bool SelectMenu::is_open() const { return impl_->open; }
editor::Json SelectMenu::snapshot() const {
auto &menu = *impl_;
editor::Json rect = editor::Json::object();
float font = 0, scroll = 0;
if (menu.open && menu.popup) {
const auto at = menu.popup->GetAbsoluteOffset(Rml::BoxArea::Border);
const auto size = menu.popup->GetBox().GetSize(Rml::BoxArea::Border);
rect = {{"x", at.x}, {"y", at.y}, {"width", size.x}, {"height", size.y}};
font = menu.popup->GetComputedValues().font_size();
scroll = menu.popup->GetScrollTop();
}
return {{"open", menu.open},
{"id", menu.id},
{"cursor", menu.cursor},
{"selected", menu.selected},
{"option_count", menu.options.size()},
{"rect", rect},
{"font_size", font},
{"ratio", menu.context.GetDensityIndependentPixelRatio()},
{"max_height", menu.max_height},
{"scroll_top", scroll}};
}
} // namespace bmh::modern_ui
+46
View File
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "editor/archive.hpp"
#include <functional>
#include <memory>
#include <string>
namespace Rml {
class Context;
class ElementDocument;
class Event;
} // namespace Rml
namespace bmh::modern_ui {
// The visible native Select remains the only form control/value owner. Its
// native list stays closed; this adapter owns a temporary list inside #canvas.
class SelectMenu final {
public:
using CheckMarkupFn = std::function<std::string(float size_dp)>;
// Called after SetSelection and its ordinary change event. Reselection emits
// no synthetic change; the owner may explicitly handle that user intent here.
using CommitFn =
std::function<void(const std::string &id, int index, bool reselected)>;
SelectMenu(Rml::Context &, Rml::ElementDocument &, CheckMarkupFn, CommitFn);
~SelectMenu();
SelectMenu(const SelectMenu &) = delete;
SelectMenu &operator=(const SelectMenu &) = delete;
// Invoke in capture phase before menu-specific handlers. True means consumed.
// Tab cancels the popup and returns false so normal focus navigation
// proceeds.
bool process_event(Rml::Event &);
// Call before replacing canvas contents. Does not restore an obsolete focus.
void before_render();
// Call after context Update: checks lifetime/disabled state and places popup.
void after_layout();
bool is_open() const;
editor::Json snapshot() const;
private:
struct Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace bmh::modern_ui
+66 -1
View File
@@ -5,6 +5,7 @@
#include "launch/rml_path.hpp"
#include "launch/rml_video.hpp"
#include "modern/ui/controls.hpp"
#include "modern/ui/select_menu.hpp"
#include "modern/ui/demo_calendar.hpp"
#include "modern/ui/demo_finance.hpp"
#include "modern/ui/demo_environment.hpp"
@@ -346,6 +347,16 @@ class App final : public Rml::EventListener {
std::shared_ptr<const Catalog> world_;
std::unique_ptr<DemoSource> source_;
std::unique_ptr<TicketPopover> ticket_;
std::unique_ptr<SelectMenu> select_menu_;
bool select_text_input_owned_ = false;
struct SelectCapture final : Rml::EventListener {
std::function<void(Rml::Event &)> handler;
void ProcessEvent(Rml::Event &event) override {
if (handler) handler(event);
}
} select_capture_;
static constexpr std::array<const char *, 9> select_capture_events_ = {
"mousedown", "mouseup", "click", "keydown", "textinput", "blur", "scroll", "mousemove", "contextmenu"};
bool focus_ticket_ = false;
std::set<std::string> pending_selects_;
std::string focus_after_render_;
@@ -758,7 +769,7 @@ class App final : public Rml::EventListener {
void entry_sync_club();
void entry_confirm();
bool entry_action(const std::string &, Rml::Element *);
bool entry_change(Rml::Element *);
bool entry_change(Rml::Element *, bool user_reselected = false);
bool entry_input(Rml::Element *);
bool entry_event(Rml::Event &);
Json entry_snapshot() const;
@@ -828,7 +839,23 @@ class App final : public Rml::EventListener {
if (statistics_trophy_.contains("asset"))
needs_render_ = true;
}
void select_sync_keyboard() {
if (select_menu_ && select_menu_->is_open()) {
if (!SDL_IsTextInputActive()) {
SDL_StartTextInput();
select_text_input_owned_ = true;
}
} else if (select_text_input_owned_) {
auto *focus = context_ ? context_->GetFocusElement() : nullptr;
auto *input = dynamic_cast<Rml::ElementFormControlInput *>(focus);
const auto type = input ? input->GetAttribute<Rml::String>("type", "text") : "";
const bool editable = input && type != "range" && type != "checkbox" && type != "radio" && type != "button";
if (!editable && (!focus || focus->GetTagName() != "textarea")) SDL_StopTextInput();
select_text_input_owned_ = false;
}
}
void render() {
if (select_menu_) select_menu_->before_render();
if (scene_ == "desktop" && !files_capturing_ && opening_pending()) {
scene_ = "opening";
menu_.clear();
@@ -961,6 +988,7 @@ class App final : public Rml::EventListener {
}
}
void render_popup() {
if (!popup_.empty() && select_menu_) select_menu_->before_render();
if (popup_.empty()) {
element("popup")->SetClass("visible", false);
rendered_popup_.clear();
@@ -1043,6 +1071,11 @@ class App final : public Rml::EventListener {
context_->Update();
if (center_selects(*doc_))
context_->Update();
if (select_menu_) {
select_menu_->after_layout();
select_sync_keyboard();
context_->Update();
}
if (amount_select_all_) {
if (auto *input = dynamic_cast<Rml::ElementFormControlInput *>(element("calculator-value"))) input->Select();
amount_select_all_ = false;
@@ -1221,6 +1254,32 @@ public:
doc_ = context_->LoadDocument(rml::asset_path(assets_ / "modern.rml"));
if (!doc_)
throw std::runtime_error("Modern UI layout missing");
select_menu_ = std::make_unique<SelectMenu>(
*context_, *doc_, [this](float size) { return glyph("check", size); },
[this](const std::string &id, int, bool reselected) {
if (!reselected) return;
if (auto *control = element(id)) {
if ((id == "manager-country" || id == "manager-league") && scene_ == "manager")
entry_change(control, true);
else {
Rml::Dictionary parameters;
parameters["ui_select_reselected"] = true;
control->DispatchEvent("change", parameters);
}
}
});
select_capture_.handler = [this](Rml::Event &event) {
if (event.GetType() == "keydown") keyboard_navigation_ = true;
else if (event.GetType() == "mousedown") keyboard_navigation_ = false;
const bool was_open = select_menu_->is_open();
if (select_menu_->process_event(event)) {
event.StopImmediatePropagation();
dirty_ = true;
} else if (was_open != select_menu_->is_open()) dirty_ = true;
select_sync_keyboard();
};
for (const char *event : select_capture_events_)
doc_->AddEventListener(event, &select_capture_, true);
for (const char *event :
{"click", "dblclick", "change", "input", "keydown", "blur", "mousedown",
"mouseup", "mousemove", "contextmenu", "focus"})
@@ -1277,6 +1336,12 @@ public:
}
}
void shutdown() {
select_capture_.handler = {};
if (doc_)
for (const char *event : select_capture_events_)
doc_->RemoveEventListener(event, &select_capture_, true);
select_menu_.reset();
select_sync_keyboard();
ticket_.reset();
if (doc_) {
doc_->Close();
+17 -1
View File
@@ -188,7 +188,7 @@ bool App::widget_event(Rml::Event &event) {
return widget_change(target);
}
}
if (type != "keydown" || scene_ != "desktop")
if (type != "keydown" || (scene_ != "desktop" && menu_ != "quit"))
return false;
const auto key =
Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
@@ -233,6 +233,22 @@ bool App::widget_event(Rml::Event &event) {
event.StopImmediatePropagation();
return true;
}
if (key == Rml::Input::KI_TAB && menu_ == "quit") {
Rml::ElementList buttons;
if (auto *modal = doc_->QuerySelector(".desktop-modal-layer"))
modal->QuerySelectorAll(buttons, "button");
std::erase_if(buttons, [](auto *button) {
return !button->IsVisible(true) || button->HasAttribute("disabled");
});
if (!buttons.empty()) {
const auto found = std::find(buttons.begin(), buttons.end(), context_->GetFocusElement());
const int count = int(buttons.size());
const int old = found == buttons.end() ? (shift ? 0 : -1) : int(found - buttons.begin());
buttons[size_t((old + (shift ? -1 : 1) + count) % count)]->Focus(true);
}
event.StopImmediatePropagation();
return true;
}
if (key == Rml::Input::KI_ESCAPE && menu_ == "quit") {
widget_action("desktop-quit-cancel", nullptr);
event.StopImmediatePropagation();
+545
View File
@@ -0,0 +1,545 @@
// SPDX-License-Identifier: GPL-3.0-only
// Real Rml input/document tests. The renderer is windowless; controls are not.
#include "modern/ui/controls.hpp"
#include "modern/ui/select_menu.hpp"
#include <RmlUi/Core/ElementText.h>
#include <RmlUi/Core/Elements/ElementFormControlSelect.h>
#include <cmath>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <vector>
using namespace bmh::modern_ui;
namespace {
using Key = Rml::Input::KeyIdentifier;
void require(bool value, const char *message) {
if (!value)
throw std::runtime_error(message);
}
struct Renderer final : Rml::RenderInterface {
Rml::CompiledGeometryHandle CompileGeometry(Rml::Span<const Rml::Vertex>,
Rml::Span<const int>) 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<const Rml::byte>,
Rml::Vector2i) override {
return 1;
}
void ReleaseTexture(Rml::TextureHandle) override {}
void EnableScissorRegion(bool) override {}
void SetScissorRegion(Rml::Rectanglei) override {}
};
struct System final : Rml::SystemInterface {
size_t stylesheet_errors = 0;
double GetElapsedTime() override { return 0; }
bool LogMessage(Rml::Log::Type type, const Rml::String &message) override {
if ((type == Rml::Log::LT_WARNING || type == Rml::Log::LT_ERROR) &&
(message.find("property") != message.npos ||
message.find("style") != message.npos ||
message.find("Syntax error") != message.npos)) {
++stylesheet_errors;
std::cerr << message << '\n';
}
return true;
}
};
struct Commit {
std::string id;
int index;
bool reselected;
int changes_seen;
};
struct Host final : Rml::EventListener {
Rml::Context *context = nullptr;
Rml::ElementDocument *document = nullptr;
SelectMenu *menu = nullptr;
bool populating = false;
std::map<std::string, int> changes;
std::vector<Commit> commits;
int outside_clicks = 0, tab_moves = 0;
void ProcessEvent(Rml::Event &event) override {
if (menu && menu->process_event(event))
return;
auto *target = event.GetTargetElement();
if (!populating && event.GetType() == "change" &&
dynamic_cast<Rml::ElementFormControlSelect *>(target))
++changes[target->GetId()];
if (event.GetType() == "click")
for (auto *node = target; node; node = node->GetParentNode())
if (node->GetId() == "outside") {
++outside_clicks;
break;
}
if (event.GetType() == "keydown" &&
event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_TAB) {
// Minimal real host navigation: the adapter must cancel and let this run.
const auto id =
context->GetFocusElement() ? context->GetFocusElement()->GetId() : "";
if (id == "basic") {
document->GetElementById("after")->Focus(true);
++tab_moves;
event.StopImmediatePropagation();
}
}
}
};
std::string options(const std::string &selected = "alpha") {
std::string out;
for (const auto &[value, label] :
std::vector<std::pair<std::string, std::string>>{
{"alpha", "Alpha &amp; &lt;Verein&gt; &quot;A&quot;"},
{"blocked", "Blocked"},
{"apfel", "Äpfel"},
{"zulu", "Zulu"},
{"alpine", "Alpine"}})
out += "<option value='" + value + "' " +
(value == selected ? "selected " : "") +
(value == "blocked" ? "disabled" : "") + ">" + label + "</option>";
return out;
}
std::string many_options() {
std::string out;
for (int index = 0; index < 30; ++index)
out += "<option value='" + std::to_string(index) + "' " +
(index == 0 ? "selected" : "") + ">Option " + std::to_string(index) +
"</option>";
return out;
}
std::string contents(const std::string &selected = "alpha") {
const auto select = [](const char *id, const char *position,
const std::string &rows, const char *attributes = "") {
return "<select id='" + std::string(id) +
"' aria-label='Synthetic choice' " + attributes +
" style='position:absolute;height:88dp;font-size:30dp;" + position +
"'>" + rows + "</select>";
};
return "<section id='owner' class='window' "
"style='left:400dp;top:200dp;width:2400dp;height:1600dp;'>" +
select("basic", "left:120dp;top:160dp;width:620dp;",
options(selected)) +
"<button id='after' "
"style='position:absolute;left:120dp;top:60dp;width:400dp;height:76dp;"
"'><span>After select</span></button>" +
select("long", "left:1000dp;top:160dp;width:620dp;", many_options()) +
select("league", "left:120dp;top:500dp;width:800dp;", many_options(),
"data-select-style='league'") +
select("capped", "left:1000dp;top:500dp;width:620dp;", many_options(),
"data-select-max-height='280'") +
select("bottom", "left:120dp;top:1440dp;width:620dp;",
many_options()) +
select("edge", "left:2250dp;top:1050dp;width:100dp;", many_options()) +
select("disabled", "left:1000dp;top:1000dp;width:620dp;", options(),
"disabled") +
select(
"none", "left:1000dp;top:1200dp;width:620dp;",
"<option value='x' selected disabled>No enabled option</option>") +
"</section><button id='outside' "
"style='position:absolute;left:200dp;top:1900dp;width:350dp;height:"
"80dp;'><span>Outside</span></button>";
}
struct Fixture {
Rml::Context *context = nullptr;
Rml::ElementDocument *document = nullptr;
Host host;
std::unique_ptr<SelectMenu> menu;
float ratio;
std::string theme;
const std::vector<std::string> events = {
"mousedown", "mouseup", "click", "contextmenu", "keydown", "textinput",
"change", "input", "blur", "focus", "scroll"};
Fixture(const std::string &css, const std::string &name, float density)
: ratio(density), theme(name) {
context = Rml::CreateContext("select-menu-tests",
{int(3840 * density), int(2160 * density)});
require(context, "Rml context missing");
context->SetDensityIndependentPixelRatio(density);
document = context->LoadDocumentFromMemory(
"<rml><head><style>" + css + "</style></head><body class='" + name +
"'><div id='canvas'>" + contents() + "</div></body></rml>");
require(document, "Rml document missing");
document->Show();
context->Update();
context->Render();
host.context = context;
host.document = document;
menu = std::make_unique<SelectMenu>(
*context, *document,
[](float size) {
const auto n = std::to_string(size);
return "<span class='fixture-check-art' style='display:block;width:" +
n + "dp;height:" + n +
"dp;border-right:2dp var(--accent);border-bottom:2dp "
"var(--accent);'></span>";
},
[&](const std::string &id, int index, bool reselected) {
host.commits.push_back({id, index, reselected, host.changes[id]});
});
host.menu = menu.get();
for (const auto &event : events)
document->AddEventListener(event, &host, true);
settle();
host.changes.clear();
host.commits.clear();
}
~Fixture() {
if (document)
for (const auto &event : events)
document->RemoveEventListener(event, &host, true);
host.menu = nullptr;
menu.reset();
if (document)
document->Close();
if (context)
Rml::RemoveContext("select-menu-tests");
}
Rml::Element *node(const std::string &id) const {
auto *value = document->GetElementById(id);
require(value, "Fixture node missing");
return value;
}
Rml::ElementFormControlSelect *native(const std::string &id) const {
auto *value = dynamic_cast<Rml::ElementFormControlSelect *>(node(id));
require(value, "Fixture is not a real native select");
return value;
}
void settle() {
for (int i = 0; i < 3; ++i) {
context->Update();
menu->after_layout();
context->Update();
center_selects(*document);
context->Render();
}
}
void click(const std::string &id) {
auto *element = node(id);
const auto at = element->GetAbsoluteOffset(Rml::BoxArea::Border),
size = element->GetBox().GetSize(Rml::BoxArea::Border);
context->ProcessMouseMove(int(std::lround(at.x + size.x / 2)),
int(std::lround(at.y + size.y / 2)), 0);
context->ProcessMouseButtonDown(0, 0);
context->ProcessMouseButtonUp(0, 0);
settle();
}
void key(Key value) {
context->ProcessKeyDown(value, 0);
context->ProcessKeyUp(value, 0);
settle();
}
void text(const std::string &value) {
context->ProcessTextInput(value);
settle();
}
int cursor() const { return menu->snapshot().at("cursor").get<int>(); }
void opening(const std::string &id) {
click(id);
require(menu->is_open(), "Real mouse input did not open adapter");
require(!native(id)->IsSelectBoxVisible(),
"Native and external lists opened simultaneously");
require(menu->snapshot().at("id").get<std::string>() == id,
"Popup owner identity incorrect");
}
void escape() {
key(Rml::Input::KI_ESCAPE);
require(!menu->is_open(), "Escape did not cancel popup");
}
void bounded(const std::string &trigger, bool down) {
auto *popup = node("native-select-menu"), *owner = node("owner");
const auto p = popup->GetAbsoluteOffset(Rml::BoxArea::Border),
s = popup->GetBox().GetSize(Rml::BoxArea::Border);
const auto at = owner->GetAbsoluteOffset(Rml::BoxArea::Border),
size = owner->GetBox().GetSize(Rml::BoxArea::Border);
const auto t = node(trigger)->GetAbsoluteOffset(Rml::BoxArea::Border),
ts = node(trigger)->GetBox().GetSize(Rml::BoxArea::Border);
require(p.x >= at.x + 18 * ratio - 2 &&
p.x + s.x <= at.x + size.x - 18 * ratio + 2,
"Popup escaped horizontal window bounds");
require(p.y >= at.y + 18 * ratio - 2 &&
p.y + s.y <= at.y + size.y - 18 * ratio + 2,
"Popup escaped vertical window bounds");
require(down ? p.y >= t.y + ts.y - 1 : p.y + s.y <= t.y + 1,
"Popup opened on wrong side of trigger");
}
};
std::string rendered_text(Rml::Element *node) {
std::string result;
if (auto *text = dynamic_cast<Rml::ElementText *>(node)) {
for (const auto &line : text->GetLines())
result += line.text;
} else
for (int i = 0; i < node->GetNumChildren(); ++i)
result += rendered_text(node->GetChild(i));
return result;
}
void interaction(Fixture &f) {
f.opening("basic");
require(rendered_text(f.node("native-select-option-0"))
.find("Alpha & <Verein> \"A\"") != std::string::npos,
"Option entities were double-escaped or interpreted as markup");
require(f.menu->snapshot().at("option_count").get<int>() == 5 &&
f.cursor() == 0,
"Initial selection/options incorrect");
f.key(Rml::Input::KI_DOWN);
require(f.cursor() == 2, "Arrow did not skip disabled option");
require(f.context->GetFocusElement()->GetId() == "native-select-option-2",
"Cursor focus not moved to enabled option");
f.click("native-select-option-1");
require(f.menu->is_open() && f.native("basic")->GetValue() == "alpha" &&
f.host.commits.empty(),
"Disabled option committed or closed menu");
f.key(Rml::Input::KI_END);
require(f.cursor() == 4, "End did not select last enabled cursor");
f.key(Rml::Input::KI_DOWN);
require(f.cursor() == 0, "Down did not wrap enabled options");
f.key(Rml::Input::KI_UP);
require(f.cursor() == 4, "Up did not wrap enabled options");
f.key(Rml::Input::KI_HOME);
require(f.cursor() == 0, "Home did not select first enabled cursor");
require(f.native("basic")->GetValue() == "alpha" &&
f.host.changes["basic"] == 0 && f.host.commits.empty(),
"Browsing changed real value or dispatched a handler");
f.key(Rml::Input::KI_DOWN);
f.key(Rml::Input::KI_RETURN);
require(!f.menu->is_open() && f.native("basic")->GetValue() == "apfel" &&
f.native("basic")->GetSelection() == 2,
"Enter did not commit real select value/index");
require(
f.host.changes["basic"] == 1 && f.host.commits.size() == 1 &&
!f.host.commits.back().reselected &&
f.host.commits.back().changes_seen == 1,
"Changed choice did not fire exactly one native change before callback");
require(f.context->GetFocusElement()->GetId() == "basic",
"Commit did not restore trigger focus");
f.opening("basic");
f.click("native-select-option-2");
require(f.host.commits.size() == 2 && f.host.commits.back().reselected &&
f.host.changes["basic"] == 1,
"Reselection lost callback or emitted synthetic ordinary change");
f.native("basic")->Focus(true);
f.key(Rml::Input::KI_F4);
require(f.menu->is_open(), "F4 did not open real select adapter");
f.key(Rml::Input::KI_A);
f.text("a");
f.text("lpi");
require(f.cursor() == 4,
"Typeahead prefix doubled key/textinput or ignored enabled text");
f.escape();
f.opening("basic");
f.text("ä");
f.text("p");
require(f.cursor() == 2, "Unicode textinput did not match accented caption");
f.escape();
require(f.native("basic")->GetValue() == "apfel" &&
f.host.changes["basic"] == 1 && f.host.commits.size() == 2,
"Escape/typeahead changed committed value or callback count");
f.opening("basic");
f.key(Rml::Input::KI_DOWN);
f.key(Rml::Input::KI_TAB);
require(!f.menu->is_open() &&
f.context->GetFocusElement()->GetId() == "after" &&
f.host.tab_moves == 1,
"Tab did not cancel before host focus navigation");
require(f.host.changes["basic"] == 1 && f.host.commits.size() == 2,
"Tab committed highlighted option");
f.opening("basic");
f.click("outside");
require(!f.menu->is_open() && f.host.outside_clicks == 1 &&
f.native("basic")->GetValue() == "apfel",
"Outside cancel swallowed click or committed draft");
f.click("disabled");
require(!f.menu->is_open(), "Disabled trigger opened popup");
f.click("none");
require(!f.menu->is_open(), "All-disabled option set opened popup");
}
void geometry(Fixture &f) {
for (const auto &[id, cap] : std::vector<std::pair<std::string, float>>{
{"long", 480}, {"league", 740}, {"capped", 280}}) {
f.opening(id);
f.bounded(id, true);
auto *popup = f.node("native-select-menu"), *control = f.node(id);
require(std::abs(f.menu->snapshot().at("max_height").get<float>() -
cap * f.ratio) < 2,
"Style/custom popup cap incorrect");
require(popup->GetBox().GetSize(Rml::BoxArea::Border).y <=
cap * f.ratio + 2,
"Popup exceeded requested physical height");
const auto font = control->GetComputedValues().font_size();
require(std::abs(f.menu->snapshot().at("font_size").get<float>() - font) <
.05f,
"Popup font does not match physical trigger font");
const auto expected =
f.theme == "silver" ? Rml::Colourb{243, 247, 252, 252}
: f.theme == "matchday"
? Rml::Colourb{48, 48, 55, 252}
: Rml::Colourb{41, 55, 68,
static_cast<Rml::byte>(id == "league" ? 250 : 255)};
require(popup->GetComputedValues().background_color() == expected,
"Popup used wrong theme surface colour");
for (int index = 0; index < 30; ++index)
require(std::abs(f.node("native-select-option-" + std::to_string(index))
->GetComputedValues()
.font_size() -
font) < .05f,
"Option font changed from trigger font");
auto *row = f.node("native-select-option-0");
auto *art = row->QuerySelector(".fixture-check-art"),
*caption = row->QuerySelector(".native-select-text"),
*slot = row->QuerySelector(".native-select-check");
require(art && caption && slot, "Check or caption box disappeared");
const auto mark = art->GetBox().GetSize(Rml::BoxArea::Border),
text = caption->GetBox().GetSize(Rml::BoxArea::Border);
require(mark.x > 0 && mark.y > 0 && text.x > 0 && text.y > 0,
"Check/text geometry collapsed");
require(caption->GetAbsoluteOffset(Rml::BoxArea::Border).x >=
art->GetAbsoluteOffset(Rml::BoxArea::Border).x + mark.x - 1,
"Check art overlaps caption");
require(std::abs(slot->GetBox().GetSize(Rml::BoxArea::Border).x -
(id == "league" ? 34 : 28) * f.ratio) < 1,
"Check slot differs from style geometry");
f.key(Rml::Input::KI_END);
require(f.cursor() == 29 &&
f.menu->snapshot().at("scroll_top").get<float>() > 0,
"End did not scroll long menu");
const float end_scroll = f.menu->snapshot().at("scroll_top").get<float>();
auto *last = f.node("native-select-option-29");
const auto at = last->GetAbsoluteOffset(Rml::BoxArea::Border),
size = last->GetBox().GetSize(Rml::BoxArea::Border);
const auto top = popup->GetAbsoluteOffset(Rml::BoxArea::Border),
height = popup->GetBox().GetSize(Rml::BoxArea::Border);
require(at.y >= top.y - 1 && at.y + size.y <= top.y + height.y + 2,
"End cursor remains clipped outside popup");
f.key(Rml::Input::KI_HOME);
const auto first_at = f.node("native-select-option-0")
->GetAbsoluteOffset(Rml::BoxArea::Border);
const auto first_size = f.node("native-select-option-0")
->GetBox()
.GetSize(Rml::BoxArea::Border);
const auto home_top = popup->GetAbsoluteOffset(Rml::BoxArea::Border),
home_size = popup->GetBox().GetSize(Rml::BoxArea::Border);
const float home_scroll = f.menu->snapshot().at("scroll_top").get<float>();
if (!(f.cursor() == 0 && home_scroll < end_scroll &&
first_at.y >= top.y - 1 &&
first_at.y + first_size.y <= top.y + height.y + 2)) {
std::cerr << "HOME DIAGNOSTIC id=" << id << " density=" << f.ratio
<< " old_popup=[" << top.x << ',' << top.y << ',' << height.x
<< ',' << height.y << "] new_popup=[" << home_top.x << ','
<< home_top.y << ',' << home_size.x << ',' << home_size.y
<< "] first_row=[" << first_at.x << ',' << first_at.y << ','
<< first_size.x << ',' << first_size.y
<< "] scroll_top=" << home_scroll
<< " end_scroll=" << end_scroll << " cursor=" << f.cursor()
<< " fresh_geometry_pass="
<< (f.cursor() == 0 && home_scroll < end_scroll &&
first_at.y >= home_top.y - 1 &&
first_at.y + first_size.y <= home_top.y + home_size.y + 2)
<< '\n';
}
require(f.cursor() == 0 &&
f.menu->snapshot().at("scroll_top").get<float>() < end_scroll &&
first_at.y >= top.y - 1 &&
first_at.y + first_size.y <= top.y + height.y + 2,
"Home did not return to visible first row");
require(f.native(id)->GetValue() == "0" && f.host.changes[id] == 0,
"Scrolling navigated native committed value");
f.escape();
}
f.opening("bottom");
f.bounded("bottom", false);
f.escape();
f.opening("edge");
f.bounded("edge", true);
require(
f.node("native-select-menu")->GetAbsoluteOffset(Rml::BoxArea::Border).x <
f.node("edge")->GetAbsoluteOffset(Rml::BoxArea::Border).x,
"Narrow right-edge trigger did not clamp popup left");
f.escape();
}
void lifecycle(Fixture &f) {
const auto commits = f.host.commits.size();
const int changes = f.host.changes["basic"];
f.opening("basic");
f.native("basic")->SetAttribute("disabled", "disabled");
f.settle();
require(!f.menu->is_open() && f.host.commits.size() == commits &&
f.host.changes["basic"] == changes,
"Disabling open owner committed a value");
f.native("basic")->RemoveAttribute("disabled");
f.settle();
f.opening("basic");
f.menu->before_render();
f.host.populating = true;
f.node("canvas")->SetInnerRML(contents("apfel"));
f.settle();
f.host.populating = false;
require(
!f.menu->is_open() && f.native("basic")->GetValue() == "apfel" &&
f.host.commits.size() == commits,
"Normal DOM replacement retained popup or committed obsolete control");
f.opening("basic");
f.host.populating = true;
f.node("canvas")->SetInnerRML(contents("apfel"));
f.settle();
f.host.populating = false;
require(!f.menu->is_open() && f.host.commits.size() == commits,
"Removed owner did not invalidate open popup lifetime");
const auto snapshot = f.menu->snapshot();
require(!snapshot.at("open").get<bool>() &&
snapshot.at("id").get<std::string>().empty() &&
snapshot.at("cursor").get<int>() == -1,
"Closed snapshot retained stale owner/cursor");
}
} // namespace
int main(int argc, char **argv) try {
require(argc == 2, "Pass the Modern asset directory");
const auto assets = std::filesystem::path(argv[1]);
Renderer renderer;
System system;
Rml::SetRenderInterface(&renderer);
Rml::SetSystemInterface(&system);
require(Rml::Initialise(), "Rml initialization failed");
require(Rml::LoadFontFace((assets / "LatoLatin-Regular.ttf").string(),
"Modern", Rml::Style::FontStyle::Normal,
Rml::Style::FontWeight::Normal),
"Regular font missing");
require(Rml::LoadFontFace((assets / "LatoLatin-Bold.ttf").string(), "Modern",
Rml::Style::FontStyle::Normal,
Rml::Style::FontWeight::Bold),
"Bold font missing");
std::ostringstream css;
for (const auto *name :
{"theme.rcss", "entry.rcss", "settings.rcss", "select_menu.rcss"}) {
std::ifstream input(assets / name);
require(bool(input), "Production stylesheet missing");
css << input.rdbuf() << '\n';
}
for (const auto *theme : {"midnight", "silver", "matchday"})
for (float density : {1.f / 3, .5f, 1.f, 2.f}) {
std::cerr << "SelectMenu " << theme << " density=" << density << '\n';
Fixture fixture(css.str(), theme, density);
require(system.stylesheet_errors == 0,
"Rml rejected a production stylesheet property");
interaction(fixture);
geometry(fixture);
lifecycle(fixture);
}
Rml::Shutdown();
std::cout << "PASS real Rml select menu input: commit/reselect/cancel, "
"Unicode, focus/scroll, theme/fonts/geometry and owner lifetime "
"in 3 themes at 4 densities\n";
return 0;
} catch (const std::exception &error) {
std::cerr << error.what() << '\n';
return 1;
}