Xinf API Reference
Back | Index
class xinf.style.StyledElement
extends XMLElement

An Element with style.

Keeps a list of associated style classes, and automatically matches against the ownerDocument's StyleSheet.

Recognizes the "style" attribute when parsing from XML.

function new( traits:Dynamic ) :Void
Create a new StyledElement with initially empty style classes.
function setStyleTrait<T>( name:String, value:T ) :T
Set the style trait name to value. Similar to Element.setTrait, but also calls styleChanged().
function getStyleTrait<T>( name:String, type:Dynamic, ?inherit:Bool ) :T

Return the value of the "style trait" name. Style traits differ from normal traits in a few aspects:

  • they can come from StyleSheets
  • they can have SpecialTraitValues
  • they can be inherited (when inherit is true or omitted, or the trait has the special type Inherit)
  • their value is cached, so access should be relatively efficient even when the value is determined by inheritance.

DOCME: move this doc somewhere else?

function styleChanged( ) :Void

Hook function. Derived classes can override this to do something when the element's style changes (like redraw).

In reality, it is not strictly always called when the style would change-- notably, if the style comes from a StyleSheet, and either the StyleSheet changes or this element would match different selectors (because it changed in the display hierarchy), or similar things, it will *not* be called, in the current implementation.

Note, however, that setting any trait with setStyleTrait, or changing a StyledElement's style classes does indeed trigger a call to styleChanged.

function addStyleClass( name:String ) :Void
Add the style class name, and re-match against ownerDocument's StyleSheet.
function removeStyleClass( name:String ) :Void
Remove the style class name, and re-match against ownerDocument's StyleSheet.
function hasStyleClass( name:String ) :Bool
Return true if name is in the list of style classes.
function getStyleClasses( ) :Iterator<String>
Return an iterator of the list of style classes.
function getTagName( ) :String

Return the element's XML tag name.

FIXME: this needs rework. currently, tagName must be set "manually" by deriving classes. Binding could/should take care of that.

function matchSelector( s:Selector ) :Bool
Return true if the object matches the given Selector s, false otherwise.
Back | Index