Class Widget

(back to index)

The base class for all Fltk widgets.

Subclasses: Box  Browser_  Button  Group  Input_  Menu_  

Property index

activechangedlabelfontselection_colorwhen
aligncolorlabelsizetakeseventswindow
argumenthlabeltypetypex
boxlabeloutputvisibley
callbacklabelcolorparentw

Function index

activateclear_outputinsideresizesize
active_rcontainspositionset_changedtake_focus
clear_changeddeactivateredrawset_outputvisible_r

Key properties

typenamesummary
string labelWidget label
integer labelsizeLabel font size
Font labelfontLabel font
Color labelcolorLabel color
Color colorColor of widget
Boxtype boxBorder and style of widget
Align alignPosition of label
function callbackFunction called when triggered

Key functions

typenamesummary
void redraw()Redraw the widget
void resize(integer x, integer y, integer w, integer h)Change this widget's position and size
boolean take_focus()Give this widget the focus

Description

Widget is the base class for all widgets in FLTK. You can't create one of these directly, but all other widgets inherit from it.

When you create any widget, it's added to the current Group (which may be a Window. See the Group documentation for more information on groups.

When you change properties that affect the widget's appearance (like color or label), it's up to you to call redraw() to update the display.

Detailed reference

parent: Widget

Returns a the parent widget. Usually this is a Group or Window. Returns nil if none. parent is not readonly, but you should not set it unless you really know what you're doing.

type: integer

The type property provides C++ code with rough runtime information about what kind of Fl_Widget this is. Lua doesn't need this, but some subclasses of Widget change their behavior by setting this to particular values.

x: readonly integer

Except for window widgets, x is the horizontal position of this widget relative to its parent window. Use resize() or position() to change.

y: readonly integer

Except for window widgets, y is the vertical position of this widget relative to its parent window. Use resize() or position() to change.

w: readonly integer

The width of this widget. Use resize() or size() to change.

h: readonly integer

The height of this widget. Use resize() or size() to change.

resize(integer x, integer y, integer w, integer h): void

Resize and reposition this widget. Except for windows, these coordinates are relative to the widget's parent window.

position(integer x, integer y): void

Reposition this widget. Except for windows, these coordinates are relative to the widget's parent window.

size(integer w, integer h): void

Resize this widget.

align: Align

How the label is printed next to or inside the widget. The default value is Align.center, which centers the label. See Align for further details.

box: Boxtype

The box property identifies a routine that draws the border and background of the widget. For instance, a Button with a raised border has Boxtype.up; a Button with lowered border has Boxtype.down.

See Boxtype for the available types. The default depends on the widget, but is usually Boxtype.none or Boxtype.up.

color: Color

This color is passed to the box routine; it's usually the overall color of the widget

color is an index into an internal table of rgb colors. For most widgets this defaults to Color.gray. See the documentation of Color for named colors and operations that affect Fltk's color handling.

selection_color: Color

Widgets have a secondary color. This is usually used to color the widget when it is selected, although some widgets use this color for other purposes.

label: string

The label is printed somewhere on the widget or next to it. Its position depends on the align property; how it's drawn depends on the labeltype property..

labeltype: Labeltype

A labeltype identifies a routine that draws the label of the widget. This can be used for special effects such as emboss (Labeltype.embossed). In future versions of Lua Fltk, it will be used to treat the label() pointer as another form of data such as a bitmap.

The value Labeltype.normal prints the label as text. See Labeltype for further documentation.

labelcolor: Color

The color used to draw the widget's label.

labelcolor is an index into an internal table of rgb colors. For most widgets this defaults to Color.black. See the documentation of Color for named colors and operations that affect Fltk's color handling.

labelfont: Font

The font used to draw the widget's label. Font is an index into an internal table of fonts. The default font is Font.helvetica; add Font.bold or Font.italic to add those styles: Font.helvetica+Font.bold. See Font for further documentation.

labelsize: integer

The point size of the font used to draw the widget's label. The Fltk default is 14.

callback: function

Most widgets are designed to respond to user interaction. Depending on the type of widget and the value of the when property, the function in the callback property will be called when the user takes action that directly affects this widget. For example, the callback runs when a Button is pushed, or when the user changes the value of an Input field.

argument: integer

Don't set this property; it's reserved for the use of the Lua-Fltk runtime system.

when: When

The when property is a set of flags used by subclasses of Widget to decide when to deliver a callback. If the value is When.never then the callback is never done. Other values are described in the individual widgets and in the When documentation.

visible: readonly boolean

An invisible widget never gets redrawn and does not get events. The visible property is true if the widget is set to be visible. A widget is only visible if visible is true on it and all of its parents.

Changing it will send Event.show or Event.hide events to the widget. Do not change visible if the parent is not visible, as this will send false Event.show or Event.hide events to the widget. redraw() is called automatically, if necessary, on this widget or its parent.

visible_r(): boolean

visible_r() returns true if the widget and all of its parents are visible. A widget is only visible if visible is true on it and all of its parents.

active: readonly boolean

active returns whether the widget is active. An inactive widget does not get any events, but it does get redrawn. A widget is only active if active is true on it and all of its parents.

Changing this value will send Event.activate or Event.deactivate to the widget if active_r() is true.

Currently you cannot deactivate Window widgets.

active_r(): boolean

active_r() returns whether the widget and all of its parents are active. An inactive widget does not get any events, but it does get redrawn. A widget is only active if active is true on it and all of its parents.

activate(): void

Activates the widget. See the active property for more documentation.

deactivate(): void

Deactivates the widget. See the active property for more documentation.

output: readonly boolean

Widgets that the output property is true of are "output only"; they don't receive any events. This is similar to not active widgets, except output does not affect how the widget is drawn.

set_output(): void

Makes this widget output-only. See the output property for more documentation.

clear_output(): void

Resets this widget's output-only status. See the output property for more documentation.

takesevents: readonly boolean

This property is true if the widget is visible, active, and not output-only.

changed: readonly boolean

changed is a flag that is turned on when the user changes the value stored in the widget. This is only used by subclasses of Widget that store values, but is in the base class so it is easier to scan all the widgets in a panel and run the callback on the changed ones in response to an "OK" button.

Most widgets turn this flag off when they perform a callback, and when the program sets the stored value.

set_changed(): void

Sets the changed flag on this widget. See the changed property for more documentation.

clear_changed(): void

Clears the changed flag on this widget. See the output property for more documentation.

take_focus(): boolean

Tries to make this widget be the Fl.focus widget, by first sending it an Event.focus event, and if it returns non-zero, setting Fl.focus to this widget. You should use this method to assign the focus to an widget. Returns true if the widget accepted the focus.

contains(Widget b): boolean

Returns true if b is a child of this widget, or is equal to this widget. Returns false if b is nil.

inside(Widget a): boolean

Returns true if this is a child of a, or is equal to a . Returns false if a is nil.

redraw(): void

Redraw this widget. Call this after changing appearance-related properties like labelsize.

Actually, this only flags the widget as needing a redisplay; it will be redrawn the next time events are processed.

window: readonly Window

The Window this widget lives in. For window widgets, gives the window's parent window, if any; otherwise it's nil.


doctool generated at Sun Aug 5 20:52:29 2001