class RIButton
Attributes
color[RW]
font[RW]
font_color[RW]
height[RW]
hover_color[RW]
onclick[RW]
size[RW]
text[RW]
width[RW]
x[RW]
y[RW]
Public Class Methods
new(opts = [:x, :y, :width, :height, :color, :hover_color, :onclick])
click to toggle source
- x
-
X position of the button
- y
-
Y position of the button
- width
-
Width of the button
- height
-
Height of the button
- color
-
Base color of the button
hover_color
-
Color the button will change to when the mouse is hovered over it. Exclude this to have no hover color
- text
-
Text to show on the button's label
- font
-
Font of the button's label (note: as of now, you must include the font file within your project for this to work)
- size
-
Size of the button's label's text
font_color
-
Color of the button's label's text
# File lib/RIUI/RIButton.rb, line 17 def initialize(opts = [:x, :y, :width, :height, :color, :hover_color, :onclick]) ### Initialize variables and start actions @x = opts[:x] || 0 @y = opts[:y] || 0 @width = opts[:width] || 100 @height = opts[:height] || 50 @color = opts[:color] || 'blue' @hover_color = opts[:hover_color] || @color @onclick = opts[:onclick] @rect = Rectangle.new(x: @x, y: @y, z: 0, width: @width, height: @height, color: @color) #actions end
Public Instance Methods
contains(x, y)
click to toggle source
# File lib/RIUI/RIButton.rb, line 29 def contains(x, y) ### Check if the button contains a certain point if @rect.contains?(x, y) true else false end end
mouse_down_actions(x, y)
click to toggle source
# File lib/RIUI/RIButton.rb, line 55 def mouse_down_actions(x, y) if @rect.contains?(x, y) @onclick.call end end
mouse_move_actions(x, y)
click to toggle source
# File lib/RIUI/RIButton.rb, line 48 def mouse_move_actions(x, y) if @rect.contains?(x, y) @rect.color = @hover_color else @rect.color = @color end end
mouse_up_actions()
click to toggle source
# File lib/RIUI/RIButton.rb, line 60 def mouse_up_actions; end
onClick(opts = [:onclick])
click to toggle source
# File lib/RIUI/RIButton.rb, line 36 def onClick(opts = [:onclick]) @onclick = opts[:onclick] end
setLabel(opts = [:text, :font, :size, :color])
click to toggle source
# File lib/RIUI/RIButton.rb, line 39 def setLabel(opts = [:text, :font, :size, :color]) ### Sets the label of the button @text = opts[:text] @font = opts[:font] @size = opts[:size] @font_color = opts[:font_color] @temp_label = Text.new(x: 0, y: 0, text: @text, font: @font, color: @font_color, size: @size) @label = Text.new(x: @rect.x + (@rect.width / 2) - (@temp_label.width/2), y: @rect.y + (@rect.height / 2) - (@temp_label.height/2), text: @text, font: @font, color: @font_color, size: @size) @temp_label.remove end
update_actions()
click to toggle source
# File lib/RIUI/RIButton.rb, line 61 def update_actions; end