Module corky.text
Text drawing for Corky.
Loading the module:
#: include, corky.text
Adding a font:
#: list, <font_name>, <font_family>[, <font_slant>[, <font_weight>]]
Note: The corky.lists module will automatically be loaded when corky.text is loaded.
Parameters:
<font_name>
- The name for this font, will be used to reference the font in the
text
configuration directive (see below). May be any arbitrary non-empty string.
<font_family>
, <font_slant>
, <font_weight>
Specifies the font to be used, its slant and weight. These parameters will be passed to Cairo's
cairo_select_font_face
function. For more details please see Cairo's documentation on "Rendering text and glyphs".Note that
<font_slant>
and<font_weight>
are optional parameters and may be left empty, the default values areCAIRO_FONT_SLANT_NORMAL
andCAIRO_FONT_WEIGHT_NORMAL
, respectively. TheCAIRO_
prefix may be omitted.
Adding some text:
#: text, <name>, <x>, <y>, <font_name>, <size>, <color>, <text>[, <parameter> …]
Parameters:
<name>
- The name of this text, may be any arbitrary string. It is currently not used and may be left empty. Multiple texts with the same name are allowed.
<x>
- The X coordinate of the text. Must be a valid integer greater than or equal to
0
.
<y>
- The Y coordinate of the text. Must be a valid integer greater than or equal to
0
.
<font_name>
- The font to be used. It has to be defined using a
list
directive (as explained above) before thetext
directive!
<size>
- The font size to use for the text. Must be a valid integer greater than
0
.
<color>
- The text color. The corky.dcolors module will be used to resolve the color, so any named color (see
corky.colors), fixed dynamic color or gradient color (see corky.dcolors) may be used, or a
0x<AARRGGBB>
value (or in fact any valid number between0
and0xffffffff
, see the colors module) may be used directly.
<text>
, <parameter>
The text to display. If only the
<text>
is specified without any more parameters, the<text>
will be drawn as is (conky_parse
will not be called). If one or more parameters follow the<text>
, these will be parsed byconky_parse
(via corky.cache), and the text to print will be constructed using string.format, with the<text>
describing the format of the string, and the parsed parameter values as the format arguments. Any arbitrary number of parameters (> 0
) is supported.For dynamic colors, the value to determine the text color if no parameters are specified is
0
, if parameters are specified the value of the last parameter will be used.
Examples:
#: list, fnt, DejaVu Sans Mono #: list, fnt_b, DejaVu Sans Mono, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD #: cache, ${cpu}, 1, 0, 100 #: dcolor, color, 0x00ff00, 50, 0xffff00, 0xff0000 #: text,, 10, 10, fnt, 14, color, %s, ${cpu} #: text,, 10, 30, fnt_b, 14, 0xabcdef, CPU: %s%% / %s%%, ${cpu cpu1}, ${cpu cpu2}
Info:
Functions
add (name, x, y, font_name, size, color, text, ...) | Add a text. |
text (x, y, font_family, font_slant, font_weight, size, color, text, params) | Draw some text. |
Local Functions
draw () | Draw the texts. |
config_handler (setting) | Configuration handler for text settings. |
Local Tables
texts | Stores the defined texts. |
Functions
- add (name, x, y, font_name, size, color, text, ...) line 150
-
Add a text.
The parameters are the same as the parameters for the configuration directive, in the same order. Please see above for more details.
This function will add the text to the list of texts, it will not draw it!
Parameters:
- name string Name of the text.
- x
int
X coordinate of the text (
x >= 0
). - y
int
Y coordinate of the text (
y >= 0
). - font_name string Name of the font definition list, see corky.lists.
- size
int
Font size (
size > 0
). - color The text color, uses corky.dcolors to get the actual color.
- text string The text.
- ... Additional parameters (enable string.format text handling).
Returns:
-
bool
Returns
true
if the text could be added,false
in case of any error.
- text (x, y, font_family, font_slant, font_weight, size, color, text, params) line 232
-
Draw some text.
Note: If the color can not be resolved the text will not be drawn!
Note: This function assumes that corky.cairo.init() has been called and a valid surface and context are available!
Parameters:
- x int X coordinate of the text.
- y int Y coordinate of the text.
- font_family string Font family.
- font_slant
Font slant (e.g.
cairo.FONT_SLANT_NORMAL
) - font_weight
Font weight (e.g.
cairo.FONT_WEIGHT_NORMAL
). - size int Font size.
- color Text color (string or number).
- text string Text.
- params Additional parameters.
Returns:
-
bool
Returns
true
if the text could be added,false
in case of any error.
Local Functions
- draw () line 275
- Draw the texts.
- config_handler (setting) line 299
-
Configuration handler for text settings.
This handler will be called automatically for every
text
directive in the configuration file.Parameters:
- setting table Array containing the configuration directive split into its individual parts.
Returns:
-
bool
If successful
true
,false
in case of any error.
See also:
Local Tables
- texts line 122
-
Stores the defined texts.
The keys are the text names, the values are arrays containing tables with the text data defined under that name, in the order they are added. The data tables contain the following keys:
x
,y
,font
,slant
,weight
,size
,color
,text
andparams
.params
is an array containing the optional parameters.