View Class
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);
Item Index
Methods
Methods
this
[name]
Create new object.
Parameters:
-
[name]
String optionalName of the object. Pass null for unnamed view
Returns:
add
view
[order]
Function adds existing view object into ScrollView.
Parameters:
-
view
ViewView to add. View/ScrollView/TextView are supported.
-
[order]
Symbol optionalDefault is.
* #front * #back
Returns:
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
Search for child view, which name is same as name from function's param.
Parameters:
-
name
StringName of the child view to search
Returns:
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:
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:
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:
resumeDrawing
() Window
Resume view's drawing.
Returns:
resumeDrawing
() Window
Resume view's drawing.
Returns:
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();
suspendDrawing
() Window chainable
Suspends the drawing of this view.
Returns:
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:
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
stretch
Symbol
Gets or sets if the view's width is stretchable.
- #both
Events
onChar
This event is raised by release an UNICODE character key.
Event Payload:
-
sender
ObjectObject which caused this event.
-
key
IntegerCode from unicode table.
onDraw
This event occurs, when it is necessary to redraw object. onDraw event is usually managed by skin.
Event Payload:
-
sender
ObjectObject which caused this event.
-
canvas
CanvasCanvas object enabling drawing to the TextView.
onKeyPressed
This event is raised by press the key.
Event Payload:
-
sender
ObjectObject which caused this event.
-
key
SymbolPressed 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
ObjectObject which caused this event.
-
key
SymbolPressed 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
ObjectObject which caused this event.
-
parent
ScrollViewParent object.
onPointerDragged
Called when touch (click) is moved.
onPointerPressed
Called when touch (click) is stared.
onPointerReleased
Called when touch (click) is finished.
onProcess
Callback function, which is which is called from the object every 25ms.