ref: 68786296378d283053e6b144433b704440505628
parent: 7a2f14efc374db3404c2531bc25609809a233c6b
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Jul 11 13:13:20 EDT 2015
textscreen: Allow cycling through tables with tab key. Most GUI toolkits allow using the tab key to cycle through windows, so support this (and shift-tab to cycle backwards) just for completeness.
--- a/textscreen/txt_scrollpane.c
+++ b/textscreen/txt_scrollpane.c
@@ -402,7 +402,8 @@
if ((key == KEY_UPARROW || key == KEY_DOWNARROW
|| key == KEY_LEFTARROW || key == KEY_RIGHTARROW
- || key == KEY_PGUP || key == KEY_PGDN)
+ || key == KEY_PGUP || key == KEY_PGDN
+ || key == KEY_TAB)
&& scrollpane->child->widget_class == &txt_table_class)
{
if (PageSelectedWidget(scrollpane, key))
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -500,6 +500,29 @@
}
}
+ if (key == KEY_TAB)
+ {
+ int dir;
+ int i;
+
+ dir = TXT_GetModifierState(TXT_MOD_SHIFT) ? -1 : 1;
+
+ // Cycle through all widgets until we find one that can be selected.
+ for (i = table->selected_y * table->columns + table->selected_x + dir;
+ i >= 0 && i < table->num_widgets;
+ i += dir)
+ {
+ if (IsActualWidget(table->widgets[i])
+ && TXT_SelectableWidget(table->widgets[i]))
+ {
+ ChangeSelection(table, i % table->columns, i / table->columns);
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
if (key == KEY_DOWNARROW)
{
int new_x, new_y;
@@ -518,7 +541,7 @@
return 1;
}
- }
+ }
}
if (key == KEY_UPARROW)
@@ -539,7 +562,7 @@
return 1;
}
- }
+ }
}
if (key == KEY_LEFTARROW)