Skip to content

Commit de93900

Browse files
author
Bianca Marina Stana
committed
Merge branch 'unite2025/lsp-uitk' into unite2025/screen-reader-improvements
2 parents 6f4fd9a + 9399072 commit de93900

File tree

11 files changed

+213
-13
lines changed

11 files changed

+213
-13
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: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
#if UNITY_6000_3_OR_NEWER
34+
public override AccessibilityRole GetRole() => AccessibilityRole.Dropdown;
35+
#endif // UNITY_6000_3_OR_NEWER
36+
37+
protected override void BindToElement(VisualElement element)
38+
{
39+
base.BindToElement(element);
40+
element.RegisterCallback<PointerDownEvent>(OnPointerDown);
41+
element.RegisterCallback<NavigationSubmitEvent>(OnNavigationSubmit);
42+
}
43+
44+
protected override void UnbindFromElement(VisualElement element)
45+
{
46+
element.UnregisterCallback<PointerDownEvent>(OnPointerDown);
47+
element.UnregisterCallback<NavigationSubmitEvent>(OnNavigationSubmit);
48+
base.UnbindFromElement(element);
49+
}
50+
51+
void OnNavigationSubmit(NavigationSubmitEvent evt)
52+
{
53+
OnScreenDebug.Log("Submit event received by " + ownerElement.name);
54+
ScheduledCheckForOpenedPopupMenu();
55+
}
56+
57+
void OnPointerDown(PointerDownEvent evt)
58+
{
59+
OnScreenDebug.Log("Pointer Down event " + ownerElement.name);
60+
61+
ScheduledCheckForOpenedPopupMenu();
62+
}
63+
64+
void ScheduledCheckForOpenedPopupMenu()
65+
{
66+
if (m_HasPendingCheck)
67+
{
68+
return;
69+
}
70+
71+
m_HasPendingCheck = true;
72+
ownerElement.schedule.Execute(() =>
73+
{
74+
m_HasPendingCheck = false;
75+
CheckForOpenedPopupMenu();
76+
}).ExecuteLater(300);
77+
}
78+
79+
void CheckForOpenedPopupMenu()
80+
{
81+
var panel = ownerElement.panel;
82+
83+
if (panel == null)
84+
{
85+
return;
86+
}
87+
88+
var panelRootVisualElement = panel.visualTree;
89+
var popupMenu = panelRootVisualElement.Q(classes: GenericDropdownMenu.ussClassName);
90+
91+
OnScreenDebug.Log("Showing popup menu: " + (popupMenu != null));
92+
93+
if (popupMenu != null)
94+
{
95+
var popupAcc = popupMenu.GetOrCreateAccessibleProperties();
96+
97+
#if UNITY_6000_3_OR_NEWER
98+
popupAcc.role = AccessibilityRole.Dropdown;
99+
#endif // UNITY_6000_3_OR_NEWER
100+
popupAcc.active = false;
101+
popupAcc.modal = true;
102+
103+
// Setup items in the popup menu
104+
var items = popupMenu.Query(classes: GenericDropdownMenu.itemUssClassName).ToList();
105+
var i = 0;
106+
107+
OnScreenDebug.Log("Item count : " + items.Count);
108+
foreach (var item in items)
109+
{
110+
// if (item.GetAccessibleProperties() != null)
111+
// continue;
112+
113+
var itemAcc = item.GetOrCreateAccessibleProperties();
114+
var itemLabel = item.Q<Label>();
115+
116+
itemAcc.label = itemLabel != null ? itemLabel.text : $"Item {i}";
117+
itemAcc.role = AccessibilityRole.Button;
118+
itemLabel.GetOrCreateAccessibleProperties().ignored = true;
119+
i++;
120+
}
121+
122+
// NotifyChange();
123+
}
124+
125+
/*
126+
#if UNITY_6000_3_OR_NEWER
127+
var popup = ve.Q("unity-popup");
128+
129+
if (popup != null && popup.style.display == DisplayStyle.Flex)
130+
{
131+
SetState(AccessibilityState.Expanded);
132+
}
133+
else
134+
{
135+
SetState(AccessibilityState.Collapsed);
136+
}
137+
#endif // UNITY_6000_3_OR_NEWER
138+
*/
139+
}
140+
}
141+
}

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/ButtonHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public override string GetLabel()
2929
return (ownerElement as Button)?.text;
3030
}
3131

32+
public override AccessibilityRole GetRole() => AccessibilityRole.Button;
33+
3234
protected override void BindToElement(VisualElement ve)
3335
{
3436
}
35-
36-
public override AccessibilityRole GetRole() => AccessibilityRole.Button;
3737
}
3838
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public override string GetHint()
3030
return LocalizationSettings.StringDatabase.GetLocalizedString("Game Text", "DROPDOWN_CLOSED_HINT");
3131
}
3232

33+
#if UNITY_6000_3_OR_NEWER
34+
public override AccessibilityRole GetRole() => AccessibilityRole.Dropdown;
35+
#endif // UNITY_6000_3_OR_NEWER
36+
3337
protected override void BindToElement(VisualElement element)
3438
{
3539
base.BindToElement(element);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace Unity.Samples.ScreenReader
77
[Preserve]
88
class LabelHandler : VisualElementAccessibilityHandler
99
{
10-
public override AccessibilityRole GetRole() => AccessibilityRole.StaticText;
11-
1210
public override string GetLabel()
1311
{
1412
return (ownerElement as Label)?.text;
1513
}
14+
15+
public override AccessibilityRole GetRole() => AccessibilityRole.StaticText;
1616
}
1717
}

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

Lines changed: 5 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,10 @@ namespace Unity.Samples.ScreenReader
78
[Preserve]
89
public class ScrollViewHandler : VisualElementAccessibilityHandler
910
{
11+
#if UNITY_6000_3_OR_NEWER
12+
public override AccessibilityRole GetRole() => AccessibilityRole.ScrollView;
13+
#endif // UNITY_6000_3_OR_NEWER
14+
1015
protected override void BindToElement(VisualElement ve)
1116
{
1217
var scrollView = ve as ScrollView;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using UnityEngine.Accessibility;
12
using UnityEngine.UIElements;
23

34
namespace Unity.Samples.ScreenReader
@@ -25,6 +26,10 @@ public override string GetLabel()
2526
{
2627
return m_Tab.label;
2728
}
29+
30+
#if UNITY_6000_3_OR_NEWER
31+
public override AccessibilityRole GetRole() => AccessibilityRole.TabButton;
32+
#endif // UNITY_6000_3_OR_NEWER
2833
}
2934

3035
class TabHandlerCreator : VisualElementAccessibilityHandlerFactory.ICreator

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());

0 commit comments

Comments
 (0)