Skip to content

Commit 945e03c

Browse files
committed
Fixed first login page not accessible. Fix some accessible label and hint.
1 parent 62075a6 commit 945e03c

File tree

7 files changed

+227
-105
lines changed

7 files changed

+227
-105
lines changed

Assets/Resources/UITk/MainView.uxml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
</ui:VisualElement>
1010
<ui:VisualElement name="loginView" style="flex-grow: 1; align-items: center; justify-content: center;">
1111
<ui:VisualElement name="logo" class="lsp-logo"/>
12-
<ui:Label class="title-text">
13-
<Bindings>
14-
<UnityEngine.Localization.LocalizedString property="text" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(405763420160)"/>
15-
</Bindings>
16-
</ui:Label>
17-
<ui:TextField placeholder-text="Enter your name" name="TextField" style="flex-direction: column; min-width: 252px; width: 949px;">
12+
<ui:TextField placeholder-text="Enter your name" name="loginNameField" label="What is your name?" style="min-width: 252px; width: 949px;">
1813
<Bindings>
1914
<ui:DataBinding property="value" data-source-path="userName" binding-mode="TwoWay"/>
2015
<UnityEngine.Localization.LocalizedString property="placeholderText" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(775025750016)"/>
16+
<UnityEngine.Localization.LocalizedString property="label" table="GUID:cc1d194facb1d9d4380a9ea2032c10ca" entry="Id(405763420160)"/>
2117
</Bindings>
2218
</ui:TextField>
2319
<ui:Button name="loginButton" class="purple">

Assets/Resources/UITk/Themes/LetterSpellTheme.uss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
rotate: -15deg;
137137
}
138138

