REBOL

How to create a RebGUI 0.4.x widget

Author: Anton Rolls
Date: 12-Jul-2006

Contents:

1. Install rebgui
2. Load rebgui
3. Create a widget
4. Add the widget to RebGUI's total list of widgets
5. Display the widget

1. Install rebgui

You will need to create a directory and unzip the contents of the rebgui distribution into it.

2. Load rebgui

A line like this should be sufficient:

do %rebgui/rebgui.r

The above assumes that rebgui is installed relative to the current script's current directory. If several scripts in different directories were to use the above line, you would need several installations of rebgui. So, you may prefer to use a more specific location:

do view-root/rebgui/rebgui.r

The above line looks for the rebgui installation relative to your Rebol/View directory.

3. Create a widget

The simplest example:

ctx-rebgui/widgets: make ctx-rebgui/widgets [

    my-rebgui-widget: make ctx-rebgui/rebface [

    ]
]

(The above example creates a face, but you can't see it because the default color is none which allows the background through.)

Adding size, color and an edge:

ctx-rebgui/widgets: make ctx-rebgui/widgets [

    my-rebgui-widget: make ctx-rebgui/rebface [
        size: 20x20
        color: snow
        edge: make default-edge [size: 1x1 color: navy]
    ]
]

Adding text:

ctx-rebgui/widgets: make ctx-rebgui/widgets [

    my-rebgui-widget: make ctx-rebgui/rebface [
        size: 20x20
        color: snow
        font: make default-font [color: black align: 'center valign: 'middle]
        text: "Hello"
    ]
]

Adding resizing:

ctx-rebgui/widgets: make ctx-rebgui/widgets [

    my-rebgui-widget: make ctx-rebgui/rebface [
        size: 20x20
        color: snow
        edge: make default-edge [size: 1x1 color: navy]
        font: make default-font [color: black align: 'center valign: 'middle]
        text: "Hello"
        span: #WH ; resize in width and height (when window is resized)
    ]
]

4. Add the widget to RebGUI's total list of widgets

append ctx-rebgui/words 'my-rebgui-widget

(you only need to do this once)

5. Display the widget

display "" [my-rebgui-widget]
do-events

That's it. You should now be able to see the widget in the window.

MakeDoc2 by REBOL - 12-Jul-2006