|
YCP UI Widget Reference
Back to the widget index
|
PushButton
|
Perform action on click
|
|
Description
A PushButton is a simple button with a text label the user can
press in order to activate some action. If you call UserInput() and
the user presses the button, UserInput() returns with the id of the
pressed button.
You can (and should) provide keybord shortcuts along with the button
label. For example "&Apply" as a button label will allow the user to
activate the button with Alt-A, even if it currently doesn't have keyboard
focus. This is important for UIs that don't support using a mouse.
Arguments
Special Properties
|
string
|
Label
|
the text on the PushButton
|
Options
|
`opt(`default)
|
makes this button the dialogs default button
|
|
`opt(`key_F1)
|
(NCurses only) activate this button with the F1 key
|
|
`opt(`key_F2)
|
(NCurses only) activate this button with the F2 key
|
|
`opt(`key_F3)
|
(NCurses only) activate this button with the F3 key
|
|
`opt(`key_F4)
|
(NCurses only) activate this button with the F4 key
|
|
`opt(`key_F5)
|
(NCurses only) activate this button with the F5 key
|
|
`opt(`key_F6)
|
(NCurses only) activate this button with the F6 key
|
|
`opt(`key_F7)
|
(NCurses only) activate this button with the F7 key
|
|
`opt(`key_F8)
|
(NCurses only) activate this button with the F8 key
|
|
`opt(`key_F9)
|
(NCurses only) activate this button with the F9 key
|
|
`opt(`key_F10)
|
(NCurses only) activate this button with the F10 key
|
|
`opt(`key_F11)
|
(NCurses only) activate this button with the F11 key
|
|
`opt(`key_F11)
|
(NCurses only) activate this button with the F12 key
|
|
`opt(`key_Return)
|
(NCurses only) activate this button with the Return key
|
Sample Usage
`PushButton(`id(`click), `opt(`default, `hstretch), "Click me")
Examples
UI::{
// Build a dialog with one button.
// Wait until that button is clicked,
// then close the dialog and terminate.
OpenDialog(
`PushButton( "&OK" )
);
UserInput();
CloseDialog();
}
|
UI(``{
// Build dialog with three buttons.
// "Cancel" is the default button, i.e. pressing "Return" will
// activate it.
OpenDialog(
`HBox(
`PushButton( `id(`ok), "&OK" ),
`PushButton( `id(`cancel), `opt(`default), "&Cancel" ),
`PushButton( `id(`help), "&Help" )
)
);
// Wait for user input. The value returned is the ID of the widget
// that makes UserInput() terminate, i.e. the respective button ID.
any button_id = UserInput();
// Close the dialog.
CloseDialog();
// Process the input.
string button_name = "";
if ( button_id == `ok ) button_name = "OK";
else if ( button_id == `cancel ) button_name = "Cancel";
else if ( button_id == `help ) button_name = "Help";
// Pop up a new dialog to display what button was clicked.
OpenDialog(
`VBox(
`Label( "You clicked button \"" + button_name + "\"."),
`PushButton( `opt(`default), "&OK" )
)
);
UserInput();
CloseDialog();
})
|
Back to the widget index
|