formalize attributes

This commit is contained in:
airstruck
2015-11-29 14:58:08 -05:00
parent bfe31e05db
commit 2d64e6ca69
28 changed files with 1921 additions and 201 deletions

View File

@@ -1,7 +1,8 @@
project = 'Luigi'
project = 'LUIGI'
description = 'Lovely User Interfaces for Game Inventors'
full_description = 'A UI library for LÖVE 0.10.0 and 0.9.2'
full_description = 'A UI library'
file = { 'luigi' }
format = 'markdown'
-- sort = true
new_type('widget', 'Widget Types', true)
new_type('attrib', 'Widget Attributes', false)

View File

@@ -24,7 +24,7 @@
<div id="navigation">
<br/>
<h1>Luigi</h1>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
@@ -42,6 +42,21 @@
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
</div>
@@ -144,7 +159,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-27 06:40:48 </i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

View File

@@ -24,7 +24,7 @@
<div id="navigation">
<br/>
<h1>Luigi</h1>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
@@ -43,6 +43,21 @@
<li><strong>Layout</strong></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
</div>
@@ -384,7 +399,7 @@ found, and focuses that widget.
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-27 06:40:48 </i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

View File

@@ -24,7 +24,7 @@
<div id="navigation">
<br/>
<h1>Luigi</h1>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
@@ -33,8 +33,8 @@
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Tables">Tables</a></li>
<li><a href="#Methods">Methods</a></li>
<li><a href="#Constructor">Constructor</a></li>
</ul>
@@ -44,6 +44,21 @@
<li><a href="../classes/Layout.html">Layout</a></li>
<li><strong>Widget</strong></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
</div>
@@ -62,17 +77,6 @@
<td class="name" nowrap><a href="#Widget.register">Widget.register (name, decorator)</a></td>
<td class="summary">Register a custom widget type.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Luigi.Widget">Luigi.Widget (layout[, data])</a></td>
<td class="summary">Widget pseudo-constructor.</td>
</tr>
</table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#Widget.typeDecorators">Widget.typeDecorators</a></td>
<td class="summary">Widget type registry.</td>
</tr>
</table>
<h2><a href="#Methods">Methods</a></h2>
<table class="function_list">
@@ -133,6 +137,13 @@
<td class="summary">Reshape the widget.</td>
</tr>
</table>
<h2><a href="#Constructor">Constructor</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#Luigi.Widget">Luigi.Widget (layout[, data])</a></td>
<td class="summary">Widget pseudo-constructor.</td>
</tr>
</table>
<br/>
<br/>
@@ -165,84 +176,6 @@
</dd>
<dt>
<a name = "Luigi.Widget"></a>
<strong>Luigi.Widget (layout[, data])</strong>
</dt>
<dd>
Widget pseudo-constructor.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">layout</span>
<span class="types"><a class="type" href="../classes/Layout.html#">Layout</a></span>
The layout this widget belongs to.
</li>
<li><span class="parameter">data</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
The data definition table for this widget.
This table is identical to the constructed widget.
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../classes/Widget.html#">Widget</a></span>
A Widget instance.
</ol>
</dd>
</dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "Widget.typeDecorators"></a>
<strong>Widget.typeDecorators</strong>
</dt>
<dd>
Widget type registry.
<h3>Fields:</h3>
<ul>
<li><span class="parameter">button</span>
A simple button
</li>
<li><span class="parameter">menu</span>
A menu bar
</li>
<li><span class="parameter">[</span>
A menu item
</li>
<li><span class="parameter">progress</span>
A progress bar
</li>
<li><span class="parameter">sash</span>
Resizes nearby widgets
</li>
<li><span class="parameter">slider</span>
Slides to adjust a normalized value
</li>
<li><span class="parameter">stepper</span>
Steps through a series of choices
</li>
<li><span class="parameter">text</span>
A text entry widget
</li>
</ul>
</dd>
</dl>
<h2 class="section-header "><a name="Methods"></a>Methods</h2>
@@ -588,6 +521,43 @@ on the parent widget.
</dd>
</dl>
<h2 class="section-header "><a name="Constructor"></a>Constructor</h2>
<dl class="function">
<dt>
<a name = "Luigi.Widget"></a>
<strong>Luigi.Widget (layout[, data])</strong>
</dt>
<dd>
Widget pseudo-constructor.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">layout</span>
<span class="types"><a class="type" href="../classes/Layout.html#">Layout</a></span>
The layout this widget belongs to.
</li>
<li><span class="parameter">data</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
The data definition table for this widget.
This table is identical to the constructed widget.
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../classes/Widget.html#">Widget</a></span>
A Widget instance.
</ol>
</dd>
</dl>
@@ -596,7 +566,7 @@ on the parent widget.
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-27 06:40:48 </i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

View File

@@ -24,11 +24,26 @@
<div id="navigation">
<br/>
<h1>Luigi</h1>
<h1>LUIGI</h1>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="widget types/button.html">button</a></li>
<li><a href="widget types/menu.html">menu</a></li>
<li><a href="widget types/menu.item.html">menu.item</a></li>
<li><a href="widget types/progress.html">progress</a></li>
<li><a href="widget types/sash.html">sash</a></li>
<li><a href="widget types/slider.html">slider</a></li>
<li><a href="widget types/stepper.html">stepper</a></li>
<li><a href="widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="classes/Event.html">Event</a></li>
@@ -42,8 +57,50 @@
<h2>Lovely User Interfaces for Game Inventors</h2>
<p>A UI library for LÖVE 0.10.0 and 0.9.2</p>
<p>A UI library</p>
<h2>Widget Types</h2>
<table class="module_list">
<tr>
<td class="name" nowrap><a href="widget_types/button.html">button</a></td>
<td class="summary">A simple button.</td>
</tr>
<tr>
<td class="name" nowrap><a href="widget_types/menu.html">menu</a></td>
<td class="summary">A menu bar.</td>
</tr>
<tr>
<td class="name" nowrap><a href="widget_types/menu.item.html">menu.item</a></td>
<td class="summary">A menu item.</td>
</tr>
<tr>
<td class="name" nowrap><a href="widget_types/progress.html">progress</a></td>
<td class="summary">A progress bar.</td>
</tr>
<tr>
<td class="name" nowrap><a href="widget_types/sash.html">sash</a></td>
<td class="summary">A sash.</td>
</tr>
<tr>
<td class="name" nowrap><a href="widget_types/slider.html">slider</a></td>
<td class="summary">A slider.</td>
</tr>
<tr>
<td class="name" nowrap><a href="widget_types/stepper.html">stepper</a></td>
<td class="summary">A stepper.</td>
</tr>
<tr>
<td class="name" nowrap><a href="widget_types/text.html">text</a></td>
<td class="summary">A text entry area.</td>
</tr>
</table>
<h2>Modules</h2>
<table class="module_list">
<tr>
<td class="name" nowrap><a href="modules/attribute.html">attribute</a></td>
<td class="summary">Widget attributes.</td>
</tr>
</table>
<h2>Classes</h2>
<table class="module_list">
<tr>
@@ -64,7 +121,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-27 06:40:48 </i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

604
doc/modules/attribute.html Normal file
View File

@@ -0,0 +1,604 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Widget_Attributes">Widget Attributes</a></li>
<li><a href="#Size_Attributes">Size Attributes </a></li>
<li><a href="#Font_Attributes">Font Attributes </a></li>
<li><a href="#Text_Attributes">Text Attributes </a></li>
<li><a href="#Visual_Attributes">Visual Attributes </a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><strong>attribute</strong></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>attribute</code></h1>
<p>Widget attributes.</p>
<p>This module defines "attributes" (special fields) that are
recognized by all widgets. Their interpretation may vary
depending on the <a href="http://www.lua.org/manual/5.1/manual.html#pdf-type">type</a> of widget. Some widget types may also
recognize additional attributes.</p>
<p>Setting attributes can have side effects. For example, setting
<a href="../modules/attribute.html#height">height</a> or <a href="../modules/attribute.html#width">width</a> causes the parent widget and its descendants
to recalculate their size and position.</p>
<h2><a href="#Widget_Attributes">Widget Attributes</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#id">id</a></td>
<td class="summary">widget identifier.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#key">key</a></td>
<td class="summary">Keyboard accelerator.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#value">value</a></td>
<td class="summary">widget value.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#style">style</a></td>
<td class="summary">widget style.</td>
</tr>
</table>
<h2><a href="#Size_Attributes">Size Attributes </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#flow">flow</a></td>
<td class="summary">Flow axis.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#width">width</a></td>
<td class="summary">Width.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#height">height</a></td>
<td class="summary">Height.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#minwidth">minwidth</a></td>
<td class="summary">Minimum width.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#minheight">minheight</a></td>
<td class="summary">Minimum height.</td>
</tr>
</table>
<h2><a href="#Font_Attributes">Font Attributes </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#font">font</a></td>
<td class="summary">Font path.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#size">size</a></td>
<td class="summary">Font size.</td>
</tr>
</table>
<h2><a href="#Text_Attributes">Text Attributes </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#text">text</a></td>
<td class="summary">Text to display.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#color">color</a></td>
<td class="summary">Text color.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#align">align</a></td>
<td class="summary">Text and icon alignment.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#wrap">wrap</a></td>
<td class="summary">Wrap text onto multiple lines.</td>
</tr>
</table>
<h2><a href="#Visual_Attributes">Visual Attributes </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#background">background</a></td>
<td class="summary">Background color.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#outline">outline</a></td>
<td class="summary">Outline color.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#slices">slices</a></td>
<td class="summary">Slice image.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#margin">margin</a></td>
<td class="summary">Margin size.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#padding">padding</a></td>
<td class="summary">Padding size.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#icon">icon</a></td>
<td class="summary">Icon path.</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Widget_Attributes"></a>Widget Attributes</h2>
<dl class="function">
<dt>
<a name = "id"></a>
<strong>id</strong>
</dt>
<dd>
widget identifier. </p>
<p>Should contain a unique string identifying the widget, if present.</p>
<p>A reference to the widget will be stored in the associated layout
in a property having the same name as the widget's id.</p>
<p>Setting this attribute re-registers the widget with its layout.
</dd>
<dt>
<a name = "key"></a>
<strong>key</strong>
</dt>
<dd>
Keyboard accelerator. </p>
<p>Should contain a string representing a key and optional modifiers,
separated by dashes; for example <code>&apos;ctrl-c&apos;</code> or <code>&apos;alt-shift-escape&apos;</code>.</p>
<p>Pressing this key combination bubbles a <code>Press</code> event on the widget,
as if it had been pressed with a mouse or touch interface.</p>
<p>Setting this attribute re-registers the widget with its layout.
</dd>
<dt>
<a name = "value"></a>
<strong>value</strong>
</dt>
<dd>
widget value. </p>
<p>Some widget types expect the value to be of a specific type and
within a specific range. For example, <a href="../widget types/slider.html#">slider</a> and <a href="../widget types/progress.html#">progress</a>
widgets expect a normalized number, and <a href="../widget types/text.html#">text</a> widgets expect
a string.</p>
<p>Setting this attribute bubbles the <code>Change</code> event.
</dd>
<dt>
<a name = "style"></a>
<strong>style</strong>
</dt>
<dd>
widget style. </p>
<p>Should contain a string or array of strings identifying
style rules to be applied to the widget. When resolving
any attribute with a <code>nil</code> value, these style rules are
searched for a corresponding attribute.</p>
<p>Setting this attribute resets the <code>Font</code> and <code>Text</code> object
associated with this widget.</p>
<p>Setting this attribute recalculates the size and position
of the parent widget and its descendants.
</dd>
</dl>
<h2 class="section-header has-description"><a name="Size_Attributes"></a>Size Attributes </h2>
<div class="section-description">
Setting these attributes recalculates the size and position
of the parent widget and its descendants.
</div>
<dl class="function">
<dt>
<a name = "flow"></a>
<strong>flow</strong>
</dt>
<dd>
Flow axis. </p>
<p>Should equal either <code>&apos;x&apos;</code> or <code>&apos;y&apos;</code>. Defaults to <code>&apos;y&apos;</code>.</p>
<p>This attribute determines the placement and default dimensions
of any child widgets.</p>
<p>When flow is <code>&apos;x&apos;</code>, the <a href="../modules/attribute.html#height">height</a> of child widgets defaults
to this widget's height, and each child is placed to the
right of the previous child. When flow is <code>&apos;y&apos;</code>, the <a href="../modules/attribute.html#width">width</a>
of child widgets defaults to this widget's width, and each
child is placed below the previous child.</p>
<p>Setting this attribute resets the <code>Text</code> object associated
with this widget.
</dd>
<dt>
<a name = "width"></a>
<strong>width</strong>
</dt>
<dd>
Width. </p>
<p>This attribute may not always hold a numeric value.
To get the calculated width, use <a href="../classes/Widget.html#Widget:getWidth">Widget:getWidth</a>.</p>
<p>Setting this attribute when the <a href="../modules/attribute.html#wrap">wrap</a> attribute is
also present resets the <code>Text</code> object associated
with this widget.
</dd>
<dt>
<a name = "height"></a>
<strong>height</strong>
</dt>
<dd>
Height. </p>
<p>This attribute may not always hold a numeric value.
To get the calculated height, use <a href="../classes/Widget.html#Widget:getHeight">Widget:getHeight</a>.
</dd>
<dt>
<a name = "minwidth"></a>
<strong>minwidth</strong>
</dt>
<dd>
Minimum width.
</dd>
<dt>
<a name = "minheight"></a>
<strong>minheight</strong>
</dt>
<dd>
Minimum height.
</dd>
</dl>
<h2 class="section-header has-description"><a name="Font_Attributes"></a>Font Attributes </h2>
<div class="section-description">
Setting these attributes resets the Font and Text
objects associated with the widget.
</div>
<dl class="function">
<dt>
<a name = "font"></a>
<strong>font</strong>
</dt>
<dd>
Font path. </p>
<p>Should contain a path to a TrueType font to use for displaying
this widget's <a href="../widget types/text.html#">text</a>.
</dd>
<dt>
<a name = "size"></a>
<strong>size</strong>
</dt>
<dd>
Font size. </p>
<p>Should contain a number representing the size of the font, in points.
Defaults to 12.
</dd>
</dl>
<h2 class="section-header has-description"><a name="Text_Attributes"></a>Text Attributes </h2>
<div class="section-description">
Setting these attributes resets the Text object
associated with the widget.
</div>
<dl class="function">
<dt>
<a name = "text"></a>
<strong>text</strong>
</dt>
<dd>
Text to display.
</dd>
<dt>
<a name = "color"></a>
<strong>color</strong>
</dt>
<dd>
Text color. </p>
<p>Should contain an array with 3 or 4 values (RGB or RGBA) from 0 to 255.
</dd>
<dt>
<a name = "align"></a>
<strong>align</strong>
</dt>
<dd>
Text and icon alignment.
</dd>
<dt>
<a name = "wrap"></a>
<strong>wrap</strong>
</dt>
<dd>
Wrap text onto multiple lines. </p>
<p>Should contain <code>true</code> for multiline text, or <code>false</code> or <code>nil</code>
for a single line. Even text containing line breaks will display
as a single line when this attribute is not set to <code>true</code>.
</dd>
</dl>
<h2 class="section-header "><a name="Visual_Attributes"></a>Visual Attributes </h2>
<dl class="function">
<dt>
<a name = "background"></a>
<strong>background</strong>
</dt>
<dd>
Background color. </p>
<p>Should contain an array with 3 or 4 values (RGB or RGBA) from 0 to 255.
</dd>
<dt>
<a name = "outline"></a>
<strong>outline</strong>
</dt>
<dd>
Outline color. </p>
<p>Should contain an array with 3 or 4 values (RGB or RGBA) from 0 to 255.
</dd>
<dt>
<a name = "slices"></a>
<strong>slices</strong>
</dt>
<dd>
Slice image. </p>
<p>Should contain a path to an image with "slices" to display for this widget.
</dd>
<dt>
<a name = "margin"></a>
<strong>margin</strong>
</dt>
<dd>
Margin size. </p>
<p>The margin area occupies space outside of the <a href="../modules/attribute.html#outline">outline</a> and <a href="../modules/attribute.html#slices">slices</a>.
</dd>
<dt>
<a name = "padding"></a>
<strong>padding</strong>
</dt>
<dd>
Padding size. </p>
<p>The padding area occupies space inside the <a href="../modules/attribute.html#outline">outline</a> and <a href="../modules/attribute.html#slices">slices</a>,
and outside the space where the <a href="../modules/attribute.html#icon">icon</a> and <a href="../widget types/text.html#">text</a> and any
child widgets appear.
</dd>
<dt>
<a name = "icon"></a>
<strong>icon</strong>
</dt>
<dd>
Icon path. </p>
<p>Should contain a path to an image file.
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,83 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><strong>button</strong></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>button</code></h1>
<p>A simple button.</p>
<p>
</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,83 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><strong>menu</strong></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>menu</code></h1>
<p>A menu bar.</p>
<p>
</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,83 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><strong>menu.item</strong></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>menu.item</code></h1>
<p>A menu item.</p>
<p>When a <a href="../widget types/menu.html#">menu</a> is created, any sub-items not having a specified type
are automatically given a type of <code>&apos;menu.item&apos;</code>. These widgets should
not be explicitly created.</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,82 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><strong>progress</strong></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>progress</code></h1>
<p>A progress bar.</p>
<p>Set the widget's <code>value</code> property to a decimal value
between 0 and 1 (inclusive) to change the width of the bar.</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,87 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><strong>sash</strong></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>sash</code></h1>
<p>A sash.</p>
<p>Dragging this widget resizes the widgets adjacent to it.
A sash must be adjacent to a widget with a specified size
in the same direction as the parent element's <code>flow</code>.</p>
<p>For example, if the parent of the sash is <code>flow = &apos;x&apos;</code>
then either or both of the siblings next to the sash
must have a specified <code>width</code> property.</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,82 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><strong>slider</strong></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>slider</code></h1>
<p>A slider.</p>
<p>Dragging this widget changes its <code>value</code> property to a
number between 0 and 1, inclusive.</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,85 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><strong>stepper</strong></li>
<li><a href="../widget types/text.html">text</a></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>stepper</code></h1>
<p>A stepper.</p>
<p>This widget is composed of two buttons and a content area.
Upon creation, this widget's children are moved into an
<code>items</code> property. The items are displayed one at a time in
the content area. Pressing the buttons cycles through the
item displayed in the content area.</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -0,0 +1,83 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LUIGI</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Widget Types</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../widget types/button.html">button</a></li>
<li><a href="../widget types/menu.html">menu</a></li>
<li><a href="../widget types/menu.item.html">menu.item</a></li>
<li><a href="../widget types/progress.html">progress</a></li>
<li><a href="../widget types/sash.html">sash</a></li>
<li><a href="../widget types/slider.html">slider</a></li>
<li><a href="../widget types/stepper.html">stepper</a></li>
<li><strong>text</strong></li>
</ul>
<h2>Modules</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../modules/attribute.html">attribute</a></li>
</ul>
<h2>Classes</h2>
<ul class="$(kind=='Topics' and '' or 'nowrap'">
<li><a href="../classes/Event.html">Event</a></li>
<li><a href="../classes/Layout.html">Layout</a></li>
<li><a href="../classes/Widget.html">Widget</a></li>
</ul>
</div>
<div id="content">
<h1>Widget <code>text</code></h1>
<p>A text entry area.</p>
<p>
</p>
<br/>
<br/>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
<i style="float:right;">Last updated 2015-11-29 14:57:48 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View File

@@ -100,7 +100,7 @@ local mainForm = { id = 'mainWindow', type = 'panel',
{ type = 'button', key='return', width = 80, id = 'aButton', text = 'Styling!',
font = 'font/liberation/LiberationMono-Regular.ttf' },
},
{ type = 'panel', id = 'statusbar', height = 24, padding = 4, textColor = { 255, 0, 0 } },
{ type = 'panel', id = 'statusbar', height = 24, padding = 4, color = { 255, 0, 0 } },
}
local layout = Layout(mainForm)

