Skip to content

Commit f0ece14

Browse files
committed
Fixed Language field not accessible. Fixed search field not working.
Set missing label to some controls
1 parent 9501ca3 commit f0ece14

File tree

7 files changed

+197
-9
lines changed

7 files changed

+197
-9
lines changed

Assets/Resources/UITk/MainView.uxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ui:VisualElement name="root" style="flex-grow: 1;">
44
<ui:VisualElement name="background" style="flex-grow: 1; position: absolute; top: 0; left: 0; bottom: 0; right: 0; background-color: rgb(11, 163, 109);"/>
55
<ui:VisualElement name="viewContainer" style="flex-grow: 1;">
6-
<Unity.Samples.LetterSpell.StackView name="stackView" index="0" style="flex-grow: 1;">
6+
<Unity.Samples.LetterSpell.StackView name="stackView" index="4" style="flex-grow: 1;">
77
<ui:VisualElement name="splashView" style="flex-grow: 1; background-image: url(&quot;project://database/Assets/UI/Images/Splash-Screen.png?fileID=4602334432413793429&amp;guid=364b68ded9ed04f07848b6c7de25fdad&amp;type=3#Intro Screen_0&quot;);">
88
<ui:Label text="A fun spelling game" name="splashSubTitle">
99
<Bindings>
@@ -90,7 +90,7 @@
9090
</Bindings>
9191
</ui:Button>
9292
</ui:VisualElement>
93-
<ui:ScrollView name="ScrollView" vertical-scroller-visibility="Hidden">
93+
<ui:ScrollView name="settingsScrollView" vertical-scroller-visibility="Hidden">
9494
<ui:TextField placeholder-text="Search Options" name="settingsSearchField">
9595
<Bindings>
9696
<UnityEngine.Localization.LocalizedString property="placeholderText" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(2876929896448)"/>

Assets/Resources/UITk/Themes/LetterSpellTheme.uss

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,29 +467,33 @@
467467
background-color: rgb(116, 45, 243);
468468
}
469469

