Class: MultiLineText

Ycc.UI. MultiLineText

new Ycc.UI.MultiLineText(option)

多行文本UI
Name Type Description
option object 所有可配置的配置项
Name Type Default Description
content string "" 内容
color string black 颜色
rect Ycc.Math.Rect 文字的绘制区域。若超出长度,此区域会被修改
wordBreak string break-all 水平方向文字超出换行
`break-all` 超出即换行
`break-word` 在单词处换行
`no-break` 不换行,超出即隐藏
默认为`no-break`
overflow string auto 垂直方向超出rect之后的显示方式
`hidden` -- 直接隐藏
`auto` -- 修改rect大小,完全显示

Extends

Members

anchorXnumber

UI对象的锚点坐标。相对坐标。相对于rect的x 锚点坐标主要用于图形的旋转、平移、缩放

anchorYnumber

UI对象的锚点坐标。相对坐标。相对于rect的y 锚点坐标主要用于图形的旋转、平移、缩放

baseUIYcc.UI

基础绘图UI

belongToYcc.Layer

UI所属的图层

ctxnull

绘图环境

ctxCachenull

缓存的绘图环境

disableTypeObject

被禁用的事件类型。key为type,val为boolean

displayLinesArray.<string>

显示在文本框中的文本行。私有属性,不允许修改。

dpinumber

设备像素比

fillStylestring

填充颜色

ghostboolean

是否幽灵状态,默认false 幽灵状态的UI:只能用于显示,不可点击,事件也不会触发,其子元素的事件也不会触发,不能通过getUIFromPointer获取 用于解决多个UI重叠时是否需要穿透,以点击被覆盖UI的问题

idnumber

UI的唯一ID

isShowRotateBeforeUIboolean

是否显示缩放之前的位置

lineWidthnumber

线条宽度

listenersObject

所有的监听器。key为type,val为listener数组。

namestring

UI实例的名字

onclickfunction

点击 的监听。默认为null

oncomputeendfunction

计算属性后的hook

oncomputestartfunction

计算属性前的hook

ondragendfunction

拖拽结束 的监听。默认为null

ondraggingfunction

拖拽 的监听。默认为null

ondragstartfunction

拖拽开始 的监听。默认为null

onmousedownfunction

鼠标按下 的监听。默认为null

onmousemovefunction

鼠标移动 的监听。默认为null

onmouseoutfunction

鼠标移出 的监听。默认为null

onmouseoverfunction

鼠标移入 的监听。默认为null

onmouseupfunction

鼠标抬起 的监听。默认为null

onrenderendfunction

渲染后的hook

onrenderstartfunction

渲染前的hook

ontapfunction

点击事件 的监听。默认为null

ontouchendfunction

触摸结束 的监听。默认为null

ontouchmovefunction

触摸移动 的监听。默认为null

ontouchstartfunction

触摸开始 的监听。默认为null

opacitynumber

透明度
UI的绘图区域

rectBgColorstring

容纳区的背景色

rectBorderColorstring

容纳区边框颜色

rectBorderWidthnumber

容纳区的边框宽度

rotationnumber

相对于锚点的旋转角度

showboolean

是否显示

stopAllEventboolean

只会阻止当前UI事件的触发,不会阻止其下面子元素事件的触发

stopEventBubbleUpboolean

默认情况下,UI阻止事件冒泡,但不会阻止事件传播给图层

stopTypeObject

被阻止的事件类型。key为type,val为boolean

strokeStylestring

线条颜色

userDatanull

用户自定义的数据

xnumber

x相对父级的位置

ynumber

y相对父级的位置

yccClass

构造器的引用,Ycc中的每个类都有此属性

Methods

添加子ui
Name Type Description
ui
Returns:
Type Description
Ycc.UI.Base

inherited addListener(type, listener)

添加某个类型的监听器
Name Type Description
type string
listener function
克隆ui
Returns:
Type Description
Ycc.UI
计算UI的各种属性。此操作必须在绘制之前调用。
计算与绘制分离的好处是,在绘制UI之前就可以提前确定元素的各种信息,从而判断是否需要绘制。

inherited containDot(dot){boolean}

