Inputtext(LzInputText)

出自OpenFace

跳转到: 导航, 搜索

目录

<inputtext>

The basic input-text element.

JavaScript: LzInputText


Extends Text This tag creates an area of the canvas that the user can use to edit text.

See the documentation for the <text> tag for a description of the width and height attributes, and of scrolling.

Single-line input text

With the multiline and password attributes set to false (the default). In this use, long lines of text are clipped according to the width attribute.

Example 1. Simple inputtext

<canvas height="20">
 <inputtext width="150">This text is editable.</inputtext>
</canvas>

Multi-line input text

With the multiline attribute set to true. In this use, text is wrapped to the length of the width attribute, and the user can press Enter to create multiple lines of input.

Example 2. Simple inputtext

 <canvas height="80">
   <inputtext width="50" multiline="true" fontsize="16">This text is editable.</inputtext>
 </canvas>

Passwords

With password set to true. Input characters are displayed as the asterisk ('*') character.

Example 3. Password inputtext

<canvas height="20">
 <inputtext width="100" password="true">password.</inputtext>
</canvas>

Optimizing inputtext

A large <inputtext> view will respond to character input slowly. In many cases, it will not be able to keep up with reasonable typing speed, even on a fast machine.

If an instance of <inputtext> will not be resized at runtime, and the compiler can determine its size at compile time, the compiler can substitute a <inputtext> view that is optimized to accept text at that size for the generic resizable <inputtext> view. This optimized <inputtext> view can keep up with typing speed even at large sizes or on a slow computer.

A program can request an optimized <inputtext> by setting the resizable attribute to false, and supplying recognizable width and height dimension attributes. A recognizable dimension attribute is an attribute that is defined as a numeric literal, such as width="100", or that is defined as a simple $once expression that adds or subtracts a numeric literal to the width or height attribute of the view's parent, its parent's parent, or so on. This final optimization allows the optimization to apply to <inputtext> tags within a class definition, as in the second example below.

Example 4. Optimized inputtext

<canvas height="20">
 <inputtext resizable="false" width="150" height="20">
   This text is editable.
 </inputtext>
</canvas>


Example 5. Component with optimized inputtext

<canvas height="20">
<class name="mytext" width="150" height="20" extends="text">
  <attribute name="text" type="text"/>
  <inputtext resizable="false" text="${parent.text}" bgcolor="green"
    x="1" y="1" width="$once{parent.width-2}" height="$once{parent.height-2}"/>
</class>
<mytext fontsize="16">This text is editable.</mytext>
</canvas>


The compiler can also infer the values of the width and height attributes if they are not supplied. If supplied, the value of the font must be a constant string in order for the text field to be optimized. If supplied, the value of the fontsize must be a constant in order to for the text field to be optimized. Generally these can be omitted and the inputtext will inherit the parent's font size and style by default.

Attributes

Name    Usage    Type(Tag)    Type(JS)    Default    Category

password  Tag & JS   boolean     Boolean    false     setter

      If true, the input text field acts like a password input field; any text typed in appears as "****" characters in the current font.



resizable  Tag & JS   boolean     Boolean           setter



Attributes inherited from Node

id, name, parent, subnodes

Attributes inherited from Text

maxlength, multiline, resize, text

Attributes inherited from View

align,bgcolor,clip,cloneManager,datapath,enabled,fgcolor,focusable,fontsize,frame,hassetheight,hassetwidth,height,ignorelayout,ignorex,ignorey, opacity,resource,resourceheight,resourcewidth,rotation,source,totalframes,valign,visible,width,x,y



Methods

setEnabled()

LzInputText.setEnabled(enabled) Sets whether user can modify input text field

Parameters Name Type Desc enabled Boolean true if the text field can be edited


setText()

LzInputText.setText(t) setText sets the text of the field to display

Parameters Name Type Desc t String the string to which to set the text


Methods inherited from LzNode

getAttribute, setAttribute,applyConstraint

Methods inherited from LzText

addText, clearText, escapeText, getText, getTextHeight, getTextWidth, setColor, setMultiline, setResize, setText

Methods inherited from LzView

destroy, getAbsoluteX, getAbsoluteY, getBGColor, getColor, getHeight, getResource, getRotation, getSource, getTotalFrames, getWidth, getX, getY, init, sendBehind, sendInFrontOf, setAlign, setBGColor, setColor, setHeight, setOpacity, setResource, setResourceNumber, setRotation, setSource, setValign, setVisible, setWidth, setX, setY, stretchResource


Events

Name             Description

ontext            None


Events inherited from LzNode

ondata, oninit

Events inherited from LzText

ontext

Events inherited from LzView

onenabled,onerror, onfocus, onwidth, onheight, onopacity, onvisible, onwidth, onx, ony, onpathready, oncloneend, onclonenumber