385
luigi/attribute.lua Normal file
View File

@@ -0,0 +1,385 @@
--[[--
Widget attributes.
This module defines "attributes" (special fields) that are
recognized by all widgets. Their interpretation may vary
depending on the `type` of widget. Some widget types may also
recognize additional attributes.
Setting attributes can have side effects. For example, setting
`height` or `width` causes the parent widget and its descendants
to recalculate their size and position.
--]]--
local Attribute = {}
--[[--
widget identifier.
Should contain a unique string identifying the widget, if present.
A reference to the widget will be stored in the associated layout
in a property having the same name as the widget's id.
Setting this attribute re-registers the widget with its layout.
@attrib id
--]]--
function Attribute.id (widget, value)
local layout = widget.layout.master or widget.layout
local oldValue = widget.attributes.id
if oldValue then
layout[oldValue] = nil
end
if value then
layout[value] = widget
end
widget.attributes.id = value
end
-- TODO: formalize this bitfield somewhere
local function parseKeyCombo (value)
local mainKey = (value):match '[^%-]+$'
local alt = (value):match 'alt%-' and 1 or 0
local ctrl = (value):match 'ctrl%-' and 2 or 0
local shift = (value):match 'shift%-' and 4 or 0
local modifierFlags = alt + ctrl + shift
return mainKey, modifierFlags
end
--[[--
Keyboard accelerator.
Should contain a string representing a key and optional modifiers,
separated by dashes; for example `'ctrl-c'` or `'alt-shift-escape'`.
Pressing this key combination bubbles a `Press` event on the widget,
as if it had been pressed with a mouse or touch interface.
Setting this attribute re-registers the widget with its layout.
@attrib key
--]]--
function Attribute.key (widget, value)
local layout = widget.layout.master or widget.layout
local oldValue = widget.attributes.key
if oldValue then
local mainKey, modifierFlags = parseKeyCombo(oldValue)
layout.accelerators[modifierFlags][mainKey] = nil
end
if value then
local mainKey, modifierFlags = parseKeyCombo(value)
layout.accelerators[modifierFlags][mainKey] = widget
end
widget.attributes.key = value
end
--[[--
widget value.
Some widget types expect the value to be of a specific type and
within a specific range. For example, `slider` and `progress`
widgets expect a normalized number, and `text` widgets expect
a string.
Setting this attribute bubbles the `Change` event.
@attrib value
--]]--
function Attribute.value (widget, value)
local oldValue = widget.value
widget.attributes.value = value
widget:bubbleEvent('Change', { value = value, oldValue = oldValue })
end
--[[--
widget style.
Should contain a string or array of strings identifying
style rules to be applied to the widget. When resolving
any attribute with a `nil` value, these style rules are
searched for a corresponding attribute.
Setting this attribute resets the `Font` and `Text` object
associated with this widget.
Setting this attribute recalculates the size and position
of the parent widget and its descendants.
@attrib style
--]]--
function Attribute.style (widget, value)
widget.attributes.style = value
widget.fontData = nil
widget.textData = nil
widget.reshape(widget.parent or widget)
end
--[[--
Size Attributes.
Setting these attributes recalculates the size and position
of the parent widget and its descendants.
@section size
--]]--
--[[--
Flow axis.
Should equal either `'x'` or `'y'`. Defaults to `'y'`.
This attribute determines the placement and default dimensions
of any child widgets.
When flow is `'x'`, the `height` of child widgets defaults
to this widget's height, and each child is placed to the
right of the previous child. When flow is `'y'`, the `width`
of child widgets defaults to this widget's width, and each
child is placed below the previous child.
Setting this attribute resets the `Text` object associated
with this widget.
@attrib flow
--]]--
function Attribute.flow (widget, value)
widget.attributes.flow = value
widget.textData = nil
widget.reshape(widget.parent or widget)
end
--[[--
Width.
This attribute may not always hold a numeric value.
To get the calculated width, use `Widget:getWidth`.
Setting this attribute when the `wrap` attribute is
also present resets the `Text` object associated
with this widget.
@attrib width
--]]--
function Attribute.width (widget, value)
value = value and math.max(value, widget.minwidth or 0)
widget.attributes.width = value
if widget.wrap then
widget.textData = nil
end
widget.reshape(widget.parent or widget)
end
--[[--
Height.
This attribute may not always hold a numeric value.
To get the calculated height, use `Widget:getHeight`.
@attrib height
--]]--
function Attribute.height (widget, value)
value = value and math.max(value, widget.minheight or 0)
widget.attributes.height = value
widget.reshape(widget.parent or widget)
end
--[[--
Minimum width.
@attrib minwidth
--]]--
function Attribute.minwidth (widget, value)
widget.attributes.minwidth = value
widget.reshape(widget.parent or widget)
end
--[[--
Minimum height.
@attrib minheight
--]]--
function Attribute.minheight (widget, value)
widget.attributes.minheight = value
widget.reshape(widget.parent or widget)
end
--[[--
Font Attributes.
Setting these attributes resets the Font and Text
objects associated with the widget.
@section font
--]]--
--[[--
Font path.
Should contain a path to a TrueType font to use for displaying
this widget's `text`.
@attrib font
--]]--
function Attribute.font (widget, value)
widget.attributes.font = value
widget.fontData = nil
widget.textData = nil
end
--[[--
Font size.
Should contain a number representing the size of the font, in points.
Defaults to 12.
@attrib size
--]]--
function Attribute.size (widget, value)
widget.attributes.size = value
widget.fontData = nil
widget.textData = nil
end
--[[--
Text Attributes.
Setting these attributes resets the Text object
associated with the widget.
@section text
--]]--
--[[--
Text to display.
@attrib text
--]]--
function Attribute.text (widget, value)
widget.attributes.text = value
widget.textData = nil
end
--[[--
Text color.
Should contain an array with 3 or 4 values (RGB or RGBA) from 0 to 255.
@attrib color
--]]--
function Attribute.color (widget, value)
widget.attributes.color = value
widget.textData = nil
end
--[[--
Text and icon alignment.
@attrib align
--]]--
function Attribute.align (widget, value)
widget.attributes.align = value
widget.textData = nil
end
--[[--
Wrap text onto multiple lines.
Should contain `true` for multiline text, or `false` or `nil`
for a single line. Even text containing line breaks will display
as a single line when this attribute is not set to `true`.
@attrib wrap
--]]--
function Attribute.wrap (widget, value)
widget.attributes.wrap = value
widget.textData = nil
end
--[[--
Visual Attributes.
@section visual
--]]--
--[[--
Background color.
Should contain an array with 3 or 4 values (RGB or RGBA) from 0 to 255.
@attrib background
--]]--
function Attribute.background (widget, value)
widget.attributes.background = value
end
--[[--
Outline color.
Should contain an array with 3 or 4 values (RGB or RGBA) from 0 to 255.
@attrib outline
--]]--
function Attribute.outline (widget, value)
widget.attributes.outline = value
end
--[[--
Slice image.
Should contain a path to an image with "slices" to display for this widget.
@attrib slices
--]]--
function Attribute.slices (widget, value)
widget.attributes.slices = value
end
--[[--
Margin size.
The margin area occupies space outside of the `outline` and `slices`.
@attrib margin
--]]--
function Attribute.margin (widget, value)
widget.attributes.margin = value
widget.textData = nil
widget:reshape()
end
--[[--
Padding size.
The padding area occupies space inside the `outline` and `slices`,
and outside the space where the `icon` and `text` and any
child widgets appear.
@attrib padding
--]]--
function Attribute.padding (widget, value)
widget.attributes.padding = value
widget.textData = nil
widget:reshape()
end
--[[--
Icon path.
Should contain a path to an image file.
@attrib icon
--]]--
function Attribute.icon (widget, value)
widget.attributes.icon = value
widget.textData = nil
end
return Attribute

