Add TXT_NewButton2 for creating a button with a callback (for convenience).
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 673
This commit is contained in:
parent
0755f5ac88
commit
d3d4f6587f
4 changed files with 21 additions and 17 deletions
|
|
@ -44,7 +44,6 @@ void InsertNumber(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(value))
|
|||
|
||||
void AddNumberButton(txt_table_t *table, int value)
|
||||
{
|
||||
txt_button_t *button;
|
||||
char buf[10];
|
||||
int *val_copy;
|
||||
|
||||
|
|
@ -53,9 +52,7 @@ void AddNumberButton(txt_table_t *table, int value)
|
|||
|
||||
sprintf(buf, " %i ", value);
|
||||
|
||||
button = TXT_NewButton(buf);
|
||||
TXT_AddWidget(table, button);
|
||||
TXT_SignalConnect(button, "pressed", InsertNumber, val_copy);
|
||||
TXT_AddWidget(table, TXT_NewButton2(buf, InsertNumber, val_copy));
|
||||
}
|
||||
|
||||
void Operator(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(op))
|
||||
|
|
@ -69,7 +66,6 @@ void Operator(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(op))
|
|||
|
||||
void AddOperatorButton(txt_table_t *table, char *label, operator_t op)
|
||||
{
|
||||
txt_button_t *button;
|
||||
char buf[10];
|
||||
operator_t *op_copy;
|
||||
|
||||
|
|
@ -77,10 +73,8 @@ void AddOperatorButton(txt_table_t *table, char *label, operator_t op)
|
|||
*op_copy = op;
|
||||
|
||||
sprintf(buf, " %s ", label);
|
||||
button = TXT_NewButton(buf);
|
||||
|
||||
TXT_AddWidget(table, button);
|
||||
TXT_SignalConnect(button, "pressed", Operator, op_copy);
|
||||
TXT_AddWidget(table, TXT_NewButton2(buf, Operator, op_copy));
|
||||
}
|
||||
|
||||
void Calculate(TXT_UNCAST_ARG(button), void *unused)
|
||||
|
|
@ -113,7 +107,6 @@ void BuildGUI()
|
|||
{
|
||||
txt_window_t *window;
|
||||
txt_table_t *table;
|
||||
txt_button_t *equals_button;
|
||||
|
||||
window = TXT_NewWindow("Calculator");
|
||||
|
||||
|
|
@ -141,9 +134,8 @@ void BuildGUI()
|
|||
AddOperatorButton(table, "+", OP_PLUS);
|
||||
AddNumberButton(table, 0);
|
||||
TXT_AddWidget(table, NULL);
|
||||
equals_button = TXT_NewButton(" = ");
|
||||
TXT_SignalConnect(equals_button, "pressed", Calculate, NULL);
|
||||
TXT_AddWidget(table, equals_button);
|
||||
|
||||
TXT_AddWidget(table, TXT_NewButton2(" = ", Calculate, NULL));
|
||||
AddOperatorButton(table, "/", OP_DIV);
|
||||
|
||||
TXT_AddWidget(window, TXT_NewStrut(0, 1));
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ void SetupWindow(void)
|
|||
txt_window_t *window;
|
||||
txt_table_t *table;
|
||||
txt_table_t *rightpane;
|
||||
txt_button_t *button;
|
||||
txt_checkbox_t *cheesy_checkbox;
|
||||
txt_window_action_t *pwn;
|
||||
txt_label_t *toplabel;
|
||||
|
|
@ -121,10 +120,7 @@ void SetupWindow(void)
|
|||
|
||||
UpdateLabel(NULL, NULL);
|
||||
|
||||
button = TXT_NewButton("Close Window");
|
||||
TXT_AddWidget(window, button);
|
||||
|
||||
TXT_SignalConnect(button, "pressed", CloseWindow, NULL);
|
||||
TXT_AddWidget(window, TXT_NewButton2("Close Window", CloseWindow, NULL));
|
||||
|
||||
pwn = TXT_NewWindowAction(KEY_F1, "PWN!");
|
||||
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, pwn);
|
||||
|
|
|
|||
|
|
@ -122,3 +122,17 @@ txt_button_t *TXT_NewButton(char *label)
|
|||
return button;
|
||||
}
|
||||
|
||||
// Button with a callback set automatically
|
||||
|
||||
txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
|
||||
void *user_data)
|
||||
{
|
||||
txt_button_t *button;
|
||||
|
||||
button = TXT_NewButton(label);
|
||||
|
||||
TXT_SignalConnect(button, "pressed", func, user_data);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ struct txt_button_s
|
|||
};
|
||||
|
||||
txt_button_t *TXT_NewButton(char *label);
|
||||
txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
|
||||
void *user_data);
|
||||
void TXT_SetButtonLabel(txt_button_t *button, char *label);
|
||||
|
||||
#endif /* #ifndef TXT_BUTTON_H */
|
||||
|
|
|
|||
Loading…
Reference in a new issue