Thursday, March 17, 2011

Constantly Theme'd

One of the often requested features in LWUIT's themes has been the addition of constants for themes. Constants allow the theme designer to "hint" of desired functionality to the application code, e.g. a particular theme might have a constant indicating that it wants the scrollbar to fadeout when unused.The LWUIT resource editor now includes an additional tab for creating such constants which can be used to add constant values. These can be added in the ant task by prepending the @ sign before the constant key in the theme and setting the value to the appropriate string.Constants are always strings, they have some conventions where a constant ending with Bool is treated as a boolean true/false value and a constant ending with Int or Image (for image the string name of the image is stored but the image instance will be returned).

To use a constant one can use the UIManager's methods to get the appropriate constant type specifically:getThemeConstant isThemeConstantgetThemeImageConstant

Internally LWUIT has several builtin constants and the list is constantly growing as we add features to LWUIT, we will try to keep this list up to date when possible.

Indicates that a title with no content should be hidden even if the border for the title occupies space

.

ignorListFocusBool

Hide the focus component of the list when the list doesn't have focus

.

listItemGapInt

Builtin item gap in the list, this defaults to 2 which predated padding/margin in LWUIT

.

menuHeightPercent

Allows positioning and sizing the menu

.

menuPrefSizeBool

Allows positioning and sizing the menu

.

menuSlideDirection

Defines menu entrance effect

.

menuSlideInDirBool

Defines menu entrance effect

.

menuSlideOutDirBool

Defines menu entrance effect

.

menuTransitionIn

Defines menu entrance effect

.

menuTransitionInImage

Defines menu entrance effect

.

menuTransitionOut

Defines menu entrance effect

.

menuTransitionOutImage

Defines menu entrance effect

.

menuWidthPercent

Allows positioning and sizing the menu

.

otherPopupRendererBool

Indicates that a separate renderer UIID/instance should be used to the list within the combo box popup

.

popupCancelBodyBool

Indicates that a cancel button should appear within the combo box popup

.

popupTitleBool

Indicates that a title should appear within the combo box popup

.

pureTouchBool

Indicates the pure touch mode

.

radioSelectedDisImage

Radio button image

.

radioSelectedImage

Radio button image

.

radioUnselectedDisImage

Radio button image

.

radioUnselectedImage

Radio button image

.

rendererShowsNumbersBool

Indicates whether renderers should render the entry number

.

reverseSoftButtonsBool

Swaps the softbutton positions

.

slideDirection

Default slide transition settings

.

slideInDirBool

Default slide transition settings

.

slideOutDirBool

Default slide transition settings

.

snapGridBool

Snap to grid toggle

.

tabsFillRowsBool

Indicates if the tabs should fill the row using flow layout

.

tabsGridBool

Indicates whether tabs should use a grid layout thus forcing all tabs to have identical sizes

.

tickerSpeedInt

The speed of label/button etc. tickering in ms.

.

tintColor

The aarrggbb hex color to tint the screen when a dialog is shown

.

touchCommandFillBool

Indicates how the touch menu should layout the commands within

.

touchCommandFlowBool

Indicates how the touch menu should layout the commands within

.

touchMenuBool

Force the touch menu

.

transitionSpeedInt

Indicates the default speed for transitions

One "odd" behavior of constants is that once they are set by a theme they don't get "lost" when replacing the theme. E.g. if one would set the comboImage constant to a specific value in theme A and then switch to theme B that doesn't define the comboImage, the original theme A comboImage might remain. The reason for this is simple, when extracting the constant values components keep the values in cache locally and just don't track the change in value. Furthermore, since the components allow manually setting values its impractical for them to track whether a value was set by a constant or explicitly by the user.The solution for this is to either manually reset undesired values before replacing a theme (e.g. for the case above by calling the default look and feel method for setting the combo image with a null value) or defining a constant value to replace the existing value.

BTW I haven't been blogging or posting videos as often as I should both because I have been a bit under the weather and because I have been quite swamped with work (checkout the SVN changes). Hopefully I'll feel a bit better next week and increase my blogging a bit.