Main»Config Files

Config Files

General structure

The config files in Hybrid use a custom format inspired by CSS, D and Deadlock's .cfg files. At the top level, they can define layout, custom widgets, and may import other configs. Whitespace and comments are treated like in D.

Imports

The syntax for an import clause is simple: import "fileName", where fileName is a path to another .cfg file, relative to the application's working directory

Layout definition

Configs may create concrete widgets as well as abstract named widget slots that the D code may reference. For all of these entities, property, style and custom layout attributes may be set. The most basic element of a layout definition is a...

Widget declaration
There are two forms of these:
  • new type [name] [children]
  • name [children]
The first one creates a concrete widget, which will be instantiated and retained by the GUI system. The second is merely a point in which the D code may insert its concrete widget.
type is an identifier specifying which widget should be created.
name can be a single identifier or a list of identifiers starting from and separated by dots. In the former case, it's a name relative to the parent widget; in the latter, it's a global one.
children can be composed of the following:
  • A single semicolon - no children
  • { Layout definition } - children in the default slot
  • @identifier { Layout definition } - children in a slot named identifier ; may appear several times if the widget supports multiple child slots
Each widget declaration may be preceded by Layout attribs - an arbitrary string delimited by square braces. It is associated with the widget and passed verbatim to a layout handler in the widget's parent.
Examples:
tlist;
[hexpand] new Button { ... }
[hexpand hfill] new Progressbar prog1;

new TabView tabView
{ ... }
@tab0 { ... }
@tab1 { ... }

Property assignment
Syntax
name = non-block-value ;
name = { block-value }
name is a string composed of identifiers separated by dots
value may be one of the following:
  • Simple value
    • string
    • identifier
    • int
    • float
    • bool (true | false)
  • A list of simple values
  • A 'function' call - identifier (comma-separated list of values)
  • A block containing value assignments
Examples:
text = "cfg extra";
fontSize = 8;
size = 50 0;
style.normal = {
    color = rgba(.7, 1, .7, .8);
}


Special properties
Some property names have special meanings:
  • layout
    • The value can be a block or an identifier.
    • An identifier value sets the layout type for a widget
    • A block value sets parameters for the layout
  • style.identifier
    • The value is always a block
    • identifier specifies which widget style the value defines
  • shape
    • The value is an identifier
    • It specifies the shape for the current widget. A widget without a shape may not be rendered properly.
Examples:
layout = HBox;
layout = {
    spacing = 5;
}
shape = Rectangle;
style.normal = {
    border = 2 rgb(.8, .8, .8);
}


Custom widget definition


The syntax is: widget identifier { Custom body }
Custom body may contain everything a Layout definition can, plus two more elements:
Property binding
TODO
Sub-widget binding
TODO
Examples:
widget WindowFrameButton {
    layout = Layered;

    new Icon icon {
    }

    [hfill vfill] new Graphic hlight {
        ...
    }

    addIcon = prop(icon.addIcon);
    icon = sub(icon);
    hlight = sub(hlight);
}