Class: Fidgit::ColorPicker
Constant Summary
- CHANNELS =
[:red, :green, :blue]
- DEFAULT_CHANNEL_NAMES =
CHANNELS.map {|c| c.to_s.capitalize }
- INDICATOR_HEIGHT =
25
Constants inherited from Composite
Fidgit::Composite::DEBUG_BORDER_COLOR
Constants inherited from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary
Attributes inherited from Packer
Attributes inherited from Element
#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z
Instance Method Summary (collapse)
- - (Object) color
- - (Object) color=(value)
-
- (ColorPicker) initialize(options = {}, &block)
constructor
A new instance of ColorPicker.
Methods inherited from Container
#add, #button, #clear, #color_picker, #color_well, #combo_box, #file_browser, #grid, #group, #hit_element, #horizontal, #image_frame, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #to_s, #toggle_button, #update, #vertical, #write_tree, #x=, #y=
Methods inherited from Element
#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #to_s, #update, #width, #width=, #with, #x, #x=, #y, #y=
Methods included from Event
#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe
Constructor Details
- (ColorPicker) initialize(options = {}, &block)
A new instance of ColorPicker
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fidgit/elements/color_picker.rb', line 27 def initialize( = {}, &block) = { padding: 0, spacing: 0, channel_names: DEFAULT_CHANNEL_NAMES, color: default(:color), indicator_height: default(:indicator_height), }.merge! @color = [:color].dup @indicator_height = [:indicator_height] super() = width vertical do @sliders = {} CHANNELS.each_with_index do |channel, i| @sliders[channel] = (value: @color.send(channel), range: 0..255, width: , tip: [: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: , height: @indicator_height end end |
Instance Method Details
- (Object) color
12 |
# File 'lib/fidgit/elements/color_picker.rb', line 12 def color; @color.dup; end |
- (Object) color=(value)
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fidgit/elements/color_picker.rb', line 14 def color=(value) @color = value.dup CHANNELS.each do |channel| @sliders[channel].value = @color.send channel end publish :changed, @color.dup value end |