Skip to content

1.04 Fonts and colors

Lokasenna edited this page Aug 3, 2018 · 6 revisions

Fonts

In the interest of making Lokasenna_GUI as straightforward as possible, and since Reaper's API does the opposite, fonts are handled by way of presets.

1   -- Title
2   -- Header
3   -- Label
4   -- Value
GUI.font(2)

Most classes will have one or two font parameters:

GUI.elms.my_label.font = 3

Presets can be overridden or added to at any point:

                font     size  flags
GUI.fonts[4] = {"Calibri", 12, "bi"}
GUI.fonts[5] = {"Arial",   10}
GUI.fonts["meme"] = {"Impact", 20, "b"}

GUI.font will also directly accept a table in the same format.

The default presets all use the same font, and are OS-dependent. As of this writing they are:

  • Windows: Calibri
  • OSX: Helvetica Neue
  • Linux: Arial

Textbox and TextEditor elements need a monospace font for their content. By default:

  • Windows: Lucida Console
  • OSX: Andale Mono
  • Linux: DejaVu Sans Mono

Note: On OSX, font sizes are multiplied by 0.7 at runtime because Mac and Windows apparently can't agree on something as simple as font sizes.

Colors

Colors are dealt with in a similar fashion.

wnd_bg      -- Window BG
tab_bg      -- Tabs BG
elm_bg      -- Element BG
elm_frame   -- Element Frame
elm_fill    -- Element Fill
elm_outline -- Element Outline
txt         -- Text
GUI.color("elm_fill")
GUI.elms.my_label.color = "cyan"

As with fonts, the color presets can be added to or amended:

                     R   G    B    A
GUI.colors["red"] = {16, 103, 192, 255}
GUI.colors["my_ugly_button"] = {96, 128, 192, 255}

And GUI.color can likewise be given a color table directly.

The 16 standard web colors are also available, by name: GUI.color("magenta")

Important: Prior to calling GUI.Init, the color presets are stored as 0-255 values. Init converts them to 0-1, since that's what REAPER's gfx functions use. Be aware of this if you need to work with any color values directly after the script has started. In all honesty, though, you probably won't need to.

Setting the color yourself

Some scripts may need to tinker with the gfx color values directly, for instance to create the Label class' :fade. This is perfectly fine, but make sure you set gfx.a = 1 when you're finished. GUI.Main checks it a couple of times, but forgetting to reset a can mess up the appearance of the entire GUI.