Skip to content

Commit 4fbc089

Browse files
author
Bianca Marina Stana
committed
Merge branch 'unite2025/lsp-uitk' into unite2025/screen-reader-improvements
# Conflicts: # Assets/Scripts/Screen Reader/UITk/VisualTreeAccessibilityUpdater.cs
2 parents 65bf08e + 7bfe76d commit 4fbc089

19 files changed

+207
-133
lines changed

Assets/Resources/UITk/MainView.uxml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<ui:VisualElement name="logo" class="lsp-logo"/>
1616
<ui:TextField placeholder-text="Enter your name" name="loginNameField" label="What is your name?" language-direction="LTR" style="min-width: 252px; width: 949px;">
1717
<Bindings>
18-
<ui:DataBinding property="value" data-source-path="userName" binding-mode="TwoWay"/>
18+
<ui:DataBinding property="value" data-source-path="username" binding-mode="TwoWay"/>
1919
<UnityEngine.Localization.LocalizedString property="placeholderText" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(775025750016)"/>
2020
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(405763420160)"/>
2121
</Bindings>
@@ -103,7 +103,7 @@
103103
</ui:Label>
104104
<ui:TextField label="Username" placeholder-text="Enter your name" name="settingsUserNameField" language-direction="LTR">
105105
<Bindings>
106-
<ui:DataBinding property="value" data-source-path="userName" binding-mode="TwoWay"/>
106+
<ui:DataBinding property="value" data-source-path="username" binding-mode="TwoWay"/>
107107
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(3183403495424)"/>
108108
<UnityEngine.Localization.LocalizedString property="placeholderText" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(775025750016)"/>
109109
</Bindings>
@@ -121,13 +121,13 @@
121121
<UnityEngine.Localization.LocalizedString property="text" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(17127719464960)"/>
122122
</Bindings>
123123
</ui:Label>
124-
<ui:RadioButton label="3" name="settingsThreeWordsButton" value="true">
124+
<ui:RadioButton label="Three" name="settingsThreeWordsButton" value="true">
125125
<Bindings>
126126
<ui:DataBinding property="value" data-source-path="isThreeWords" binding-mode="TwoWay"/>
127127
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(17263564582912)"/>
128128
</Bindings>
129129
</ui:RadioButton>
130-
<ui:RadioButton label="6" name="settingsSixWordsButton">
130+
<ui:RadioButton label="Six" name="settingsSixWordsButton">
131131
<Bindings>
132132
<ui:DataBinding property="value" data-source-path="isSixWords" binding-mode="TwoWay"/>
133133
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(17369965686784)"/>
@@ -136,7 +136,7 @@
136136
</ui:VisualElement>
137137
<ui:Toggle label="Show Spelling Clues" name="settingsShowSpellingClues">
138138
<Bindings>
139-
<ui:DataBinding property="value" data-source-path="showsSpellingClues" binding-mode="TwoWay"/>
139+
<ui:DataBinding property="value" data-source-path="showSpellingClues" binding-mode="TwoWay"/>
140140
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(17491977990144)"/>
141141
<UnityEngine.Localization.LocalizedString property="text" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(1784705072656384)"/>
142142
</Bindings>

Assets/Scripts/Gameplay/GameViewController.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class GameViewController : MonoBehaviour
4545
/// </summary>
4646
LetterCard m_AccessibilitySelectedCard;
4747

48-
/// <summary>
49-
/// Keeps track of whether the hierarchy was refreshed using AccessibilityManager.RefreshHierarchy();
50-
/// </summary>
51-
bool m_WasHierarchyRefreshed;
52-
5348
void OnEnable()
5449
{
5550
m_Model.letterCardsChanged += OnLetterCardsChanged;
@@ -264,13 +259,6 @@ void MoveSelectedCard()
264259
return;
265260
}
266261

267-
// Don't move the card if the focus change occurred because of a hierarchy rebuild.
268-
if (m_WasHierarchyRefreshed)
269-
{
270-
m_WasHierarchyRefreshed = false;
271-
return;
272-
}
273-
274262
// If we reach this code, it means we're dragging the card.
275263
var selectedCardIndex = m_AccessibilitySelectedCard.transform.GetSiblingIndex();
276264
var focusedCardIndex = m_AccessibilityFocusedCard.transform.GetSiblingIndex();

