commit 8c43337af2fb3ed5072d3ef0162c9d90eaba3b38
Author: Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sun Oct 21 17:40:18 2018 -0400
Commit: Simon Howard <fraggle@soulsphere.org>
CommitDate: Sun Oct 21 17:40:18 2018 -0400
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.
---
textscreen/txt_window.c | 25 ++++++++++++++++---------
textscreen/txt_window.h | 4 ++--
2 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c
index 422e3e17..ad12945f 100644
--- 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 @@ void TXT_SetWindowAction(txt_window_t *window,
if (action != NULL)
{
- action->widget.parent = &window->table.widget;
+ action->parent = &window->table.widget;
}
}
@@ -82,7 +84,9 @@ txt_window_t *TXT_NewWindow(const char *title)
TXT_AddWidget(win, TXT_NewSeparator(NULL));
for (i=0; i<3; ++i)
+ {
win->actions[i] = NULL;
+ }
TXT_AddDesktopWindow(win);
@@ -164,7 +168,7 @@ static void LayoutActionArea(txt_window_t *window)
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,16 +176,17 @@ static void LayoutActionArea(txt_window_t *window)
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
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,25 +194,27 @@ static void LayoutActionArea(txt_window_t *window)
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
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 @@ static int MouseButtonPress(txt_window_t *window, int b)
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)
diff --git a/textscreen/txt_window.h b/textscreen/txt_window.h
index 7042ecf5..edd0de68 100644
--- a/textscreen/txt_window.h
+++ b/textscreen/txt_window.h
@@ -72,7 +72,7 @@ struct txt_window_s
// 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_SetWindowPosition(txt_window_t *window,
*/
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