Back

ColorPickerDialog

Create ColorPickerDialog objects using the CreateColorPickerDialog method of the UIExtras object:

 picker = uix.CreateColorPickerDialog( title, red, green, blue, alpha, options );

By default the ColorPickerDialog will have a title bar, use the NoTitle option to remove the title bar.

Use the NoAlpha option to remove the transparency slider from the dialog. When using the NoAlpha option, the alpha parameter of the CreateColorPickerDialog method will be ignored.

Example - With Transparency Slider

app.LoadPlugin( "UIExtras" );

var red = 255;
var green = 0;
var blue = 0;
var alpha = 255;

function OnStart()
{
 lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

 btn = app.CreateButton( "Pick Color", 0.3, 0.1 );
 btn.SetOnTouch( btn_OnTouch );
 btn.SetBackColor( "#FF0000" );
 lay.AddChild( btn );

 app.AddLayout( lay );
 
 uix = app.CreateUIExtras();
}

function btn_OnTouch()
{
 picker = uix.CreateColorPickerDialog( "Pick a Color", red, green, blue, alpha );
 picker.SetOnOk( picker_OnOk );
 picker.Show();
}

function picker_OnOk( r, g, b, a )
{
 red = r;
 green = g;
 blue = b;
 alpha = a;
 
 var hex = picker.RGBAtoHex( r, g, b, a );
 btn.SetBackColor( hex );
 
 app.ShowPopup( "RGBA(" + r + ", " + g + ", " + b + ", " + a + ")" );
}
  Copy   Copy All    Run   

Example - Without Transparency Slider

app.LoadPlugin( "UIExtras" );

var red = 255;
var green = 0;
var blue = 0;

function OnStart()
{
 lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

 btn = app.CreateButton( "Pick Color", 0.3, 0.1 );
 btn.SetOnTouch( btn_OnTouch );
 btn.SetBackColor( "#FF0000" );
 lay.AddChild( btn );

 app.AddLayout( lay );
 
 uix = app.CreateUIExtras();
}

function btn_OnTouch()
{
 picker = uix.CreateColorPickerDialog( "Pick a Color", red, green, blue, -1, "NoAlpha" );
 picker.SetOnOk( picker_OnOk );
 picker.Show();
}

function picker_OnOk( r, g, b )
{
 red = r;
 green = g;
 blue = b;
 
 var hex = picker.RGBtoHex( r, g, b );
 btn.SetBackColor( hex );
 
 app.ShowPopup( "RGB(" + r + ", " + g + ", " + b + ")" );
}
  Copy   Copy All    Run   

The following methods are available on the ColorPickerDialog object:

 GetType()
 SetTitle( title )
 Show()
 Hide()
 Dismiss()
 SetOnOk( callback )
 RGBAtoHex( r, g, b, a )
 RGBtoHex( r, g, b )

The ColorPickerDialog uses the ColorPickerView library by danielnilsson9, licensed under the Apache 2.0 License.