470-
.lsp-dir-ltr .lsp-button-strip-field__button--left {
471-
margin-right: 0;
470+
.lsp-button-strip-field__button--left {
471+
border-radius: 30px;
472+
border-width: 10px;
472473
border-right-width: 5px;
473474
border-top-right-radius: 0;
474475
border-bottom-right-radius: 0;
475476
}
476477

477478
.lsp-dir-rtl .lsp-button-strip-field__button--left{
478-
margin-left: 0;
479+
border-radius: 30px;
480+
border-width: 10px;
479481
border-left-width: 5px;
480482
border-top-left-radius: 0;
481483
border-bottom-left-radius: 0;
482484
}
483485

484-
.lsp-dir-ltr .lsp-button-strip-field__button--right {
486+
.lsp-button-strip-field__button--right {
487+
border-radius: 30px;
488+
border-width: 10px;
485489
border-top-left-radius: 0;
486490
border-bottom-left-radius: 0;
487491
border-left-width: 5px;
488-
margin-left: 0;
489492
}
490493

491494
.lsp-dir-rtl .lsp-button-strip-field__button--right {
492-
margin-right: 0;
495+
border-radius: 30px;
496+
border-width: 10px;
493497
border-right-width: 5px;
494498
border-top-right-radius: 0;
495499
border-bottom-right-radius: 0;
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using Unity.Samples.LetterSpell;
2+
using UnityEngine.Accessibility;
3+
using UnityEngine.Localization.Settings;
4+
using UnityEngine.Scripting;
5+
using UnityEngine.UIElements;
6+
7+
namespace Unity.Samples.ScreenReader
8+
{
9+
[Preserve]
10+
class BasePopupFieldHandler<TValue, TValueChoice> : BaseFieldHandler<TValue>
11+
{
12+
bool m_HasPendingCheck;
13+
14+
public BasePopupFieldHandler()
15+
{
16+
/*OnSelect += () =>
17+
{
18+
ownerElement.schedule.Execute(CheckForOpenedPopupMenu).ExecuteLater(200);
19+
20+
using var evt = NavigationSubmitEvent.GetPooled();
21+
ownerElement.SendEvent(evt);
22+
OnScreenDebug.Log("Submit event sent to " + ownerElement.name);
23+
24+
return false;//true;
25+
};*/
26+
}
27+
28+
public override string GetHint()
29+
{
30+
return LocalizationSettings.StringDatabase.GetLocalizedString("Game Text", "DROPDOWN_CLOSED_HINT");
31+
}
32+
33+
protected override void BindToElement(VisualElement element)
34+
{
35+
base.BindToElement(element);
36+
element.RegisterCallback<PointerDownEvent>(OnPointerDown);
37+
element.RegisterCallback<NavigationSubmitEvent>(OnNavigationSubmit);
38+
}
39+
40+
protected override void UnbindFromElement(VisualElement element)
41+
{
42+
element.UnregisterCallback<PointerDownEvent>(OnPointerDown);
43+
element.UnregisterCallback<NavigationSubmitEvent>(OnNavigationSubmit);
44+
base.UnbindFromElement(element);
45+
}
46+
47+
void OnNavigationSubmit(NavigationSubmitEvent evt)
48+
{
49+
OnScreenDebug.Log("Submit event received by " + ownerElement.name);
50+
ScheduledCheckForOpenedPopupMenu();
51+
}
52+
53+
void OnPointerDown(PointerDownEvent evt)
54+
{
55+
OnScreenDebug.Log("Pointer Down event " + ownerElement.name);
56+
57+
ScheduledCheckForOpenedPopupMenu();
58+
}
59+
60+
void ScheduledCheckForOpenedPopupMenu()
61+
{
62+
if (m_HasPendingCheck)
63+
{
64+
return;
65+
}
66+
67+
m_HasPendingCheck = true;
68+
ownerElement.schedule.Execute(() =>
69+
{
70+
m_HasPendingCheck = false;
71+
CheckForOpenedPopupMenu();
72+
}).ExecuteLater(300);
73+
}
74+
75+
void CheckForOpenedPopupMenu()
76+
{
77+
var panel = ownerElement.panel;
78+
79+
if (panel == null)
80+
{
81+
return;
82+
}
83+
84+
var panelRootVisualElement = panel.visualTree;
85+
var popupMenu = panelRootVisualElement.Q(classes: GenericDropdownMenu.ussClassName);
86+
87+
OnScreenDebug.Log("Showing popup menu: " + (popupMenu != null));
88+
89+
if (popupMenu != null)
90+
{
91+
var popupAcc = popupMenu.GetOrCreateAccessibleProperties();
92+
93+
#if UNITY_6000_3_OR_NEWER
94+
popupAcc.role = AccessibilityRole.Dropdown;
95+
#endif // UNITY_6000_3_OR_NEWER
96+
popupAcc.active = false;
97+
popupAcc.modal = true;
98+
99+
// Setup items in the popup menu
100+
var items = popupMenu.Query(classes: GenericDropdownMenu.itemUssClassName).ToList();
101+
var i = 0;
102+
103+
OnScreenDebug.Log("Item count : " + items.Count);
104+
foreach (var item in items)
105+
{
106+
// if (item.GetAccessibleProperties() != null)
107+
// continue;
108+
109+
var itemAcc = item.GetOrCreateAccessibleProperties();
110+
var itemLabel = item.Q<Label>();
111+
112+
itemAcc.label = itemLabel != null ? itemLabel.text : $"Item {i}";
113+
itemAcc.role = AccessibilityRole.Button;
114+
itemLabel.GetOrCreateAccessibleProperties().ignored = true;
115+
i++;
116+
}
117+
118+
// NotifyChange();
119+
}
120+
121+
/*
122+
#if UNITY_6000_3_OR_NEWER
123+
var popup = ve.Q("unity-popup");
124+
125+
if (popup != null && popup.style.display == DisplayStyle.Flex)
126+
{
127+
SetState(AccessibilityState.Expanded);
128+
}
129+
else
130+
{
131+
SetState(AccessibilityState.Collapsed);
132+
}
133+
#endif // UNITY_6000_3_OR_NEWER
134+
*/
135+
}
136+
}
137+
}

Assets/Scripts/Screen Reader/UITk/Handlers/BasePopupFieldHandler.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Screen Reader/UITk/Handlers/ScrollViewHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using UnityEngine;
2+
using UnityEngine.Accessibility;
23
using UnityEngine.Scripting;
34
using UnityEngine.UIElements;
45

@@ -7,6 +8,11 @@ namespace Unity.Samples.ScreenReader
78
[Preserve]
89
public class ScrollViewHandler : VisualElementAccessibilityHandler
910
{
11+
public override AccessibilityRole GetRole()
12+
{
13+
return AccessibilityRole.ScrollView;
14+
}
15+
1016
protected override void BindToElement(VisualElement ve)
1117
{
1218
var scrollView = ve as ScrollView;

Assets/Scripts/Screen Reader/UITk/Handlers/VisualElementAccessibilityHandlerFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ public static void RegisterBuiltinAccessibleElementFactories()
186186
RegisterFactory<Button, ButtonHandler>();
187187
RegisterGenericFactory(typeof(BaseField<>), typeof(BaseFieldHandler<>));
188188
RegisterGenericFactory(typeof(BaseSlider<>), typeof(BaseSliderHandler<>));
189+
RegisterGenericFactory(typeof(BasePopupField<,>), typeof(BasePopupFieldHandler<,>));
189190
RegisterFactory<TextField, TextFieldFieldHandler>();
190-
RegisterFactory<DropdownField, DropdownFieldHandler>();
191+
//RegisterFactory<DropdownField, DropdownFieldHandler>();
191192
RegisterFactory<ListView, ListViewHandler>();
192193
RegisterFactory<ScrollView, ScrollViewHandler>();
193194
RegisterFactory(new ListViewItemHandlerCreator());

Assets/Scripts/UITk/MainView.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class MainView : MonoBehaviour
220220
Button m_CloseSettingsButton;
221221
Button m_SettingsButton;
222222
Button m_InGameSettingsButton;
223+
private TextField m_SearchField;
223224
VisualElement m_LastView;
224225
LetterCardListModel m_Model = new();
225226

@@ -415,6 +416,14 @@ void SetupUI()
415416

416417
m_SettingsView = m_StackView.Q("settingsView");
417418
m_SettingsView.dataSource = m_PlayerSettings;
419+
420+
var settingsScrollView = m_SettingsView.Q<ScrollView>("settingsScrollView");
421+
settingsScrollView.GetOrCreateAccessibleProperties().label = "Settings Scroll View";
422+
423+
m_SearchField = m_SettingsView.Q<TextField>("settingsSearchField");
424+
m_SearchField.GetOrCreateAccessibleProperties().label = "Search";
425+
m_SearchField.GetOrCreateAccessibleProperties().role = AccessibilityRole.SearchField;
426+
m_SearchField.RegisterValueChangedCallback((e) => UpdateSearchField());
418427

419428
// m_SettingsPopup = new PopupWindow();
420429
// m_SettingsPopup.content = m_SettingsView;
@@ -607,6 +616,35 @@ public void PauseGame()
607616
Gameplay.instance.PauseGame();
608617
}
609618

619+
void UpdateSearchField()
620+
{
621+
var searchText = m_SearchField.text.Trim().ToLowerInvariant();
622+
623+
foreach (var field in m_SettingsView.Query<Label>(className: "unity-base-field__label").ToList())
624+
{
625+
if (string.IsNullOrEmpty(searchText))
626+
{
627+
field.parent.style.display = DisplayStyle.Flex;
628+
continue;
629+
}
630+
631+
var label = field.Q<Label>();
632+
633+
if (label != null && label.text.ToLowerInvariant().Contains(searchText))
634+
{
635+
field.parent.style.display = DisplayStyle.Flex;
636+
}
637+
else
638+
{
639+
field.parent.style.display = DisplayStyle.None;
640+
}
641+
}
642+
643+
// Refresh the hierarchy to ensure the screen reader is aware of the changes.
644+
//AccessibilityManager.GetService<UITkAccessibilityService>()?.RebuildHierarchy();
645+
//m_WasHierarchyRefreshed = true;
646+
}
647+
610648
/// <summary>
611649
/// Regenerates all the letter cards.
612650
/// </summary>

0 commit comments

Comments
 (0)