|
YCP UI Widget Reference
Back to the widget index
|
Slider
|
Numeric limited range input (optional widget)
|
|
Description
A horizontal slider with (numeric) input field that allows input of an
integer value in a given range. The user can either drag the slider or
simply enter a value in the input field.
Remember you can use `opt(`notify) in order to get instant response
when the user changes the value - if this is desired.
Note:
This is a "special" widget, i.e. not all UIs necessarily support it. Check
for availability with HasSpecialWidget(`Slider) before using it.
Arguments
|
string
|
label
|
Explanatory label above the slider
|
|
integer
|
minValue
|
minimum value
|
|
integer
|
maxValue
|
maximum value
|
|
integer
|
initialValue
|
initial value
|
Special Properties
|
integer
|
Value
|
the numerical value
|
|
string
|
Label
|
the slider label
|
Sample Usage
if ( HasSpecialWidget(`Slider) {...
`Slider("Percentage", 1, 100, 50)
Examples
UI(``{
if ( ! HasSpecialWidget(`Slider) )
{
OpenDialog(
`VBox(
`Label("Error: This UI doesn't support the Slider widget!"),
`PushButton(`opt(`default), "&OK")
)
);
UserInput();
CloseDialog();
return;
}
OpenDialog(
`VBox(
`Slider( "Percentage", 0, 100, 50),
`PushButton(`opt(`default), "&OK")
)
);
UserInput();
CloseDialog();
})
|
|
// Advanced Slider + BarGraph example:
//
// Display a dialog with a bar graph for RGB color percentages
// and 3 sliders for the RGB percentage.
// Update the bar graph while the user adjusts the RGB values.
//
// Unfortunately the colors don't match any more in the BarGraph widget - they
// used to be red, blue and green. You need to use a bit of imagination
// here. ;-)
UI(``{
// Check for availability of required widgets
if ( ! HasSpecialWidget(`Slider) ||
! HasSpecialWidget(`BarGraph ) )
{
OpenDialog(
`VBox(
`Label("Error: This UI doesn't support the required special widgets!"),
`PushButton(`opt(`default), "&OK")
)
);
UserInput();
CloseDialog();
return;
}
// Initialize RGB values
integer red = 128;
integer blue = 128;
integer green = 128;
// Create the dialog
OpenDialog(
`VBox(
`HSpacing(50), // force width
`BarGraph( `id(`graph),
[ red, green, blue ],
[ "Red\n%1", "Green\n%1", "Blue\n%1" ] ),
`Slider( `id(`red), `opt(`notify), "Red", 0, 255, red ),
`Slider( `id(`green), `opt(`notify), "Green", 0, 255, green ),
`Slider( `id(`blue), `opt(`notify), "Blue", 0, 255, blue ),
`PushButton(`id(`close), `opt(`default), "&Close")
)
);
// Event processing loop - left only via the "close" button
// or the window manager close button / function.
do
{
any widget = UserInput();
if ( widget == `red || // any of the sliders?
widget == `blue ||
widget == `green )
{
// Get all slider values
red = QueryWidget(`id(`red), `Value );
green = QueryWidget(`id(`green), `Value );
blue = QueryWidget(`id(`blue), `Value );
// Update bar graph
ChangeWidget(`id(`graph), `Values, [ red, green, blue ] );
}
} while ( widget != `close && // the real "Close" button
widget != `cancel ); // the window manager close function/button
CloseDialog();
})
|
|
/**
* Advanced ColoredLabel example: A sample ColoredLabel widget and sliders
* for both foreground and background colors.
**/
UI(``{
if ( ! HasSpecialWidget(`ColoredLabel) || ! HasSpecialWidget(`Slider) )
{
OpenDialog(
`VBox(
`Label("Error: This UI doesn't support the required special widgets!"),
`PushButton(`opt(`default), "&OK")
)
);
UserInput();
CloseDialog();
return;
}
define void sample( integer fg_red, integer fg_green, integer fg_blue,
integer bg_red, integer bg_green, integer bg_blue ) ``{
return `ColoredLabel( `opt(`hstretch),
"Use the sliders\nto change color",
`rgb( fg_red, fg_green, fg_blue ),
`rgb( bg_red, bg_green, bg_blue ),
30 );
};
OpenDialog(
`VBox(
`ReplacePoint(`id(`sample), sample( 200, 0, 0,
0, 0, 200) ),
`VSpacing(),
`HBox(
`Frame( "Foreground",
`VBox(
`Slider(`id(`fg_red ),`opt(`notify), "&red", 0, 255, 200 ),
`Slider(`id(`fg_green),`opt(`notify), "&green", 0, 255, 0 ),
`Slider(`id(`fg_blue ),`opt(`notify), "&blue", 0, 255, 0 )
)
),
`Frame( "Backround",
`VBox(
`Slider(`id(`bg_red ), `opt(`notify), "r&ed", 0, 255, 0 ),
`Slider(`id(`bg_green), `opt(`notify), "gree&n", 0, 255, 0 ),
`Slider(`id(`bg_blue ), `opt(`notify), "b&lue", 0, 255, 200 )
)
)
),
`VSpacing(),
`PushButton(`id(`close), "&Close")
)
);
symbol widget = nil;
do
{
widget = UserInput();
if ( widget != `close )
{
ReplaceWidget(`id(`sample),
sample( QueryWidget(`id(`fg_red ), `Value ),
QueryWidget(`id(`fg_green), `Value ),
QueryWidget(`id(`fg_blue ), `Value ),
QueryWidget(`id(`bg_red ), `Value ),
QueryWidget(`id(`bg_green), `Value ),
QueryWidget(`id(`bg_blue ), `Value )
)
);
}
} while ( widget != `close );
CloseDialog();
})
|
Back to the widget index
|