|
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
{
if ( ! UI::HasSpecialWidget(`Slider) )
{
UI::OpenDialog(
`VBox(
`Label("Error: This UI doesn't support the Slider widget!"),
`PushButton(`opt(`default), "&OK")
)
);
UI::UserInput();
UI::CloseDialog();
return;
}
UI::OpenDialog(
`VBox(
`Slider( "Percentage", 0, 100, 50),
`PushButton(`opt(`default), "&OK")
)
);
UI::UserInput();
UI::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. ;-)
{
// Check for availability of required widgets
if ( ! UI::HasSpecialWidget(`Slider) ||
! UI::HasSpecialWidget(`BarGraph ) )
{
UI::OpenDialog(
`VBox(
`Label("Error: This UI doesn't support the required special widgets!"),
`PushButton(`opt(`default), "&OK")
)
);
UI::UserInput();
UI::CloseDialog();
return;
}
// Initialize RGB values
integer red = 128;
integer blue = 128;
integer green = 128;
// Create the dialog
UI::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.
any widget = nil;
do
{
widget = UI::UserInput();
if ( widget == `red || // any of the sliders?
widget == `blue ||
widget == `green )
{
// Get all slider values
red = (integer) UI::QueryWidget(`id(`red), `Value );
green = (integer) UI::QueryWidget(`id(`green), `Value );
blue = (integer) UI::QueryWidget(`id(`blue), `Value );
// Update bar graph
UI::ChangeWidget(`id(`graph), `Values, [ red, green, blue ] );
}
} while ( widget != `close && // the real "Close" button
widget != `cancel ); // the window manager close function/button
UI::CloseDialog();
}
|
|
/**
* Advanced ColoredLabel example: A sample ColoredLabel widget and sliders
* for both foreground and background colors.
**/
{
if ( ! UI::HasSpecialWidget(`ColoredLabel) || ! UI::HasSpecialWidget(`Slider) )
{
UI::OpenDialog(
`VBox(
`Label("Error: This UI doesn't support the required special widgets!"),
`PushButton(`opt(`default), "&OK")
)
);
UI::UserInput();
UI::CloseDialog();
return;
}
define term 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 );
};
UI::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")
)
);
any widget = nil;
do
{
widget = UI::UserInput();
if ( widget != `close )
{
UI::ReplaceWidget(`id(`sample),
sample( (integer) UI::QueryWidget(`id(`fg_red ), `Value ),
(integer) UI::QueryWidget(`id(`fg_green), `Value ),
(integer) UI::QueryWidget(`id(`fg_blue ), `Value ),
(integer) UI::QueryWidget(`id(`bg_red ), `Value ),
(integer) UI::QueryWidget(`id(`bg_green), `Value ),
(integer) UI::QueryWidget(`id(`bg_blue ), `Value )
)
);
}
} while ( widget != `close );
UI::CloseDialog();
}
|
Back to the widget index
|