View File

@@ -149,7 +149,7 @@ function Renderer:positionText (widget, x1, y1, x2, y2)
end
if not widget.fontData then
widget.fontData = Font(widget.font, widget.fontSize)
widget.fontData = Font(widget.font, widget.size)
end
local font = widget.fontData
@@ -168,7 +168,7 @@ function Renderer:positionText (widget, x1, y1, x2, y2)
if not widget.textData then
local limit = widget.wrap and x2 - x1 or nil
widget.textData = Text(
font, widget.text, widget.textColor, horizontal, limit)
font, widget.text, widget.color, horizontal, limit)
end
local textHeight = widget.textData:getHeight()

View File

@@ -17,6 +17,7 @@ function Style:getProperty (object, property, original)
for _, lookupName in ipairs(self.lookupNames) do
local lookup = rawget(object, lookupName)
or object.attributes and rawget(object.attributes, lookupName)
if lookup then
if type(lookup) ~= 'table' then
lookup = { lookup }

View File

@@ -41,7 +41,7 @@ return function (config)
['menu.item'] = {
padding = 4,
align = 'left middle',
textColor = { 0, 0, 0 }
color = { 0, 0, 0 }
},
['menu.item_active'] = {
background = highlight,

View File

@@ -8,6 +8,7 @@ local ROOT = (...):gsub('[^.]*$', '')
local Backend = require(ROOT .. 'backend')
local Event = require(ROOT .. 'event')
local Attribute = require(ROOT .. 'attribute')
local Font = Backend.Font
local Widget = {}
@@ -16,18 +17,15 @@ Event.injectBinders(Widget)
Widget.isWidget = true
--[[--
Widget type registry.
--]]--
Widget.typeDecorators = {
button = require(ROOT .. 'widget.button'), -- A simple button
menu = require(ROOT .. 'widget.menu'), -- A menu bar
['menu.item'] = require(ROOT .. 'widget.menu.item'), -- A menu item
progress = require(ROOT .. 'widget.progress'), -- A progress bar
sash = require(ROOT .. 'widget.sash'), -- Resizes nearby widgets
slider = require(ROOT .. 'widget.slider'), -- Slides to adjust a normalized value
stepper = require(ROOT .. 'widget.stepper'), -- Steps through a series of choices
text = require(ROOT .. 'widget.text'), -- A text entry widget
button = require(ROOT .. 'widget.button'),
menu = require(ROOT .. 'widget.menu'),
['menu.item'] = require(ROOT .. 'widget.menu.item'),
progress = require(ROOT .. 'widget.progress'),
sash = require(ROOT .. 'widget.sash'),
slider = require(ROOT .. 'widget.slider'),
stepper = require(ROOT .. 'widget.stepper'),
text = require(ROOT .. 'widget.text'),
}
--[[--
@@ -45,9 +43,9 @@ function Widget.register (name, decorator)
Widget.typeDecorators[name] = decorator
end
-- look for properties in shadow props, Widget, style, and theme
-- look for properties in attributes, Widget, style, and theme
local function metaIndex (self, property)
local value = self.shadowProperties[property]
local value = self.attributes[property]
if value ~= nil then return value end
local value = Widget[property]
@@ -62,92 +60,28 @@ local function metaIndex (self, property)
return theme and theme:getProperty(self, property)
end
-- setting shadow properties causes special behavior
-- setting attributes triggers special behavior
local function metaNewIndex (self, property, value)
if property == 'font' or property == 'fontSize' then
self.shadowProperties[property] = value
self.fontData = nil
self.textData = nil
end
if property == 'text' or property == 'textColor'
or property == 'align' or property == 'wrap' then
self.shadowProperties[property] = value
self.textData = nil
return
end
if property == 'width' then
value = value and math.max(value, self.minwidth or 0)
self.shadowProperties[property] = value
if self.wrap then
self.textData = nil
end
Widget.reshape(self.parent or self)
return
end
if property == 'height' then
value = value and math.max(value, self.minheight or 0)
self.shadowProperties[property] = value
Widget.reshape(self.parent or self)
return
end
if property == 'value' then
local oldValue = self.value
self.shadowProperties[property] = value
self:bubbleEvent('Change', {
value = value,
oldValue = oldValue,
})
return
end
if property == 'key' then
self.shadowProperties[property] = value
if not value then return end
local mainKey = (value):match '[^%-]+$'
local alt = (value):match 'alt%-' and 1 or 0
local ctrl = (value):match 'ctrl%-' and 2 or 0
local shift = (value):match 'shift%-' and 4 or 0
local modifierFlags = alt + ctrl + shift
local layout = self.layout.master or self.layout
layout.accelerators[modifierFlags][mainKey] = self
return
end
if property == 'id' then
self.shadowProperties[property] = value
if not value then return end
local layout = self.layout.master or self.layout
layout[value] = self
return
if Attribute[property] then
return Attribute[property](self, value)
end
rawset(self, property, value)
end
local shadowKeys = {
'id', 'key', 'value',
'width', 'height',
'font', 'fontSize',
'text', 'textColor',
'align', 'wrap',
}
local attributeNames = {}
for name in pairs(Attribute) do
attributeNames[#attributeNames + 1] = name
end
--[[--
Widget pseudo-constructor.
@function Luigi.Widget
@within Constructor
@tparam Layout layout
The layout this widget belongs to.
@@ -163,18 +97,18 @@ local function metaCall (Widget, layout, self)
self.layout = layout
self.position = { x = nil, y = nil }
self.dimensions = { width = nil, height = nil }
self.shadowProperties = {}
self.attributes = {}
setmetatable(self, { __index = metaIndex, __newindex = metaNewIndex })
for _, property in ipairs(shadowKeys) do
for _, property in ipairs(attributeNames) do
local value = rawget(self, property)
rawset(self, property, nil)
self[property] = value
end
self.type = self.type or 'generic'
self.fontData = Font(self.font, self.fontSize, self.textColor)
self.fontData = Font(self.font, self.size, self.color)
-- layout:addWidget(self)

View File

@@ -1,3 +1,9 @@
--[[--
A simple button.
@widget button
--]]--
return function (self)
end

View File

@@ -1,3 +1,9 @@
--[[--
A menu bar.
@widget menu
--]]--
return function (self)
for index, child in ipairs(self) do

View File

@@ -1,3 +1,12 @@
--[[--
A menu item.
When a `menu` is created, any sub-items not having a specified type
are automatically given a type of `'menu.item'`. These widgets should
not be explicitly created.
@widget menu.item
--]]--
local ROOT = (...):gsub('[^.]*.[^.]*.[^.]*$', '')
local Layout, Event
@@ -125,7 +134,7 @@ local function initialize (self)
local textWidth = self.fontData:getAdvance(text) + pad * 2
if isSubmenu then
local tc = self.textColor or { 0, 0, 0, 255 }
local tc = self.color or { 0, 0, 0, 255 }
local keyColor = { tc[1], tc[2], tc[3], 0x90 }
local edgeType
if #self.items > 0 then
@@ -139,7 +148,7 @@ local function initialize (self)
self:addChild { icon = icon, width = self.height }
self:addChild { text = text, width = textWidth }
self:addChild { text = key, align = 'middle right',
minwidth = self.height, textColor = keyColor, type = edgeType }
minwidth = self.height, color = keyColor, type = edgeType }
self.icon = nil
self.text = nil

View File

@@ -1,3 +1,12 @@
--[[--
A progress bar.
Set the widget's `value` property to a decimal value
between 0 and 1 (inclusive) to change the width of the bar.
@widget progress
--]]--
return function (self)
self.value = 0
self.flow = 'x' -- TODO: support vertical progress?

View File

@@ -1,3 +1,17 @@
--[[--
A sash.
Dragging this widget resizes the widgets adjacent to it.
A sash must be adjacent to a widget with a specified size
in the same direction as the parent element's `flow`.
For example, if the parent of the sash is `flow = 'x'`
then either or both of the siblings next to the sash
must have a specified `width` property.
@widget sash
--]]--
local function setDimension (widget, name, size)
if not widget.parent then
widget[name] = size

View File

@@ -1,3 +1,12 @@
--[[--
A slider.
Dragging this widget changes its `value` property to a
number between 0 and 1, inclusive.
@widget slider
--]]--
return function (self)
local function clamp (value)

View File

@@ -1,3 +1,15 @@
--[[--
A stepper.
This widget is composed of two buttons and a content area.
Upon creation, this widget's children are moved into an
`items` property. The items are displayed one at a time in
the content area. Pressing the buttons cycles through the
item displayed in the content area.
@widget stepper
--]]--
return function (self)
self.items = {}
self.index = 1

View File

@@ -1,3 +1,8 @@
--[[--
A text entry area.
@widget text
--]]--
local ROOT = (...):gsub('[^.]*.[^.]*$', '')
local utf8 = require(ROOT .. 'utf8')
@@ -231,7 +236,7 @@ return function (self)
local x, y, w, h = self:getRectangle(true, true)
local width, height = endX - startX, h
local font = self.fontData
local textColor = self.textColor or { 0, 0, 0, 255 }
local color = self.color or { 0, 0, 0, 255 }
local textTop = math.floor(y + (h - font:getLineHeight()) / 2)
Backend.push()
@@ -242,12 +247,12 @@ return function (self)
Backend.setColor(self.highlight)
Backend.drawRectangle('fill', startX, y, width, height)
if Backend.getTime() % 2 < 1.75 then
Backend.setColor(textColor)
Backend.setColor(color)
Backend.drawRectangle('fill', endX, y, 1, height)
end
-- draw text
Backend.setColor(textColor)
Backend.setColor(color)
Backend.print(self.value, x - self.scrollX, textTop)
if not self.focused then
Backend.pop()