139+
.lsp-letter-card:focus {
140+
border-bottom-color: rgb(255, 0, 0);
141+
}
142+
139143
.lsp-letter-card__button-container {
140144
position: absolute;
141145
top: 100%;
@@ -581,3 +585,14 @@
581585

582586
#clueLabel {
583587
}
588+
589+
#loginNameField {
590+
flex-direction: column;
591+
}
592+
593+
#loginNameField .unity-base-field__label {
594+
-unity-text-align: middle-center;
595+
color: rgb(255, 255, 255);
596+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
597+
margin-bottom: 30px;
598+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class DropdownFieldHandler : BaseFieldHandler<string>
1010
{
1111
bool m_HasPendingCheck;
1212

13+
14+
public override string GetHint()
15+
{
16+
return "Double tap to expand";
17+
}
18+
1319
protected override void BindToElement(VisualElement element)
1420
{
1521
base.BindToElement(element);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ namespace Unity.Samples.ScreenReader
77
[Preserve]
88
class TextFieldFieldHandler : BaseFieldHandler<string>
99
{
10+
public override string GetValue()
11+
{
12+
var textField = ownerElement as TextField;
13+
14+
if (string.IsNullOrEmpty(textField.value))
15+
return ownerElement is TextField tf ? tf.textEdition.placeholder : textField.value;
16+
return base.GetValue();
17+
}
18+
1019
public override AccessibilityRole GetRole()
1120
{
1221
return AccessibilityRole.TextField;

Assets/Scripts/UITk/Card.cs

Lines changed: 102 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
using UnityEngine.Scripting;
66
using UnityEngine.UIElements;
77
using Unity.Samples.ScreenReader;
8+
using UnityEditor;
89
using Button = UnityEngine.UIElements.Button;
910

1011
namespace Unity.Samples.LetterSpell
1112
{
12-
class UITkLetterCard : VisualElement
13+
class UITkLetterCard : AccessibleVisualElement
1314
{
1415
Label m_TextElement;
1516
Vector2 m_Start;
@@ -27,86 +28,75 @@ class UITkLetterCard : VisualElement
2728
// public override string GetLabel() => (owner as UITkLetterCard).text;
2829
// }
2930

30-
public bool selected => cardListView?.selectedCard == this;
31+
private bool m_Selected;
3132

32-
public string text
33+
public bool selected
3334
{
34-
get => m_TextElement.text;
35-
set => m_TextElement.text = value;
35+
get => m_Selected;
36+
set
37+
{
38+
if (m_Selected == value)
39+
return;
40+
m_Selected = value;
41+
if (value)
42+
Focus();
43+
UpdateSelectedState();
44+
}
3645
}
3746

38-
public event Action<int, int> dropped;
39-
40-
[RegisterAccessibilityHandler(typeof(UITkLetterCard))]
41-
[Preserve]
42-
class AccessibleLetterCardHandler : VisualElementAccessibilityHandler
47+
void UpdateSelectedState()
4348
{
44-
UITkLetterCard card => ownerElement as UITkLetterCard;
45-
46-
public override string GetLabel() => card.text;
47-
48-
protected override void BindToElement(VisualElement ve)
49-
{
50-
card.m_TextElement.GetOrCreateAccessibleProperties().ignored = true;
51-
}
49+
EnableInClassList("selected", selected);
50+
}
5251

53-
public AccessibleLetterCardHandler()
52+
public string text
53+
{
54+
get => m_TextElement.text;
55+
set
5456
{
55-
OnSelect += () =>
56-
{
57-
var letter = ownerElement as UITkLetterCard;
58-
59-
if (!letter.selected)
60-
{
61-
letter.Select();
62-
}
63-
else
64-
{
65-
letter.Unselect();
66-
}
67-
68-
return true;
69-
};
57+
m_TextElement.text = value;
58+
accessible.label = value;
7059
}
7160
}
7261

62+
public event Action<int, int> dropped;
63+
7364
public void Select()
7465
{
75-
cardListView.selectedCard = this;
76-
OnScreenDebug.Log("Selected card: " + text);
66+
if (cardListView.selectedCard != this)
67+
{
68+
cardListView.selectedCard = this;
69+
70+
// check whether we are focused or not
71+
var focused = this.focusController?.focusedElement == this;
72+
73+
AssistiveSupport.notificationDispatcher.SendAnnouncement($"Card {text} selected. Swipe Left or Right to move the card." + (focused ? "Or Double tap to unselect it." : ""));
74+
75+
OnScreenDebug.Log("Selected card: " + text);
76+
}
7777
}
7878

7979
public void Unselect()
8080
{
8181
if (this == cardListView.selectedCard)
8282
{
83-
cardListView.selectedCard = null;
83+
// check whether we are focused or not
84+
var focused = this.focusController?.focusedElement == this;
85+
cardListView.selectedCard = null;
86+
87+
AssistiveSupport.notificationDispatcher.SendAnnouncement($"Card {text} selected. Swipe Left or Right to move the card." + (focused ? "Or Double tap to unselect it." : ""));
88+
8489
}
8590
}
91+
8692
public UITkLetterCard()
8793
{
8894
m_TextElement = new Label();
8995
Add(m_TextElement);
9096
AddToClassList("lsp-letter-card");
9197
AddToClassList("lsp-card-view-item");
92-
93-
// style.transitionProperty = new StyleList<StylePropertyName>(new List<StylePropertyName>{ new StylePropertyName("left")});
94-
// style.transitionDuration = new StyleList<TimeValue>(new List<TimeValue>{new(0.5f)});
95-
/*style.marginLeft = 4;
96-
style.marginTop = 4;
97-
style.marginRight = 4;
98-
style.marginBottom = 4;
99-
*/
100-
/*style.fontSize = 40;
101-
style.alignItems = Align.Center;
102-
style.justifyContent = Justify.Center;
103-
104-
style.borderBottomLeftRadius = 6;
105-
style.borderTopLeftRadius = 6;
106-
style.borderBottomRightRadius = 6;
107-
style.borderTopRightRadius = 6;*/
108-
109-
// style.backgroundColor = Color.white;
98+
99+
focusable = true;
110100

111101
style.position = Position.Absolute;
112102

@@ -146,6 +136,26 @@ public UITkLetterCard()
146136

147137
RegisterCallbacksOnTarget();
148138
RegisterCallback<AttachToPanelEvent>(OnAttachToPanel);
139+
RegisterCallback<FocusInEvent>(OnFocusIn);
140+
RegisterCallback<BlurEvent>(OnBlur);
141+
142+
// Accessibility
143+
m_TextElement.GetOrCreateAccessibleProperties().ignored = true;
144+
accessible.selected += () =>
145+
{
146+
if (!selected)
147+
{
148+
Select();
149+
OnScreenDebug.Log("Selected card: " + text);
150+
}
151+
else
152+
{
153+
OnScreenDebug.Log("UnSelected card: " + text);
154+
Unselect();
155+
}
156+
157+
return true;
158+
};
149159
}
150160

151161
bool m_Animated;
@@ -173,6 +183,22 @@ void OnAttachToPanel(AttachToPanelEvent e)
173183
// TODO: FIX ANIMATION WHEN STARTING A GAME
174184
// schedule.Execute(() => animated = true).ExecuteLater(500);
175185
}
186+
187+
void OnFocusIn(FocusInEvent e)
188+
{
189+
AssistiveSupport.notificationDispatcher.SendAnnouncement($"Double tap to select Card {text} and start moving.");
190+
191+
OnScreenDebug.Log("OnFocusIn " + text);
192+
e.StopPropagation();
193+
}
194+
195+
void OnBlur(BlurEvent e)
196+
{
197+
OnScreenDebug.Log("Un Focus " + text);
198+
accessible.hint = null;
199+
e.StopPropagation();
200+
}
201+
176202
protected Rect CalculatePosition(float x, float y, float width, float height)
177203
{
178204
var rect = new Rect(x, y, width, height);
@@ -266,15 +292,6 @@ protected void OnMouseDown(MouseDownEvent e)
266292
return;
267293
}
268294

269-
if (e.ctrlKey)
270-
{
271-
cardListView.selectedCard = cardListView.selectedCard == this ? null : this;
272-
}
273-
else
274-
{
275-
cardListView.selectedCard = this;
276-
}
277-
278295
if (m_Active)
279296
{
280297
e.StopImmediatePropagation();
@@ -302,6 +319,8 @@ protected void OnMouseMove(MouseMoveEvent e)
302319
{
303320
if (m_Active)
304321
{
322+
// Ensure the card is selected when we start dragging it.
323+
Select();
305324
var diff = e.localMousePosition - m_Start;
306325

307326
if (!dragging && Math.Abs(diff.x) > 5)
@@ -346,6 +365,18 @@ protected void OnMouseUp(MouseUpEvent e)
346365
{
347366
if (e.button == (int)MouseButton.LeftMouse)
348367
{
368+
// Select or unselect the card if we didn't drag it.
369+
if (!m_Dragging)
370+
{
371+
if (selected)
372+
{
373+
Unselect();
374+
}
375+
else
376+
{
377+
Select();
378+
}
379+
}
349380
m_Active = false;
350381
dragging = false;
351382

@@ -651,10 +682,14 @@ public UITkLetterCard selectedCard
651682
return;
652683
}
653684

654-
m_SelectedCard?.RemoveFromClassList("selected");
685+
if (m_SelectedCard != null)
686+
m_SelectedCard.selected = false;
687+
655688
m_SelectedCard = value;
656-
m_SelectedCard?.AddToClassList("selected");
657-
m_SelectedCard?.UpdateButtonEnableState();
689+
OnScreenDebug.Log("ListView selected card: " + (m_SelectedCard != null ? m_SelectedCard.text : "null"));
690+
691+
if (m_SelectedCard != null)
692+
m_SelectedCard.selected = true;
658693
}
659694
}
660695

Assets/Scripts/UITk/Controls/StackView.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Unity.Samples.ScreenReader;
23
using UnityEngine;
34
using UnityEngine.UIElements;
45

@@ -68,18 +69,16 @@ public VisualElement activeView
6869
}
6970

7071
m_ActiveView = value;
71-
72+
index = IndexOf(m_ActiveView);
7273
if (panel != null)
7374
{
7475
StartTransition(oldView, m_ActiveView);
7576
}
7677
else
7778
{
7879
UpdateViews();
80+
activeViewChanged?.Invoke();
7981
}
80-
81-
index = IndexOf(m_ActiveView);
82-
activeViewChanged?.Invoke();
8382
}
8483
}
8584

@@ -126,15 +125,21 @@ void StartTransition(VisualElement from, VisualElement to)
126125

127126
fadeOut.onAnimationCompleted += () =>
128127
{
128+
activeViewChanged?.Invoke();
129129
};
130130
}
131+
else
132+
{
133+
activeViewChanged?.Invoke();
134+
}
131135
};
132136
}
133137
else if (to != null)
134138
{
135139
// If there is no from, just show the
136140
to.style.display = DisplayStyle.Flex;
137141
to.style.opacity = 1;
142+
activeViewChanged?.Invoke();
138143
}
139144
}
140145

0 commit comments

Comments
 (0)