Skip to content

Commit

Permalink
semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
danemadsen committed May 21, 2024
1 parent 997123d commit afa43f4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 58 deletions.
102 changes: 49 additions & 53 deletions lib/ui/mobile/widgets/buttons/menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,61 +29,56 @@ class _MenuButtonState extends State<MenuButton> {

@override
Widget build(BuildContext context) {
return Semantics(
label: 'Menu Button',
hint: 'Open the menu to select a model or switch to a different page',
excludeSemantics: true,
child: Consumer<Session>(
builder: (context, session, child) {
if (canUseCache(session)) {
options = cache;
return IconButton(
key: iconButtonKey,
icon: const Icon(
Icons.account_tree_rounded,
size: 24,
),
onPressed: onPressed,
);
}
else {
lastModelType = session.model.type;
lastCheck = DateTime.now();

return FutureBuilder(
future: session.model.options,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
options = snapshot.data as List<String>;
cache = options;

return IconButton(
key: iconButtonKey,
icon: const Icon(
Icons.account_tree_rounded,
size: 24,
),
onPressed: onPressed,
);
} else {
return const Padding(
padding: EdgeInsets.all(8.0), // Adjust padding to match the visual space of the IconButton
child: SizedBox(
width: 24, // Width of the CircularProgressIndicator
height: 24, // Height of the CircularProgressIndicator
child: Center(
child: CircularProgressIndicator(
strokeWidth: 3.0, // Adjust the thickness of the spinner here
),
return Consumer<Session>(
builder: (context, session, child) {
if (canUseCache(session)) {
options = cache;
return IconButton(
tooltip: 'Open Menu',
key: iconButtonKey,
icon: const Icon(
Icons.account_tree_rounded,
size: 24,
),
onPressed: onPressed,
);
}
else {
lastModelType = session.model.type;
lastCheck = DateTime.now();
return FutureBuilder(
future: session.model.options,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
options = snapshot.data as List<String>;
cache = options;
return IconButton(
tooltip: 'Open Menu',
key: iconButtonKey,
icon: const Icon(
Icons.account_tree_rounded,
size: 24,
),
onPressed: onPressed,
);
} else {
return const Padding(
padding: EdgeInsets.all(8.0), // Adjust padding to match the visual space of the IconButton
child: SizedBox(
width: 24, // Width of the CircularProgressIndicator
height: 24, // Height of the CircularProgressIndicator
child: Center(
child: CircularProgressIndicator(
strokeWidth: 3.0, // Adjust the thickness of the spinner here
),
),
);
}
),
);
}
);
}
}
);
}
)
}
);
}

Expand All @@ -106,8 +101,9 @@ class _MenuButtonState extends State<MenuButton> {
tileColor: session.model.name == modelName ? Theme.of(context).colorScheme.secondary : null,
);
}
)))
.toList();
)
)
).toList();

showMenu(
context: context,
Expand Down
7 changes: 5 additions & 2 deletions lib/ui/mobile/widgets/chat_widgets/chat_branch_switcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class _ChatBranchSwitcherState extends State<ChatBranchSwitcher> {
return Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
children: [
IconButton(
tooltip: 'Previous chat branch',
padding: const EdgeInsets.all(0),
onPressed: () {
if (!session.chat.tail.finalised) return;
Expand All @@ -40,9 +41,11 @@ class _ChatBranchSwitcherState extends State<ChatBranchSwitcher> {
),
Text(
'${currentIndex + 1}/$siblingCount',
style: Theme.of(context).textTheme.labelLarge
style: Theme.of(context).textTheme.labelLarge,
semanticsLabel: 'Chat branch ${currentIndex + 1} of $siblingCount',
),
IconButton(
tooltip: 'Next chat branch',
padding: const EdgeInsets.all(0),
onPressed: () {
if (!session.chat.tail.finalised) return;
Expand Down
12 changes: 9 additions & 3 deletions lib/ui/mobile/widgets/chat_widgets/chat_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class _ChatMessageState extends State<ChatMessage> with SingleTickerProviderStat
node.role == ChatRole.user ? user.name : character.name,
style: const TextStyle(
fontWeight: FontWeight.normal,
color: Colors
.white, // This color is needed, but it will be overridden by the shader.
color: Colors.white,
fontSize: 20,
),
)
Expand Down Expand Up @@ -80,6 +79,7 @@ class _ChatMessageState extends State<ChatMessage> with SingleTickerProviderStat
List<Widget> userOptions() {
return [
IconButton(
tooltip: 'Edit Message',
onPressed: onEdit,
icon: const Icon(Icons.edit),
),
Expand All @@ -89,6 +89,7 @@ class _ChatMessageState extends State<ChatMessage> with SingleTickerProviderStat
List<Widget> assistantOptions() {
return [
IconButton(
tooltip: 'Regenerate Response',
onPressed: onRegenerate,
icon: const Icon(Icons.refresh),
),
Expand Down Expand Up @@ -125,11 +126,13 @@ class _ChatMessageState extends State<ChatMessage> with SingleTickerProviderStat
),
Row(children: [
IconButton(
tooltip: 'Approve Edit',
padding: const EdgeInsets.all(0),
onPressed: () => onEditingDone(messageController.text),
icon: const Icon(Icons.done)
),
IconButton(
tooltip: 'Cancel Edit',
padding: const EdgeInsets.all(0),
onPressed: onEditingCancel,
icon: const Icon(Icons.close)
Expand All @@ -156,7 +159,10 @@ class _ChatMessageState extends State<ChatMessage> with SingleTickerProviderStat
if (part.isEmpty) continue;

if (i % 2 == 0) {
widgets.add(SelectableText(part, style: TextStyle(
widgets.add(
SelectableText(
part,
style: TextStyle(
fontWeight: FontWeight.normal,
color: Theme.of(context).colorScheme.onPrimary,
fontSize: 16,
Expand Down

0 comments on commit afa43f4

Please sign in to comment.