判断某个点是否在UI组件内 默认根据ui的容纳区rect字段进行判断,子UI可以覆盖此方法
Name Type Description
dot Ycc.Math.Dot 某个点的绝对坐标
Returns:
Type Description
boolean
禁止某个事件触发
Name Type Description
type
合并参数,只会合并对象中已存在的key
Name Type Description
option
Returns:
Type Description
Ycc.UI
获取UI的绝对坐标,主要考虑图层坐标 注:此区域未经过旋转
Returns:
Type Description
Ycc.Math.Rect

inherited getAbsolutePositionPolygon()

获取UI平移、旋转之后位置的多边形区域,子UI需覆盖此方法
获取容纳UI的矩形区域,子UI可以覆盖此方法 注:此区域未经过旋转
Returns:
Type Description
Ycc.Math.Rect
获取当前UI在树结构中的深度

inherited getMaxContentInWidth(content, width){string}

给定宽度,获取能容纳的最长单行字符串
Name Type Description
content string 文本内容
width number 指定宽度
Returns:
Type Description
string
在某个图层中初始化UI
Name Type Description
layer Layer 图层
判断当前区域在某个区域外
Name Type Description
rect Ycc.Math.Rect

inherited isOutOfStage(){boolean}

判断ui是否存在于舞台之外,渲染时可以不予渲染 在compute之后使用,判断更准确
Returns:
Type Description
boolean
删除子ui
Name Type Description
ui

inherited removeListener(type, listener)

移除某个类型的监听器
Name Type Description
type
listener
删除自身。 若子类包含多个UI,需要重载
渲染至ctx
Name Type Description
ctx

inherited renderDashBeforeUI(ctx)

绘制UI平移、旋转之前的位置,用虚线绘制 需要子UI重载
Name Type Description
ctx optional 绘图环境,非必传

inherited renderRectBgColor(absoluteRect)

渲染容纳区rect的背景色
开启离屏canvas后,此过程只会发生在离屏canvas中
Name Type Description
absoluteRect Ycc.Math.Rect 容纳区的绝对位置

inherited renderRectBorder(absoluteRect)

渲染容纳区rect的边框
开启离屏canvas后,此过程只会发生在离屏canvas中
Name Type Description
absoluteRect Ycc.Math.Rect 容纳区的绝对位置
恢复某个事件的触发
Name Type Description
type
坐标系的缩放和旋转。 先缩放、再旋转。
TODO
  • 子类渲染前需要调用此方法
  • 多边形替换rect后,此方法废弃,不再调用
阻止某个事件类型继续传递
Name Type Description
type
根据当前的锚点、旋转角度获取某个点的转换之后的坐标
Name Type Description
dot Ycc.Math.Dot | Array.<Ycc.Math.Dot> 需要转换的点,该点为相对坐标,相对于当前UI的父级
Returns:
Type Description
Ycc.Math.Dot 转换后的点,该点为绝对坐标

inherited transformToAbsolute(dotOrArr){Ycc.Math.Dot|Array.<Ycc.Math.Dot>}

根据图层坐标和UI位置坐标,将某个点的相对坐标(相对于UI的父级),转换为舞台的绝对坐标
Name Type Description
dotOrArr Ycc.Math.Dot | Array.<Ycc.Math.Dot>
Returns:
Type Description
Ycc.Math.Dot | Array.<Ycc.Math.Dot>

inherited transformToLocal(dotOrArr){Ycc.Math.Dot|Array.<Ycc.Math.Dot>}

根据图层坐标和UI位置坐标,将某个点的绝对坐标,转换为相对于UI父级的相对坐标
Name Type Description
dotOrArr Ycc.Math.Dot | Array.<Ycc.Math.Dot>
Returns:
Type Description
Ycc.Math.Dot | Array.<Ycc.Math.Dot>

inherited triggerListener(type, data)

触发某一类型的监听器
Name Type Description
type
data

inherited triggerUIEventBubbleUp(type, x, y, originEvent){Array.<Ycc.UI>}

冒泡触发UI的事件
Name Type Description
type
x
y
originEvent ycc事件所对应的原始事件
Returns:
Type Description
Array.<Ycc.UI> 返回已触发事件的UI列表