Moscrif API Docs for: 2012q3
Show:

View Class

Library: ui

This class defines controls, which are components with visual representation.

Example:

var btnView = new Moscrif.View("button");
btnView.width = 150;
btnView.height = 150;
btnView.top = 100;
btnView.left = 100;
btnView.onDraw = function(s, c)
{
    ......
}
app.add(btnView);

Methods

this

(
  • [name]
)
View

Create new object.

Parameters:

  • [name] String optional

    Name of the object. Pass null for unnamed view

Returns:

View:

add

(
  • view
  • [order]
)
View chainable

Function adds existing view object into ScrollView.

Parameters:

  • view View

    View to add. View/ScrollView/TextView are supported.

  • [order] Symbol optional

    Default is.

        * #front
        * #back
    

Returns:

View: Return instance of itself.

Example:

var container = new Moscrif.View("container");
... width, height, onDraw ...
app.add(container);

var itemA = new Moscrif.View("itemA");
... width, height (60), top (0), onDraw ...
container.add(itemA);

var itemB = new Moscrif.View("itemB");
... width, height (60), top (60), onDraw ...
container.add(itemB);

detach

() chainable

Remove this view form it's parent.

Example:

var container = new Moscrif.View("container");

var itemA = new Moscrif.View("itemA");
container.add(itemA);

var itemB = new Moscrif.View("itemB");
container.add(itemB);
…...
// find view by name
var item = container.find("itemA");
// detach them
item.detach();

find

(
  • name
)
View

Search for child view, which name is same as name from function's param.

Parameters:

  • name String

    Name of the child view to search

Returns:

View: Instance of found child view, or null if not found.

Example:

var container = new Moscrif.View("container");

var itemA = new Moscrif.View("itemA");
container.add(itemA);

var itemB = new Moscrif.View("itemB");
container.add(itemB);
…...
// find view by name
var item = container.find("itemA");
// detach them
item.detach();

getChildrenBounds

() Multivalue

Returns four values (left, top, right, bottom) of child's union content.

Returns:

getChildrenSize

() Multivalue

Returns wo values (width, height) of child's union content.

Returns:

hasFocus

() Boolean

Returns true if ScrollView has focus. Otherwise, function returns false.

Returns:

invalidate

(
  • [left]
  • [top]
  • [right]
  • [bottom]
)

This function ensure redrawing a rectangle, determined by parameters. If no parameters are set, whole object will be redraw. Redrawing manages the function, which is set to onDraw event.

Parameters:

  • [left] Boolean optional

    Left border of the rectangle to be invalidated.

  • [top] Boolean optional

    Top border of the rectangle to be invalidated.

  • [right] Boolean optional

    Right border of the rectangle to be invalidated.

  • [bottom] Boolean optional

    Bottom border of the rectangle to be invalidated.

Example:

container = new Moscrif.View("container");
….
app.add(container);
….
// redraw top half of view
container.invalidate(0, 0, System.width, System.height / 2);

performLayout

() Window chainable

Performs (force) layout calculations.

Returns:

Window:

resumeDrawing

() Window

Resume view's drawing.

Returns:

Window:

resumeDrawing

() Window

Resume view's drawing.

Returns:

Window:

resumeLayout

() chainable

Resume layer's recalculating.

Example:

var container = new Moscrif.View("container");

// suspend layout before adding a large number of components to ensure better performance
container.suspendLayout();
for (var i = 0; i<NUM_OF_ITEMS; i++) {
    var item = new Moscrif.View("item_" + i);
    …. width, heigh, onDraw (left, top is managed by layout)...
    container.add(item);
}
// resume layout
container.resumeLayout();

setFocus

() Boolean

Function sets focus to the object.

Returns:

suspendDrawing

() Window chainable

Suspends the drawing of this view.

Returns:

Window:

suspendLayout

() Window

Pause layer's recalculating. This function is useful when a lot of items are inserted into view in short time. When resumeLayout is called, all items will be inserted at once .

Returns:

Window:

Example:

var container = new Moscrif.View("container");

// suspend layout before adding a large number of components to ensure better performance
container.suspendLayout();
for (var i = 0; i<NUM_OF_ITEMS; i++) {
    var item = new Moscrif.View("item_" + i);
    …. width, heigh, onDraw (left, top is managed by layout)...
    container.add(item);
}
// resume layout
container.resumeLayout()

Properties

childredCount

Integer

Count of the childs.

clipToBounds

Boolean

Set/Get if the view is not clipped to its bounds.

focusable

Boolean

Ability to have a focus.

height

Integer

Height of the view (in pixels).

layout

Integer

StackLayout used to organize elements into the object.

left

Integer

X - coordinates of view's position.

name

String

Name of the object.

stretch

Symbol

Gets or sets if the view's width is stretchable.

  • #both

top

Integer

Y - coordinates of view's position.

visible

Boolean

Visibility of the view. True = visible, false = invisible. Default is visible.

width

Integer

Width of the object (in pixels).

Events

onChar

This event is raised by release an UNICODE character key.

Event Payload:

  • sender Object

    Object which caused this event.

  • key Integer

    Code from unicode table.

onDraw

This event occurs, when it is necessary to redraw object. onDraw event is usually managed by skin.

Event Payload:

  • sender Object

    Object which caused this event.

  • canvas Canvas

    Canvas object enabling drawing to the TextView.

onKeyPressed

This event is raised by press the key.

Event Payload:

  • sender Object

    Object which caused this event.

  • key Symbol

    Pressed key.

    • #leftSoftKey
    • #rightSoftKey
    • #home
    • #back
    • #send
    • #end
    • #num0 - #num9
    • #star - the * key
    • #hash - the # key
    • #up
    • #down
    • #left
    • #right
    • #ok
    • #volumeUp
    • #volumeDown
    • #power
    • #camera

onKeyReleased

This event is raised by release the key.

Event Payload:

  • sender Object

    Object which caused this event.

  • key Symbol

    Pressed key.

    • #leftSoftKey
    • #rightSoftKey
    • #home
    • #back
    • #send
    • #end
    • #num0 - #num9
    • #star - the * key
    • #hash - the # key
    • #up
    • #down
    • #left
    • #right
    • #ok
    • #volumeUp
    • #volumeDown
    • #power
    • #camera

onParentScroll

Called when this view is scrolled (only when is owned by ScrollView).

Event Payload:

  • sender Object

    Object which caused this event.

  • parent ScrollView

    Parent object.

onPointerDragged

Called when touch (click) is moved.

Event Payload:

  • sender Object

    Object which caused this event.

  • x Integer

    X coordinates of pointer.

  • y Integer

    Y coordinates of pointer.

onPointerPressed

Called when touch (click) is stared.

Event Payload:

  • sender Object

    Object which caused this event.

  • x Integer

    X coordinates of pointer.

  • y Integer

    Y coordinates of pointer.

onPointerReleased

Called when touch (click) is finished.

Event Payload:

  • sender Object

    Object which caused this event.

  • x Integer

    X coordinates of pointer.

  • y Integer

    Y coordinates of pointer.

onProcess

Callback function, which is which is called from the object every 25ms.

onResize

Occurs when the control is resized.

Event Payload:

  • sender Object

    Object which caused this event.

  • width Integer

    New width of resized view.

  • height Integer

    New height of resized view.