Class GGLib::Widget
In: widget.rb
Parent: Containable

The Widget class is an interface between the button class and the window class which allows for user interaction with an area of the screen. This area is referred to as the widget. To make a Widget, simply create a class derived from Widget and override methods as needed:

 class MyWidget < Widget      #all widgets are subclasses of Widget
   attr_reader :text,:font    #most widgets will have text and font attributes
   def initialize(window,text)
     super(window,Button::Image,0,400,640,480,"img/gui/mywidget image.png",name="My Widget")       #use super to initialize the button
     @text=text; @font=Gosu::Font.new(window, "arial", 50)          #initialize widget specific variables
   end
   def draw                        #the window will call draw every time it executes GameWindow::draw
     font.draw(text,0,0)           #you do not have to draw the image here, Button class does that for you
     if clicked?                   #here you do widget specific things like drawing text,
       setImage(Gosu::Image.new)   #changing the picture on mouse over or click, etc
     end
   end
   def onDelete        #onDelete is called when the window wants to delete the widget
     puts "deleted"    #execute widget specific code here
   end                 #or leave the function alone if there is no widget specific code
 end

See the `Widget Programmer‘s Handbook` for more info.

Methods

Classes and Modules

Module GGLib::Widget::Event

Attributes

buttonId  [R] 
defimage  [R] 
id  [R] 
name  [R] 
sleeping  [R] 
theme  [RW] 
window  [R] 
zfocus  [R] 

Public Class methods

Public Instance methods

[Validate]