commit 68786296378d283053e6b144433b704440505628
Author: Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sat Jul 11 17:13:20 2015 -0400
Commit: Simon Howard <fraggle@soulsphere.org>
CommitDate: Sat Jul 11 17:13:20 2015 -0400
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.
---
textscreen/txt_scrollpane.c | 3 ++-
textscreen/txt_table.c | 27 +++++++++++++++++++++++++--
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/textscreen/txt_scrollpane.c b/textscreen/txt_scrollpane.c
index e1f2d3cb..2388d0cc 100644
--- a/textscreen/txt_scrollpane.c
+++ b/textscreen/txt_scrollpane.c
@@ -402,7 +402,8 @@ static int TXT_ScrollPaneKeyPress(TXT_UNCAST_ARG(scrollpane), int key)
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))
diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c
index 4e4c68fb..fdadac27 100644
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -500,6 +500,29 @@ static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key)
}
}
+ 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 @@ static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key)
return 1;
}
- }
+ }
}
if (key == KEY_UPARROW)
@@ -539,7 +562,7 @@ static int TXT_TableKeyPress(TXT_UNCAST_ARG(table), int key)
return 1;
}
- }
+ }
}
if (key == KEY_LEFTARROW)