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.0 through 1.0.
  • on_changed receives red, green, blue, and alpha values.
  • With require "uing/crimage" and an application dependency on CrImage, both color = and set_color accept CrImage::Color::Color. The color getter still returns a numeric RGBA tuple; color_crimage returns a CrImage::Color::NRGBA. Use NRGBA for translucent colors; Color.parse currently constructs translucent RGBA values without premultiplying their channels.
button.color = CrImage::Color::NRGBA.new(255, 0, 0, 128)
selected = button.color_crimage

API reference · Gallery source