Sha256: 025a1b9a3bd484437b9f3a494a69796a8240adf448a0c277348aab6b3939f66e
Contents?: true
Size: 1.64 KB
Versions: 16
Compression:
Stored size: 1.64 KB
Contents
# encoding: utf-8 module Fidgit class ColorPicker < Composite CHANNELS = [:red, :green, :blue] DEFAULT_CHANNEL_NAMES = CHANNELS.map {|c| c.to_s.capitalize } INDICATOR_HEIGHT = 25 event :changed def color; @color.dup; end def color=(value) @color = value.dup CHANNELS.each do |channel| @sliders[channel].value = @color.send channel end publish :changed, @color.dup value end # @param (see Composite#initialize) # @option (see Composite#initialize) def initialize(options = {}, &block) options = { padding: 0, spacing: 0, channel_names: DEFAULT_CHANNEL_NAMES, color: default(:color), indicator_height: default(:indicator_height), }.merge! options @color = options[:color].dup @indicator_height = options[:indicator_height] super(options) slider_width = width vertical do @sliders = {} CHANNELS.each_with_index do |channel, i| @sliders[channel] = slider(value: @color.send(channel), range: 0..255, width: slider_width, tip: options[:channel_names][i]) do |sender, value| @color.send "#{channel}=", value @indicator.background_color = @color publish :changed, @color.dup end end @indicator = label '', background_color: @color, width: slider_width, height: @indicator_height end end protected # Use block as an event handler. def post_init_block(&block) subscribe :changed, &block end end end
Version data entries
16 entries across 16 versions & 1 rubygems