Assets/Scripts/Screen Reader/UITk/AccessibleProperties.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void IncrementVersion(VisualElement element)
5353
internal Value<bool> m_IsActive = new(true);
5454
internal Value<string> m_Label;
5555
internal Value<AccessibilityRole> m_Role;
56+
internal Value<AccessibilityState> m_State;
5657
internal Value<bool> m_Ignored;
5758
internal Value<bool> m_Modal;
5859
internal Value<string> m_Value;
@@ -96,6 +97,13 @@ public AccessibilityRole role
9697
set => m_Role.Set(this, value);
9798
}
9899

100+
[UxmlAttribute, CreateProperty]
101+
public AccessibilityState state
102+
{
103+
get => m_State.Get();
104+
set => m_State.Set(this, value);
105+
}
106+
99107
[UxmlAttribute, CreateProperty]
100108
public string value
101109
{

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public override string GetLabel()
1414

1515
public override string GetValue()
1616
{
17-
var field = ownerElement as BaseField<TValueType>;
18-
return field == null ? "" : $"{field.value}";
17+
return ownerElement is BaseField<TValueType> field ? $"{field.value}" : "";
1918
}
2019

2120
protected override void BindToElement(VisualElement ve)
@@ -33,8 +32,15 @@ protected override void UnbindFromElement(VisualElement ve)
3332

3433
void OnValueChanged(ChangeEvent<TValueType> e)
3534
{
36-
EnsureLabelIsNotAccessible();
37-
NotifyChange();
35+
if (ownerElement is Toggle or RadioButton or Slider)
36+
{
37+
var updater = ownerElement.panel.GetAccessibilityUpdater();
38+
updater?.UpdateNode(this);
39+
}
40+
else
41+
{
42+
NotifyChange();
43+
}
3844
}
3945

4046
void EnsureLabelIsNotAccessible()
@@ -47,20 +53,4 @@ void EnsureLabelIsNotAccessible()
4753
}
4854
}
4955
}
50-
51-
[Preserve]
52-
class ToggleHandler : BaseFieldHandler<bool>
53-
{
54-
#if UNITY_2023_3_OR_NEWER
55-
public override AccessibilityRole GetRole() => AccessibilityRole.Toggle;
56-
#endif // UNITY_2023_3_OR_NEWER
57-
}
58-
59-
[Preserve]
60-
class RadioButtonHandler : BaseFieldHandler<bool>
61-
{
62-
#if UNITY_2023_3_OR_NEWER
63-
public override AccessibilityRole GetRole() => AccessibilityRole.Toggle;
64-
#endif // UNITY_2023_3_OR_NEWER
65-
}
6656
}

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ class BasePopupFieldHandler<TValue, TValueChoice> : BaseFieldHandler<TValue>
1313

1414
public BasePopupFieldHandler()
1515
{
16-
/*OnSelect += () =>
16+
selected += () =>
1717
{
18-
ownerElement.schedule.Execute(CheckForOpenedPopupMenu).ExecuteLater(200);
18+
ownerElement.schedule.Execute(CheckForOpenedPopupMenu).ExecuteLater(300);
1919

20-
using var evt = NavigationSubmitEvent.GetPooled();
20+
using var evt = NavigationSubmitEvent.GetPooled();
21+
evt.target = ownerElement;
2122
ownerElement.SendEvent(evt);
23+
2224
OnScreenDebug.Log("Submit event sent to " + ownerElement.name);
2325

24-
return false;//true;
25-
};*/
26+
return true;
27+
};
2628
}
2729

2830
public override string GetHint()
@@ -51,6 +53,7 @@ protected override void UnbindFromElement(VisualElement element)
5153
void OnNavigationSubmit(NavigationSubmitEvent evt)
5254
{
5355
OnScreenDebug.Log("Submit event received by " + ownerElement.name);
56+
5457
ScheduledCheckForOpenedPopupMenu();
5558
}
5659

@@ -115,27 +118,23 @@ void CheckForOpenedPopupMenu()
115118

116119
itemAcc.label = itemLabel != null ? itemLabel.text : $"Item {i}";
117120
itemAcc.role = AccessibilityRole.Button;
121+
itemAcc.state = item.hasCheckedPseudoState ? AccessibilityState.Selected : AccessibilityState.None;
122+
itemAcc.selected += () =>
123+
{
124+
using var evt = NavigationSubmitEvent.GetPooled();
125+
evt.target = item;
126+
item.SendEvent(evt);
127+
128+
return true;
129+
};
130+
118131
itemLabel.GetOrCreateAccessibleProperties().ignored = true;
132+
119133
i++;
120134
}
121135

