Class: Clogs::Radio

Inherits:
Control show all
Defined in:
lib/clogs/drawables/controls.rb

Constant Summary collapse

BOX =
16

Constants inherited from Control

Control::PADDING_X, Control::PADDING_Y

Instance Attribute Summary

Attributes inherited from Control

#focused, #hovered, #pressed

Attributes inherited from Drawable

#abs_x, #abs_y, #children, #height, #parent, #shoes_linkable_id, #styles, #width, #x, #y

Instance Method Summary collapse

Methods inherited from Control

#clickable?, #label, #on_mouse_enter, #on_mouse_leave, #text_style

Methods inherited from Drawable

#add_child, #app, #clickable?, #contains?, #destroy_self, #each_peer, #focus_gained, #focus_lost, #focusable?, for_shoes_class, #hidden?, #initialize, #margin, #needs_layout!, #notify, #on_click, #on_key, #on_mouse_move, #paint, #positioned?, #properties_changed, #redraw!, #remove_child, #requested_height, #requested_width, #set_parent, #style

Constructor Details

This class inherits a constructor from Clogs::Drawable

Instance Method Details

#draw(painter, x, y) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/clogs/drawables/controls.rb', line 130

def draw(painter, x, y)
  painter.fill_oval(x, y, BOX, BOX, [255, 255, 255, 255])
  painter.stroke_oval(x + 0.5, y + 0.5, BOX - 1, BOX - 1, [120, 120, 120, 255], thickness: 1)
  return unless style(:checked)

  painter.fill_oval(x + 4, y + 4, BOX - 8, BOX - 8, [30, 30, 30, 255])
end

#measure(_available_width) ⇒ Object



125
126
127
128
# File 'lib/clogs/drawables/controls.rb', line 125

def measure(_available_width)
  @width = BOX
  @height = BOX
end

#on_release(x, y, _button) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/clogs/drawables/controls.rb', line 138

def on_release(x, y, _button)
  return unless contains?(x, y)

  # Selecting one radio in a group clears the others, as Shoes does.
  group = style(:group)
  if group && @parent
    @parent.children.each do |sib|
      sib.styles["checked"] = false if sib.is_a?(Radio) && sib.style(:group) == group
    end
  end
  @styles["checked"] = true
  notify("click")
  redraw!
end