functionality common to all widgets
getBorderSize
size_in_pixel = a_widget:getBorderSize()
getEventId
event_name = a_widget:getEventId()
getHeight
h = w_widget:getHeight()
getPosition
x, y = a_widget:getPosition()
getSize
w, h = a_widget:getSize()
getWidth
w = a_widget:getWidth()
getX
x_pos = a_widget:getX()
Note: the position is in pixel; relative to the parent of the respective widget.
getY
y_pos = a_widget:getY()
isEnabled
isFocusable
isFocused
isVisible
is_widget_visible = a_widget:isVisible()
setBackgroundColor
a_widget:setBackgroundColor(color_helper_object)
See: Color
setBaseColor
a_widget:setBaseColor(color_helper_object)
See: Color
setBorderSize
a_widget:setBorderSize(0)
setEnabled
setEventId
a_widget:setEventId("my_callback_function_name")
setFocusable
setForegroundColor
a_widget:setForegroundColor(color_helper_object)
See: Color
setPosition
a_widget:setPosition(30, 60) -- x, y
setSize
a_widget:setSize(200, 150) -- width, height
setVisible
a_widget:setVisible(false)
GUI objects
Underlined headings mark widgets, the rest
are helper objects.
I am trying to show all possible constructors, but I will not
repeat the description of every function for every object.
To see all functions for each object refer to
this list.
some_button = Button("Click me")
some_button:setEventId("button_clicked")
-- you have to define the corresponding function.
-- gui.actions = {} will already exist
gui.actions.button_clicked = function()
-- note the name ^
print("hello world")
end
If you want a button with a texture, look at TwoButton; also
see ClickLabel.
isPressed
is_button_pressed = a_button:isPressed()
adjustSize
Don't call; really! Maybe later. Proceed if you want, but you have
been warned.
getAlignment
horizontal_text_align = a_button:getAlignment()
Possible values: 0 left, 1 center, 2 right
setAlignment
a_button:setAlignment(0)
getCaption
print(a_button:getCaption())
setCaption
existing_button:setCaption("new caption")
setFont
a_button:setFont(font_helper_object)
See TTFont
m_checkbox = CheckBox()
isMarked
m_checkbox:isMarked()
setMarked
m_checkbox:setMarked(false)
m_clabel = ClickLabel("hello world")'
This object behaves like a Button (it sends event
on being clicked) but displays only a Label.
Color
color1 = Color()
color2 = Color(10, 20, 255) -- r, g, b (0 - 255)
color3 = Color(50, 95, 120, 128) -- r, g, b, a
There are also accessor/mutator functions; but really rather boring.
my_container = Container()
A container of widgets; similiar to the guimanager widgets can
be added and removed. The positions of the sub-widgets are relative
to their parent container.
add
a_container:add(another_widget)
clear
a_container:clear()
Removes all sub-widgets of this container.
Note: poorly researched; bad things may happen if you keep references
to the contained sub-widgets (in Lua) when you call this.
isOpaque
a_container:isOpaque()
moveToBottom
a_container:moveToBottom(a_contained_widget)
moveToTop
a_container:moveToTop(a_contained_widget)
remove
a_container:remove(a_contained_widget)
setOpaque
a_container:setOpaque(true)
dropdown = DropDown(list_model_object)
See ListModel
getSelected
selected_item_index = dropdown:getSelected()
setListModel
dropdown:setListModel(another_list_model_object)
setSelected
dropdown:setSelected(0) -- index into the listmodel
my_icon = Icon(image_object)
See Image
setImage
my_icon:setImage(another_image_object)
Image
an_image = Image("filename")
getHeight
an_image:getHeight()
getWidth
an_image:setWidth()
setAnimActive
an_image:setAnimActive(true)
setAnimDirection
an_image:setAnimDirection(true)
setAnimEndCallback
an_image:setAnimEndCallback("func_name")
m_label = Label("some caption")
m_listbox = ListBox(listmodel_object)
See ListModel &
DropDown.
ListModel
m_listmodel = ListModel("a", "b", "c") -- any number of elements
addElement
m_listmodel:addElement("d")
getElementAt
element_5 = m_listmodel:getElementAt(5)
getNumberOfElements
m_listmodel:getNumberOfElements()
radio1 = RadioButton()
radio2 = RadioButton("my caption", "groupname")
radio3 = RadioButton("my caption", "groupname", true) -- set marked
isMarked
radio1:isMarked()
setMarked
radio1:setMarked(true)
m_area = ScrollArea()
setContent
m_area:setContent(another_widget)
setScrollPolicy
m_area:setScrollPolicy(0, 0) -- horizontal, vertical
This controls the visibility of scrollbars;
Possible values: 0 always, 1 never, 2 auto
getScrollPolicy
h, v = m_area:getScrollPolicy()
setScrollbarWidth
m_area:setScrollBarWidth(5) -- in pixel
setScrollAmount
m_area:setScrollAmount(10, 50) -- horiz, vert
getMaxScroll
h, v = m_area:getMaxScroll()
m_slider1 = Slider()
m_slider2 = Slider(100.8) -- end of scale; floating point
m_slider3 = Slider(20.5, 45.6) -- start of scale, end of scale
getOrientation
m_orientation = m_slider1:getOrientation()
getScale
scale_start, scale_end = m_slider1:getScale()
getValue
set_value = m_slider1:getValue()
setOrientation
m_slider1:setOrientation(0)
Possible values: 0 horizontal, 1 vertical
setScale
m_slider1:setScale(10.2, 20.4) -- start, end
setValue
m_slider1:setValue(15.5)
m_textbox = TextBox("default content")
addRow
m_textbox:addRow("next line of content")
isEditable
m_textbox:isEditable() -- can the user edit it
setEditable
m_textbox:setEditable(false)
getNumberOfRows
m_textbox:getNumberOfRows()
getTextRow
a_line_of_text = m_textbox:getTextRow(4)
setTextRow
m_textbox:setTextRow(5, "bla bla")
m_tfield = TextField("default value")
getCaretPosition
m_tfield:getCaretPosition()
getText
print(m_tfield:getText())
setCaretPosition
m_tfield:setCaretPosition(5)
Note: dunno what happens when you set a position larger than the current text; exception being thrown around most probably.
setText
m_tfield:setText("other text")
TTFont
m_font = TTFont("font_filename", 18) -- font size
setColor
m_font:setColor(10, 50, 200) -- r, g, b
m_tbutton1 = TwoButton(up_image_object, down_image_object)
m_tbutton2 = TwoButton(up_image, down_image, "caption above")
This acts like a Button but displays
Image objects and optionally a caption above the active image.
m_window1 = Window()
m_window2 = Window(any_widget)
Similiar to a Container but this can be moved around with
the mouse.
isMovable
m_window1:isMovable()
setMovable
m_window1:setMovable(true)
getPadding
padding_in_pixel = m_window1:getPadding()
setPadding
m_window1:setPadding(0)
getTitleBarHeight
height_in_pixel = m_window1:getTitleBarHeight()
setTitleBarHeight
m_window1:setTitleBarHeight(4)
setContent
m_window1:setContent(a_widget)
In guichan 0.5 you should use :add/:remove on Windows.