122136
// NotifyChange();
123137
}
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-
*/
139138
}
140139
}
141140
}

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ public ButtonHandler()
1111
{
1212
selected += () =>
1313
{
14-
if (ownerElement is not Button button)
15-
{
16-
return false;
17-
}
18-
19-
using var e = new NavigationSubmitEvent();
20-
e.target = button;
21-
button.SendEvent(e);
14+
using var evt = NavigationSubmitEvent.GetPooled();
15+
evt.target = ownerElement;
16+
ownerElement.SendEvent(evt);
2217

2318
return true;
2419
};
@@ -31,8 +26,8 @@ public override string GetLabel()
3126

3227
public override AccessibilityRole GetRole() => AccessibilityRole.Button;
3328

34-
protected override void BindToElement(VisualElement ve)
35-
{
36-
}
29+
public override AccessibilityState GetState() => ownerElement is Button { hasCheckedPseudoState: true }
30+
? AccessibilityState.Selected
31+
: AccessibilityState.None;
3732
}
3833
}

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ class DropdownFieldHandler : BaseFieldHandler<string>
1313

1414
public DropdownFieldHandler()
1515
{
16-
/*OnSelect += () =>
16+
selected += () =>
1717
{
18-
ownerElement.schedule.Execute(CheckForOpenedPopupMenu).ExecuteLater(200);
18+
ownerElement.schedule.Execute(CheckForOpenedPopupMenu).ExecuteLater(300);
1919

20-
using var evt = NavigationSubmitEvent.GetPooled();
20+
using var evt = NavigationSubmitEvent.GetPooled();
21+
evt.target = ownerElement;
2122
ownerElement.SendEvent(evt);
23+
2224
OnScreenDebug.Log("Submit event sent to " + ownerElement.name);
2325

24-
return false;//true;
25-
};*/
26+
return true;
27+
};
2628
}
2729

2830
public override string GetHint()
@@ -115,27 +117,23 @@ void CheckForOpenedPopupMenu()
115117

116118
itemAcc.label = itemLabel != null ? itemLabel.text : $"Item {i}";
117119
itemAcc.role = AccessibilityRole.Button;
120+
itemAcc.state = item.hasCheckedPseudoState ? AccessibilityState.Selected : AccessibilityState.None;
121+
itemAcc.selected += () =>
122+
{
123+
using var evt = NavigationSubmitEvent.GetPooled();
124+
evt.target = item;
125+
item.SendEvent(evt);
126+
127+
return true;
128+
};
129+
118130
itemLabel.GetOrCreateAccessibleProperties().ignored = true;
131+
119132
i++;
120133
}
121134

122135
// NotifyChange();
123136
}
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-
*/
139137
}
140138
}
141139
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using UnityEngine.Accessibility;
2+
using UnityEngine.Scripting;
3+
using UnityEngine.UIElements;
4+
5+
namespace Unity.Samples.ScreenReader
6+
{
7+
[Preserve]
8+
class RadioButtonHandler : BaseFieldHandler<bool>
9+
{
10+
public RadioButtonHandler()
11+
{
12+
selected += () =>
13+
{
14+
using var evt = NavigationSubmitEvent.GetPooled();
15+
evt.target = ownerElement;
16+
ownerElement.SendEvent(evt);
17+
18+
return true;
19+
};
20+
}
21+
22+
public override string GetValue() => "";
23+
24+
#if UNITY_2023_3_OR_NEWER
25+
public override AccessibilityRole GetRole() => AccessibilityRole.Toggle;
26+
#endif // UNITY_2023_3_OR_NEWER
27+
28+
public override AccessibilityState GetState() => ownerElement is RadioButton { value: true }
29+
? AccessibilityState.Selected
30+
: AccessibilityState.None;
31+
}
32+
}

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

Lines changed: 3 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/SliderHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public void Step(bool incr)
3030
slider.value += step;
3131
}
3232

33+
public override string GetValue()
34+
{
35+
return ownerElement is Slider field ? $"{field.value:P0}" : "";
36+
}
37+
3338
#if UNITY_2023_3_OR_NEWER
3439
public override AccessibilityRole GetRole() => AccessibilityRole.Slider;
3540
#endif // UNITY_2023_3_OR_NEWER

0 commit comments

Comments
 (0)