lib/rubygoo/check_box.rb in rubygoo-0.0.6 vs lib/rubygoo/check_box.rb in rubygoo-0.0.7

- old
+ new

@@ -1,22 +1,47 @@ +require 'label' module Rubygoo class CheckBox < Widget attr_accessor :checked can_fire :checked + DEFAULT_PARAMS = {:align=>:right} def initialize(opts={}) + opts = DEFAULT_PARAMS.merge opts super opts + @checked = opts[:checked] + + # only supports label on the right + # TODO maybe I should do this in added + @label_text = opts[:label] + @label_alignment = opts[:align] end def added() - @checked = false @color = theme_property :color @bg_color = theme_property :bg_color @border_color = theme_property :border_color @focus_color = theme_property :focus_color @checked_color = theme_property :checked_color + @hover_color = theme_property :hover_color @rect = Rect.new [@x-@x_pad,@y-@y_pad,@w+2*@x_pad,@h+2*@y_pad] + unless @label_text.nil? or @label_text.empty? + @label = Label.new @label_text, :x=>0,:y=>0, :relative=>@relative, :visible=>false + @parent.add @label + + case @label_alignment + when :right + lx = @x+2*@x_pad+@w + ly = @y + when :left + ly = @y + lx = @x-2*@x_pad-@label.w + end + @label.x = lx + @label.y = ly + @label.show + end end def checked?() @checked end @@ -73,9 +98,13 @@ cx1 = rect[0] cy1 = rect[1] cx2 = rect[2] + x1 cy2 = rect[3] + y1 adapter.fill cx1, cy1, cx2, cy2, @checked_color + end + + if mouse_over? and @hover_color + adapter.fill x1, y1, x2, y2, @hover_color end if @border_color adapter.draw_box x1, y1, x2, y2, @border_color end