ColorButton
ColorButton opens the platform color chooser and stores an RGBA color.
Runnable example
require "uing/crimage"
UIng.init
window = UIng::Window.new("ColorButton Example", 300, 100, margined: true)
window.on_closing do
UIng.quit
true
end
color_button = UIng::ColorButton.new do |button|
button.color = CrImage::Color::NRGBA.new(255, 0, 0, 255)
on_changed do |red, green, blue, alpha|
window.msg_box("Color Changed", "R=#{red}, G=#{green}, B=#{blue}, A=#{alpha}")
end
end
window.child = color_button
window.show
UIng.main
UIng.uninit
Usage notes
- RGBA components are floating-point values from
0.0through1.0. on_changedreceives red, green, blue, and alpha values.- With
require "uing/crimage"and an application dependency on CrImage, bothcolor =andset_coloracceptCrImage::Color::Color. Thecolorgetter still returns a numeric RGBA tuple;color_crimagereturns aCrImage::Color::NRGBA. UseNRGBAfor translucent colors;Color.parsecurrently constructs translucentRGBAvalues without premultiplying their channels.
button.color = CrImage::Color::NRGBA.new(255, 0, 0, 128)
selected = button.color_crimage