ref: 8c43337af2fb3ed5072d3ef0162c9d90eaba3b38
parent: 74cdbeddf5d96c1ca3e934ff9136a040a2d47055
author: Simon Howard <[email protected]>
date: Sun Oct 21 13:40:18 EDT 2018
textscreen: Allow any widget in action area. It may be desirable to wrap a window action in a txt_conditional_t sometimes so that actions dynamically appear based on how the config changes. So change the TXT_SetWindowAction() API to accept any widget instead of mandating a txt_window_action_t.
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -35,8 +35,10 @@
void TXT_SetWindowAction(txt_window_t *window,
txt_horiz_align_t position,
- txt_window_action_t *action)
+ TXT_UNCAST_ARG(action))
{
+ TXT_CAST_ARG(txt_widget_t, action);
+
if (window->actions[position] != NULL)
{
TXT_DestroyWidget(window->actions[position]);
@@ -48,7 +50,7 @@
if (action != NULL)
{
- action->widget.parent = &window->table.widget;
+ action->parent = &window->table.widget;
}
}
@@ -82,7 +84,9 @@
TXT_AddWidget(win, TXT_NewSeparator(NULL));
for (i=0; i<3; ++i)
+ {
win->actions[i] = NULL;
+ }
TXT_AddDesktopWindow(win);
@@ -164,7 +168,7 @@
if (window->actions[TXT_HORIZ_LEFT] != NULL)
{
- widget = (txt_widget_t *) window->actions[TXT_HORIZ_LEFT];
+ widget = window->actions[TXT_HORIZ_LEFT];
TXT_CalcWidgetSize(widget);
@@ -172,9 +176,10 @@
widget->y = window->window_y + window->window_h - widget->h - 1;
// Adjust available space:
-
space_available -= widget->w;
space_left_offset += widget->w;
+
+ TXT_LayoutWidget(widget);
}
// Draw the right action
@@ -181,7 +186,7 @@
if (window->actions[TXT_HORIZ_RIGHT] != NULL)
{
- widget = (txt_widget_t *) window->actions[TXT_HORIZ_RIGHT];
+ widget = window->actions[TXT_HORIZ_RIGHT];
TXT_CalcWidgetSize(widget);
@@ -189,8 +194,9 @@
widget->y = window->window_y + window->window_h - widget->h - 1;
// Adjust available space:
-
space_available -= widget->w;
+
+ TXT_LayoutWidget(widget);
}
// Draw the center action
@@ -197,17 +203,18 @@
if (window->actions[TXT_HORIZ_CENTER] != NULL)
{
- widget = (txt_widget_t *) window->actions[TXT_HORIZ_CENTER];
+ widget = window->actions[TXT_HORIZ_CENTER];
TXT_CalcWidgetSize(widget);
// The left and right widgets have left a space sandwiched between
// them. Center this widget within that space.
-
widget->x = window->window_x
+ space_left_offset
+ (space_available - widget->w) / 2;
widget->y = window->window_y + window->window_h - widget->h - 1;
+
+ TXT_LayoutWidget(widget);
}
}
@@ -417,7 +424,7 @@
for (i=0; i<3; ++i)
{
- widget = (txt_widget_t *) window->actions[i];
+ widget = window->actions[i];
if (widget != NULL
&& x >= widget->x && x < (signed) (widget->x + widget->w)
--- a/textscreen/txt_window.h
+++ b/textscreen/txt_window.h
@@ -72,7 +72,7 @@
// Actions that appear in the box at the bottom of the window
- txt_window_action_t *actions[3];
+ txt_widget_t *actions[3];
// Callback functions to invoke when keys/mouse buttons are pressed
@@ -159,7 +159,7 @@
*/
void TXT_SetWindowAction(txt_window_t *window, txt_horiz_align_t position,
- txt_window_action_t *action);
+ TXT_UNCAST_ARG(action));
/**
* Set a callback function to be invoked whenever a key is pressed within