add compEventType in component (#5894)

This commit is contained in:
JoneLau
2019-12-19 15:00:11 +08:00
committed by pandamicro
parent 86636442cf
commit dfd752b8ce
13 changed files with 413 additions and 348 deletions
+21 -16
View File
@@ -78,6 +78,10 @@ enum State {
DISABLED = 'disabled',
}
export enum EventType {
CLICK = 'click',
}
/**
* @zh
* 按钮组件。可以被按下,或者点击。<br/>
@@ -416,6 +420,7 @@ export class ButtonComponent extends Component {
}
public static Transition = Transition;
public static EventType = EventType;
/**
* @zh
* 按钮的点击事件列表。
@@ -427,31 +432,31 @@ export class ButtonComponent extends Component {
})
public clickEvents: ComponentEventHandler[] = [];
@property
private _interactable = true;
protected _interactable = true;
@property
private _transition = Transition.NONE;
protected _transition = Transition.NONE;
@property
private _normalColor: Color = new Color(214, 214, 214, 255);
protected _normalColor: Color = new Color(214, 214, 214, 255);
@property
private _hoverColor: Color = new Color(211, 211, 211, 255);
protected _hoverColor: Color = new Color(211, 211, 211, 255);
@property
private _pressColor: Color = Color.WHITE.clone();
protected _pressColor: Color = Color.WHITE.clone();
@property
private _disabledColor: Color = new Color(124, 124, 124, 255);
protected _disabledColor: Color = new Color(124, 124, 124, 255);
@property
private _normalSprite: SpriteFrame | null = null;
protected _normalSprite: SpriteFrame | null = null;
@property
private _hoverSprite: SpriteFrame | null = null;
protected _hoverSprite: SpriteFrame | null = null;
@property
private _pressedSprite: SpriteFrame | null = null;
protected _pressedSprite: SpriteFrame | null = null;
@property
private _disabledSprite: SpriteFrame | null = null;
protected _disabledSprite: SpriteFrame | null = null;
@property
private _duration = 0.1;
protected _duration = 0.1;
@property
private _zoomScale = 1.2;
protected _zoomScale = 1.2;
@property
private _target: Node | null = null;
protected _target: Node | null = null;
private _pressed = false;
private _hovered = false;
private _fromColor: Color = new Color();
@@ -484,7 +489,7 @@ export class ButtonComponent extends Component {
if (!CC_EDITOR) {
this._registerEvent();
} else {
this.node.on('spriteframe-changed', (comp: SpriteComponent) => {
this.node.on(SpriteComponent.EventType.SPRITE_FRAME_CHANGED, (comp: SpriteComponent) => {
if (this._transition === Transition.SPRITE) {
this._normalSprite = comp.spriteFrame;
} else {
@@ -510,7 +515,7 @@ export class ButtonComponent extends Component {
this.node.off(SystemEventType.MOUSE_ENTER, this._onMouseMoveIn, this);
this.node.off(SystemEventType.MOUSE_LEAVE, this._onMouseMoveOut, this);
} else {
this.node.off('spriteframe-changed');
this.node.off(SpriteComponent.EventType.SPRITE_FRAME_CHANGED);
}
}
@@ -663,7 +668,7 @@ export class ButtonComponent extends Component {
if (this._pressed) {
ComponentEventHandler.emitEvents(this.clickEvents, event);
this.node.emit('click', this);
this.node.emit(EventType.CLICK, this);
}
this._pressed = false;
this._updateState();
+26 -26
View File
@@ -580,48 +580,48 @@ export class LabelComponent extends UIRenderComponent {
public static CanvasPool = new CanvasPool();
@property
private _useOriginalSize = true;
protected _useOriginalSize = true;
@property
private _string = 'label';
protected _string = 'label';
@property
private _horizontalAlign = HorizontalTextAlignment.CENTER;
protected _horizontalAlign = HorizontalTextAlignment.CENTER;
@property
private _verticalAlign = VerticalTextAlignment.CENTER;
protected _verticalAlign = VerticalTextAlignment.CENTER;
@property
private _actualFontSize = 0;
protected _actualFontSize = 0;
@property
private _fontSize = 40;
protected _fontSize = 40;
@property
private _fontFamily = 'Arial';
protected _fontFamily = 'Arial';
@property
private _lineHeight = 40;
protected _lineHeight = 40;
@property
private _overflow: Overflow = Overflow.NONE;
protected _overflow: Overflow = Overflow.NONE;
@property
private _enableWrapText = true;
protected _enableWrapText = true;
@property
private _font: Font | null = null;
protected _font: Font | null = null;
@property
private _isSystemFontUsed = true;
private _spacingX = 0;
protected _isSystemFontUsed = true;
protected _spacingX = 0;
@property
private _isItalic = false;
protected _isItalic = false;
@property
private _isBold = false;
protected _isBold = false;
@property
private _isUnderline = false;
protected _isUnderline = false;
@property
private _cacheMode = CacheMode.NONE;
protected _cacheMode = CacheMode.NONE;
// don't need serialize
// 这个保存了旧项目的 file 数据
private _N$file: Font | null = null;
private _texture: SpriteFrame | LetterRenderTexture | null = null;
private _ttfSpriteFrame: SpriteFrame | null = null;
private _userDefinedFont: Font | null = null;
private _assemblerData: ISharedLabelData | null = null;
private _fontAtlas: FontAtlas | null = null;
private _letterTexture: LetterRenderTexture | null = null;
protected _N$file: Font | null = null;
protected _texture: SpriteFrame | LetterRenderTexture | null = null;
protected _ttfSpriteFrame: SpriteFrame | null = null;
protected _userDefinedFont: Font | null = null;
protected _assemblerData: ISharedLabelData | null = null;
protected _fontAtlas: FontAtlas | null = null;
protected _letterTexture: LetterRenderTexture | null = null;
constructor () {
super();
@@ -731,7 +731,7 @@ export class LabelComponent extends UIRenderComponent {
}
}
private _flushMaterial () {
protected _flushMaterial () {
const material = this._material;
// Setup blend function for premultiplied ttf label texture
// if (this._texture === this._ttfSpriteFrame) {
@@ -747,7 +747,7 @@ export class LabelComponent extends UIRenderComponent {
this._updateMaterial(material);
}
private _applyFontTexture (force: boolean) {
protected _applyFontTexture (force: boolean) {
const font = this._font;
if (font instanceof BitmapFont) {
const spriteFrame = font.spriteFrame;
@@ -53,9 +53,9 @@ import { LabelComponent } from './label-component';
@menu('UI/Render/LabelOutline')
export class LabelOutlineComponent extends Component {
@property
private _color = new Color(255, 255, 255, 255);
protected _color = new Color(255, 255, 255, 255);
@property
private _width = 1;
protected _width = 1;
/**
* @zh
@@ -108,7 +108,7 @@ export class LabelOutlineComponent extends Component {
this._updateRenderData();
}
private _updateRenderData () {
protected _updateRenderData () {
const label = this.node.getComponent(LabelComponent);
if (label) {
label.updateRenderData(true);
+24 -24
View File
@@ -493,9 +493,9 @@ export class LayoutComponent extends Component {
@property
protected _affectedByScale = false;
private _layoutSize = new Size(300, 200);
private _layoutDirty = true;
private _isAlign = false;
protected _layoutSize = new Size(300, 200);
protected _layoutDirty = true;
protected _isAlign = false;
/**
* @zh
@@ -535,7 +535,7 @@ export class LayoutComponent extends Component {
this._removeEventListeners();
}
private _migratePaddingData () {
protected _migratePaddingData () {
this._paddingLeft = this._N$padding;
this._paddingRight = this._N$padding;
this._paddingTop = this._N$padding;
@@ -543,7 +543,7 @@ export class LayoutComponent extends Component {
this._N$padding = 0;
}
private _addEventListeners () {
protected _addEventListeners () {
director.on(Director.EVENT_AFTER_UPDATE, this.updateLayout, this);
this.node.on(NodeEvent.SIZE_CHANGED, this._resized, this);
this.node.on(NodeEvent.ANCHOR_CHANGED, this._doLayoutDirty, this);
@@ -553,7 +553,7 @@ export class LayoutComponent extends Component {
this._addChildrenEventListeners();
}
private _removeEventListeners () {
protected _removeEventListeners () {
director.off(Director.EVENT_AFTER_UPDATE, this.updateLayout, this);
this.node.off(NodeEvent.SIZE_CHANGED, this._resized, this);
this.node.off(NodeEvent.ANCHOR_CHANGED, this._doLayoutDirty, this);
@@ -563,7 +563,7 @@ export class LayoutComponent extends Component {
this._removeChildrenEventListeners();
}
private _addChildrenEventListeners () {
protected _addChildrenEventListeners () {
const children = this.node.children;
for (const child of children) {
child.on(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this);
@@ -574,7 +574,7 @@ export class LayoutComponent extends Component {
}
}
private _removeChildrenEventListeners () {
protected _removeChildrenEventListeners () {
const children = this.node.children;
for (const child of children) {
child.off(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this);
@@ -585,7 +585,7 @@ export class LayoutComponent extends Component {
}
}
private _childAdded (child: Node) {
protected _childAdded (child: Node) {
child.on(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this);
child.on(NodeEvent.SIZE_CHANGED, this._doLayoutDirty, this);
child.on(NodeEvent.TRANSFORM_CHANGED, this._transformDirty, this);
@@ -595,7 +595,7 @@ export class LayoutComponent extends Component {
this._doLayoutDirty();
}
private _childRemoved (child: Node) {
protected _childRemoved (child: Node) {
child.off(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this);
child.off(NodeEvent.SIZE_CHANGED, this._doLayoutDirty, this);
child.off(NodeEvent.TRANSFORM_CHANGED, this._transformDirty, this);
@@ -605,12 +605,12 @@ export class LayoutComponent extends Component {
this._doLayoutDirty();
}
private _resized () {
protected _resized () {
this._layoutSize = this.node.getContentSize();
this._doLayoutDirty();
}
private _doLayoutHorizontally (baseWidth: number, rowBreak: boolean, fnPositionY: Function, applyChildren: boolean) {
protected _doLayoutHorizontally (baseWidth: number, rowBreak: boolean, fnPositionY: Function, applyChildren: boolean) {
const layoutAnchor = this.node.getAnchorPoint();
const children = this.node.children;
@@ -744,7 +744,7 @@ export class LayoutComponent extends Component {
return containerResizeBoundary;
}
private _doLayoutVertically (
protected _doLayoutVertically (
baseHeight: number,
columnBreak: boolean,
fnPositionX: Function,
@@ -886,7 +886,7 @@ export class LayoutComponent extends Component {
return containerResizeBoundary;
}
private _doLayoutBasic () {
protected _doLayoutBasic () {
const children = this.node.children;
let allChildrenBoundingBox: Rect | null = null;
@@ -940,7 +940,7 @@ export class LayoutComponent extends Component {
}
}
private _doLayoutGridAxisHorizontal (layoutAnchor, layoutSize) {
protected _doLayoutGridAxisHorizontal (layoutAnchor, layoutSize) {
const baseWidth = layoutSize.width;
let sign = 1;
@@ -983,7 +983,7 @@ export class LayoutComponent extends Component {
}
}
private _doLayoutGridAxisVertical (layoutAnchor: Vec2, layoutSize: Size) {
protected _doLayoutGridAxisVertical (layoutAnchor: Vec2, layoutSize: Size) {
const baseHeight = layoutSize.height;
let sign = 1;
@@ -1024,7 +1024,7 @@ export class LayoutComponent extends Component {
}
}
private _doLayoutGrid () {
protected _doLayoutGrid () {
const layoutAnchor = this.node.getAnchorPoint();
const layoutSize = this.node.getContentSize();
@@ -1037,7 +1037,7 @@ export class LayoutComponent extends Component {
}
private _getHorizontalBaseWidth (children: Readonly<Node[]>) {
protected _getHorizontalBaseWidth (children: Readonly<Node[]>) {
let newWidth = 0;
let activeChildCount = 0;
if (this._resizeMode === ResizeMode.CONTAINER) {
@@ -1055,7 +1055,7 @@ export class LayoutComponent extends Component {
return newWidth;
}
private _getVerticalBaseHeight (children: Readonly<Node[]>) {
protected _getVerticalBaseHeight (children: Readonly<Node[]>) {
let newHeight = 0;
let activeChildCount = 0;
if (this._resizeMode === ResizeMode.CONTAINER) {
@@ -1074,7 +1074,7 @@ export class LayoutComponent extends Component {
return newHeight;
}
private _doLayout () {
protected _doLayout () {
if (this._N$layoutType === Type.HORIZONTAL) {
const newWidth = this._getHorizontalBaseWidth(this.node.children);
@@ -1107,11 +1107,11 @@ export class LayoutComponent extends Component {
}
}
private _getUsedScaleValue (value) {
protected _getUsedScaleValue (value) {
return this._affectedByScale ? Math.abs(value) : 1;
}
private _transformDirty (type: TransformBit) {
protected _transformDirty (type: TransformBit) {
if (!(type & TransformBit.POSITION)){
return;
}
@@ -1119,11 +1119,11 @@ export class LayoutComponent extends Component {
this._doLayoutDirty();
}
private _doLayoutDirty () {
protected _doLayoutDirty () {
this._layoutDirty = true;
}
private _doScaleDirty (type: TransformBit) {
protected _doScaleDirty (type: TransformBit) {
if (type & TransformBit.SCALE){
this._layoutDirty = this._layoutDirty || this._affectedByScale;
}
+27 -34
View File
@@ -37,6 +37,8 @@ import { PageViewIndicatorComponent } from './page-view-indicator-component';
import { ScrollViewComponent } from './scroll-view-component';
import { ScrollBarComponent } from './scroll-bar-component';
import { warnID } from '../../core/platform/debug';
import { extendsEnum } from '../../core/data/utils/extends-enum';
import { EventType as ScrollEventType } from './scroll-view-component';
import { Node } from '../../core';
const _temp_vec2 = new Vec2();
@@ -83,20 +85,11 @@ ccenum(Direction);
/**
* @en Enum for ScrollView event type.
* @zh 滚动视图事件类型
* @enum PageView.EventType
*/
enum PageViewEventType {
/**
* @en The page turning event
* @zh 翻页事件
* @property {Number} PAGE_TURNING
*/
PAGE_TURNING = 0,
enum EventType {
PAGE_TURING = 'page-turning',
}
ccenum(PageViewEventType);
/**
* @en The PageView control
* @zh 页面视图组件
@@ -221,7 +214,7 @@ export class PageViewComponent extends ScrollViewComponent {
public static SizeMode = SizeMode;
public static Direction = Direction;
public static EventType = PageViewEventType;
public static EventType = extendsEnum(EventType, ScrollEventType);
/**
* @en
@@ -311,14 +304,14 @@ export class PageViewComponent extends ScrollViewComponent {
@property
protected _indicator: PageViewIndicatorComponent | null = null;
private _curPageIdx = 0;
private _lastPageIdx = 0;
private _pages: Node[] = [];
private _initContentPos = new Vec3();
private _scrollCenterOffsetX: number[] = []; // 每一个页面居中时需要的偏移量(X)
private _scrollCenterOffsetY: number[] = []; // 每一个页面居中时需要的偏移量(Y)
private _touchBeganPosition = new Vec3();
private _touchEndPosition = new Vec3();
protected _curPageIdx = 0;
protected _lastPageIdx = 0;
protected _pages: Node[] = [];
protected _initContentPos = new Vec3();
protected _scrollCenterOffsetX: number[] = []; // 每一个页面居中时需要的偏移量(X)
protected _scrollCenterOffsetY: number[] = []; // 每一个页面居中时需要的偏移量(Y)
protected _touchBeganPosition = new Vec3();
protected _touchEndPosition = new Vec3();
public __preload() {
this.node.on(SystemEventType.SIZE_CHANGED, this._updateAllPagesSize, this);
@@ -327,14 +320,14 @@ export class PageViewComponent extends ScrollViewComponent {
public onEnable() {
super.onEnable();
if (!CC_EDITOR) {
this.node.on('scroll-ended-with-threshold', this._dispatchPageTurningEvent, this);
this.node.on(PageViewComponent.EventType.SCROLL_ENG_WITH_THRESHOLD, this._dispatchPageTurningEvent, this);
}
}
public onDisable() {
super.onDisable();
if (!CC_EDITOR) {
this.node.off('scroll-ended-with-threshold', this._dispatchPageTurningEvent, this);
this.node.off(PageViewComponent.EventType.SCROLL_ENG_WITH_THRESHOLD, this._dispatchPageTurningEvent, this);
}
}
@@ -532,7 +525,7 @@ export class PageViewComponent extends ScrollViewComponent {
if (this._scrolling) {
this._scrolling = false;
if (!this._autoScrolling) {
this._dispatchEvent('scroll-ended');
this._dispatchEvent(PageViewComponent.EventType.SCROLL_ENDED);
}
}
}
@@ -561,12 +554,12 @@ export class PageViewComponent extends ScrollViewComponent {
protected _onMouseWheel() { }
private _syncScrollDirection() {
protected _syncScrollDirection() {
this.horizontal = this.direction === Direction.Horizontal;
this.vertical = this.direction === Direction.Vertical;
}
private _syncSizeMode() {
protected _syncSizeMode() {
const view = this.view;
if (!this.content || !view) { return; }
const layout = this.content.getComponent(LayoutComponent);
@@ -588,7 +581,7 @@ export class PageViewComponent extends ScrollViewComponent {
}
// 初始化页面
private _initPages() {
protected _initPages() {
if (!this.content) { return; }
this._initContentPos = this.content.position;
const children = this.content.children;
@@ -602,15 +595,15 @@ export class PageViewComponent extends ScrollViewComponent {
this._updatePageView();
}
private _dispatchPageTurningEvent() {
protected _dispatchPageTurningEvent() {
if (this._lastPageIdx === this._curPageIdx) { return; }
this._lastPageIdx = this._curPageIdx;
ComponentEventHandler.emitEvents(this.pageEvents, this, PageViewEventType.PAGE_TURNING);
this.node.emit('page-turning', this);
ComponentEventHandler.emitEvents(this.pageEvents, this);
this.node.emit(EventType.PAGE_TURING, this);
}
// 快速滑动
private _isQuicklyScrollable(touchMoveVelocity: Vec3) {
protected _isQuicklyScrollable(touchMoveVelocity: Vec3) {
if (this.direction === Direction.Horizontal) {
if (Math.abs(touchMoveVelocity.x) > this.autoPageTurningThreshold) {
return true;
@@ -625,7 +618,7 @@ export class PageViewComponent extends ScrollViewComponent {
}
// 通过 idx 获取偏移值数值
private _moveOffsetValue(idx: number) {
protected _moveOffsetValue(idx: number) {
const offset = new Vec3();
if (this._sizeMode === SizeMode.Free) {
if (this.direction === Direction.Horizontal) {
@@ -650,7 +643,7 @@ export class PageViewComponent extends ScrollViewComponent {
return offset;
}
private _getDragDirection(moveOffset: Vec3) {
protected _getDragDirection(moveOffset: Vec3) {
if (this._direction === Direction.Horizontal) {
if (moveOffset.x === 0) {
return 0;
@@ -669,7 +662,7 @@ export class PageViewComponent extends ScrollViewComponent {
}
// 是否超过自动滚动临界值
private _isScrollable(offset: Vec3, index: number, nextIndex: number) {
protected _isScrollable(offset: Vec3, index: number, nextIndex: number) {
if (this._sizeMode === SizeMode.Free) {
let curPageCenter = 0;
let nextPageCenter = 0;
@@ -698,7 +691,7 @@ export class PageViewComponent extends ScrollViewComponent {
}
}
private _autoScrollToPage() {
protected _autoScrollToPage() {
const bounceBackStarted = this._startBounceBackIfNeeded();
// Note:
const moveOffset = new Vec3();
@@ -142,14 +142,14 @@ export class PageViewIndicatorComponent extends Component {
})
public spacing = 0;
@property
public _spriteFrame: SpriteFrame | null = null;
protected _spriteFrame: SpriteFrame | null = null;
@property
public _direction: Direction = Direction.HORIZONTAL;
protected _direction: Direction = Direction.HORIZONTAL;
@property
public _cellSize = new Size(20, 20);
private _layout: LayoutComponent | null = null;
private _pageView: PageViewComponent | null = null;
private _indicators: Node[] = [];
protected _cellSize = new Size(20, 20);
protected _layout: LayoutComponent | null = null;
protected _pageView: PageViewComponent | null = null;
protected _indicators: Node[] = [];
public onLoad () {
this._updateLayout();
@@ -207,17 +207,17 @@ export class ProgressBarComponent extends Component {
public static Mode = Mode;
@property
private _barSprite: SpriteComponent | null = null;
protected _barSprite: SpriteComponent | null = null;
@property
private _mode = Mode.HORIZONTAL;
protected _mode = Mode.HORIZONTAL;
@property
private _totalLength = 1;
protected _totalLength = 1;
@property
private _progress = 0.1;
protected _progress = 0.1;
@property
private _reverse = false;
protected _reverse = false;
private _initBarSprite () {
protected _initBarSprite () {
if (this._barSprite) {
const entity = this._barSprite.node;
if (!entity) { return; }
@@ -250,7 +250,7 @@ export class ProgressBarComponent extends Component {
}
}
private _updateBarStatus () {
protected _updateBarStatus () {
if (this._barSprite) {
const entity = this._barSprite.node;
+40 -40
View File
@@ -346,33 +346,33 @@ export class RichTextComponent extends UIComponent {
public static VerticalAlign = VerticalTextAlignment;
@property
private _lineHeight = 40;
protected _lineHeight = 40;
@property
private _string = '<color=#00ff00>Rich</c><color=#0fffff>Text</color>';
// private _updateRichTextStatus =
protected _string = '<color=#00ff00>Rich</c><color=#0fffff>Text</color>';
// protected _updateRichTextStatus =
@property
private _horizontalAlign = HorizontalTextAlignment.LEFT;
protected _horizontalAlign = HorizontalTextAlignment.LEFT;
@property
private _fontSize = 40;
protected _fontSize = 40;
@property
private _maxWidth = 0;
protected _maxWidth = 0;
@property
private _font: TTFFont | null = null;
protected _font: TTFFont | null = null;
@property
private _imageAtlas: SpriteAtlas | null = null;
protected _imageAtlas: SpriteAtlas | null = null;
@property
private _handleTouchEvent = true;
protected _handleTouchEvent = true;
private _textArray: IHtmlTextParserResultObj[] = [];
private _labelSegments: ILabelSegment[] = [];
private _labelSegmentsCache: ILabelSegment[] = [];
private _linesWidth: number[] = [];
private _lineCount = 1;
private _labelWidth = 0;
private _labelHeight = 0;
private _layoutDirty = true;
private _lineOffsetX = 0;
private _updateRichTextStatus: () => void;
protected _textArray: IHtmlTextParserResultObj[] = [];
protected _labelSegments: ILabelSegment[] = [];
protected _labelSegmentsCache: ILabelSegment[] = [];
protected _linesWidth: number[] = [];
protected _lineCount = 1;
protected _labelWidth = 0;
protected _labelHeight = 0;
protected _layoutDirty = true;
protected _lineOffsetX = 0;
protected _updateRichTextStatus: () => void;
constructor () {
super();
@@ -428,26 +428,26 @@ export class RichTextComponent extends UIComponent {
}
}
private _addEventListeners () {
protected _addEventListeners () {
this.node.on(Node.EventType.TOUCH_END, this._onTouchEnded, this);
}
private _removeEventListeners () {
protected _removeEventListeners () {
this.node.off(Node.EventType.TOUCH_END, this._onTouchEnded, this);
}
private _updateLabelSegmentTextAttributes () {
protected _updateLabelSegmentTextAttributes () {
this._labelSegments.forEach((item) => {
this._applyTextAttribute(item);
});
}
private _createFontLabel (str: string) {
protected _createFontLabel (str: string) {
// @ts-ignore
return pool.get!(str, this);
}
private _onTTFLoaded () {
protected _onTTFLoaded () {
if (this._font instanceof TTFFont) {
if (this._font._nativeAsset) {
this._layoutDirty = true;
@@ -467,7 +467,7 @@ export class RichTextComponent extends UIComponent {
}
}
private _measureText (styleIndex: number, string?: string) {
protected _measureText (styleIndex: number, string?: string) {
const self = this;
const func = (s: string) => {
let label: ILabelSegment;
@@ -492,7 +492,7 @@ export class RichTextComponent extends UIComponent {
}
}
private _onTouchEnded (event: EventTouch) {
protected _onTouchEnded (event: EventTouch) {
const components = this.node.getComponents(UIComponent);
const self = this;
@@ -510,7 +510,7 @@ export class RichTextComponent extends UIComponent {
}
}
private _containsTouchLocation (label: ILabelSegment, point: Vec2) {
protected _containsTouchLocation (label: ILabelSegment, point: Vec2) {
const comp = label.node.getComponent(UITransformComponent);
if (!comp) {
return false;
@@ -520,7 +520,7 @@ export class RichTextComponent extends UIComponent {
return myRect.contains(point);
}
private _resetState () {
protected _resetState () {
const children = this.node.children as Mutable<Node[]>;
for (let i = children.length - 1; i >= 0; i--) {
@@ -556,7 +556,7 @@ export class RichTextComponent extends UIComponent {
this._layoutDirty = true;
}
private _activateChildren (active) {
protected _activateChildren (active) {
for (let i = this.node.children.length - 1; i >= 0; i--) {
const child = this.node.children[i];
if (child.name === RichTextChildName || child.name === RichTextChildImageName) {
@@ -565,7 +565,7 @@ export class RichTextComponent extends UIComponent {
}
}
private _addLabelSegment (stringToken: string, styleIndex: number) {
protected _addLabelSegment (stringToken: string, styleIndex: number) {
let labelSegment: ILabelSegment;
if (this._labelSegmentsCache.length === 0) {
labelSegment = this._createFontLabel(stringToken);
@@ -588,7 +588,7 @@ export class RichTextComponent extends UIComponent {
return labelSegment;
}
private _updateRichTextWithMaxWidth (labelString: string, labelWidth: number, styleIndex: number) {
protected _updateRichTextWithMaxWidth (labelString: string, labelWidth: number, styleIndex: number) {
let fragmentWidth = labelWidth;
let labelSegment: ILabelSegment;
@@ -640,17 +640,17 @@ export class RichTextComponent extends UIComponent {
}
}
private _isLastComponentCR (stringToken) {
protected _isLastComponentCR (stringToken) {
return stringToken.length - 1 === stringToken.lastIndexOf('\n');
}
private _updateLineInfo () {
protected _updateLineInfo () {
this._linesWidth.push(this._lineOffsetX);
this._lineOffsetX = 0;
this._lineCount++;
}
private _needsUpdateTextLayout (newTextArray: IHtmlTextParserResultObj[]) {
protected _needsUpdateTextLayout (newTextArray: IHtmlTextParserResultObj[]) {
if (this._layoutDirty || !this._textArray || !newTextArray) {
return true;
}
@@ -700,7 +700,7 @@ export class RichTextComponent extends UIComponent {
return false;
}
private _addRichTextImageElement (richTextElement: IHtmlTextParserResultObj) {
protected _addRichTextImageElement (richTextElement: IHtmlTextParserResultObj) {
if (!richTextElement.style) {
return;
}
@@ -775,7 +775,7 @@ export class RichTextComponent extends UIComponent {
}
}
private _updateRichText () {
protected _updateRichText () {
if (!this.enabled) {
return;
}
@@ -866,7 +866,7 @@ export class RichTextComponent extends UIComponent {
this._layoutDirty = false;
}
private _getFirstWordLen (text: string, startIndex: number, textLen: number) {
protected _getFirstWordLen (text: string, startIndex: number, textLen: number) {
let character = text.charAt(startIndex);
if (isUnicodeCJK(character) || isUnicodeSpace(character)) {
return 1;
@@ -885,7 +885,7 @@ export class RichTextComponent extends UIComponent {
return len;
}
private _updateRichTextPosition () {
protected _updateRichTextPosition () {
let nextTokenX = 0;
let nextLineIndex = 1;
const totalLineCount = this._lineCount;
@@ -926,7 +926,7 @@ export class RichTextComponent extends UIComponent {
}
}
private _convertLiteralColorValue (color: string) {
protected _convertLiteralColorValue (color: string) {
const colorValue = color.toUpperCase();
if (Color[colorValue]) {
return Color[colorValue];
@@ -937,7 +937,7 @@ export class RichTextComponent extends UIComponent {
}
}
private _applyTextAttribute (labelSeg: ILabelSegment) {
protected _applyTextAttribute (labelSeg: ILabelSegment) {
const labelComponent = labelSeg.node.getComponent(LabelComponent);
if (!labelComponent) {
return;
+17 -17
View File
@@ -159,19 +159,19 @@ export class ScrollBarComponent extends Component {
public static Direction = Direction;
@property
private _scrollView: ScrollViewComponent | null = null;
protected _scrollView: ScrollViewComponent | null = null;
@property
private _handle: SpriteComponent | null = null;
protected _handle: SpriteComponent | null = null;
@property
private _direction = Direction.HORIZONTAL;
protected _direction = Direction.HORIZONTAL;
@property
private _enableAutoHide = false;
protected _enableAutoHide = false;
@property
private _autoHideTime = 1.0;
protected _autoHideTime = 1.0;
private _touching = false;
private _opacity = 255;
private _autoHideRemainingTime = 0;
protected _touching = false;
protected _opacity = 255;
protected _autoHideRemainingTime = 0;
/**
* @zh
@@ -310,7 +310,7 @@ export class ScrollBarComponent extends Component {
this._processAutoHide(dt);
}
private _convertToScrollViewSpace (content: Node) {
protected _convertToScrollViewSpace (content: Node) {
if (!this._scrollView) {
return ZERO;
}
@@ -327,7 +327,7 @@ export class ScrollBarComponent extends Component {
return scrollViewSpacePos;
}
private _setOpacity (opacity: number) {
protected _setOpacity (opacity: number) {
if (this._handle) {
let renderComp = this.node.getComponent(SpriteComponent);
if (renderComp) {
@@ -345,7 +345,7 @@ export class ScrollBarComponent extends Component {
}
}
private _updateHandlerPosition (position: Vec3) {
protected _updateHandlerPosition (position: Vec3) {
if (this._handle) {
const oldPosition = this._fixupHandlerPosition();
@@ -353,7 +353,7 @@ export class ScrollBarComponent extends Component {
}
}
private _fixupHandlerPosition () {
protected _fixupHandlerPosition () {
const barSize = this.node.getContentSize();
const barAnchor = this.node.getAnchorPoint();
const handleSize = this.handle!.node.getContentSize();
@@ -376,7 +376,7 @@ export class ScrollBarComponent extends Component {
return fixupPosition;
}
private _conditionalDisableScrollBar (contentSize: Size, scrollViewSize: Size) {
protected _conditionalDisableScrollBar (contentSize: Size, scrollViewSize: Size) {
if (contentSize.width <= scrollViewSize.width && this._direction === Direction.HORIZONTAL) {
return true;
}
@@ -387,7 +387,7 @@ export class ScrollBarComponent extends Component {
return false;
}
private _calculateLength (contentMeasure: number, scrollViewMeasure: number, handleNodeMeasure: number, outOfBoundary: number) {
protected _calculateLength (contentMeasure: number, scrollViewMeasure: number, handleNodeMeasure: number, outOfBoundary: number) {
let denominatorValue = contentMeasure;
if (outOfBoundary) {
denominatorValue += (outOfBoundary > 0 ? outOfBoundary : -outOfBoundary) * GETTINGSHORTERFACTOR;
@@ -397,7 +397,7 @@ export class ScrollBarComponent extends Component {
return handleNodeMeasure * lengthRation;
}
private _calculatePosition (
protected _calculatePosition (
contentMeasure: number,
scrollViewMeasure: number,
handleNodeMeasure: number,
@@ -424,7 +424,7 @@ export class ScrollBarComponent extends Component {
}
}
private _updateLength (length: number) {
protected _updateLength (length: number) {
if (this._handle) {
const handleNode = this._handle.node;
const handleNodeSize = handleNode.getContentSize();
@@ -441,7 +441,7 @@ export class ScrollBarComponent extends Component {
}
}
private _processAutoHide (deltaTime: number) {
protected _processAutoHide (deltaTime: number) {
if (!this._enableAutoHide || this._autoHideRemainingTime <= 0) {
return;
} else if (this._touching) {
+211 -147
View File
@@ -59,96 +59,162 @@ const getTimeInMilliseconds = () => {
return currentTime.getMilliseconds();
};
/**
* @zh
* 滚动视图事件类型。
*/
enum ScrollViewEventType {
// /**
// * @zh
// * 滚动视图事件类型。
// */
// enum ScrollViewEventType {
// /**
// * @zh
// * 滚动视图滚动到顶部边界事件。
// */
// SCROLL_TO_TOP = 0,
// /**
// * @zh
// * 滚动视图滚动到底部边界事件。
// */
// SCROLL_TO_BOTTOM = 1,
// /**
// * @zh
// * 滚动视图滚动到左边界事件。
// */
// SCROLL_TO_LEFT = 2,
// /**
// * @zh
// * 滚动视图滚动到右边界事件。
// */
// SCROLL_TO_RIGHT = 3,
// /**
// * @zh
// * 滚动视图正在滚动时发出的事件。
// */
// SCROLLING = 4,
// /**
// * @zh
// * 滚动视图滚动到顶部边界并且开始回弹时发出的事件。
// */
// BOUNCE_TOP = 5,
// /**
// * @zh
// * 滚动视图滚动到底部边界并且开始回弹时发出的事件。
// */
// BOUNCE_BOTTOM = 6,
// /**
// * @zh
// * 滚动视图滚动到左边界并且开始回弹时发出的事件。
// */
// BOUNCE_LEFT = 7,
// /**
// * @zh
// * 滚动视图滚动到右边界并且开始回弹时发出的事件。
// */
// BOUNCE_RIGHT = 8,
// /**
// * @zh
// * 滚动视图滚动结束的时候发出的事件。
// */
// SCROLL_ENDED = 9,
// /**
// * @zh
// * 当用户松手的时候会发出一个事件。
// */
// TOUCH_UP = 10,
// /**
// * @zh
// * 滚动视图自动滚动快要结束的时候发出的事件。
// */
// AUTOSCROLL_ENDED_WITH_THRESHOLD = 11,
// /**
// * @zh
// * 滚动视图滚动开始时发出的事件。
// */
// SCROLL_BEGAN = 12,
// }
const eventMap = {
'scroll-to-top': 0,
'scroll-to-bottom': 1,
'scroll-to-left': 2,
'scroll-to-right': 3,
'scrolling': 4,
'bounce-bottom': 6,
'bounce-left': 7,
'bounce-right': 8,
'bounce-top': 5,
'scroll-ended': 9,
'touch-up': 10,
'scroll-ended-with-threshold': 11,
'scroll-began': 12,
};
export enum EventType {
/**
* @zh
* 滚动视图滚动到顶部边界事件。
*/
SCROLL_TO_TOP = 0,
SCROLL_TO_TOP = 'scroll-to-top',
/**
* @zh
* 滚动视图滚动到底部边界事件。
*/
SCROLL_TO_BOTTOM = 1,
SCROLL_TO_BOTTOM = 'scroll-to-bottom',
/**
* @zh
* 滚动视图滚动到左边界事件。
*/
SCROLL_TO_LEFT = 2,
SCROLL_TO_LEFT = 'scroll-to-left',
/**
* @zh
* 滚动视图滚动到右边界事件。
*/
SCROLL_TO_RIGHT = 3,
/**
* @zh
* 滚动视图正在滚动时发出的事件。
*/
SCROLLING = 4,
/**
* @zh
* 滚动视图滚动到顶部边界并且开始回弹时发出的事件。
*/
BOUNCE_TOP = 5,
/**
* @zh
* 滚动视图滚动到底部边界并且开始回弹时发出的事件。
*/
BOUNCE_BOTTOM = 6,
/**
* @zh
* 滚动视图滚动到左边界并且开始回弹时发出的事件。
*/
BOUNCE_LEFT = 7,
/**
* @zh
* 滚动视图滚动到右边界并且开始回弹时发出的事件。
*/
BOUNCE_RIGHT = 8,
/**
* @zh
* 滚动视图滚动结束的时候发出的事件。
*/
SCROLL_ENDED = 9,
/**
* @zh
* 当用户松手的时候会发出一个事件。
*/
TOUCH_UP = 10,
/**
* @zh
* 滚动视图自动滚动快要结束的时候发出的事件。
*/
AUTOSCROLL_ENDED_WITH_THRESHOLD = 11,
SCROLL_TO_RIGHT = 'scroll-to-right',
/**
* @zh
* 滚动视图滚动开始时发出的事件。
*/
SCROLL_BEGAN = 12,
SCROLL_BEGAN = 'scroll-began',
/**
* @zh
* 滚动视图滚动结束的时候发出的事件。
*/
SCROLL_ENDED = 'scroll-ended',
/**
* @zh
* 滚动视图滚动到顶部边界并且开始回弹时发出的事件。
*/
BOUNCE_TOP = 'bounce-top',
/**
* @zh
* 滚动视图滚动到底部边界并且开始回弹时发出的事件。
*/
BOUNCE_BOTTOM = 'bounce-bottom',
/**
* @zh
* 滚动视图滚动到左边界并且开始回弹时发出的事件。
*/
BOUNCE_LEFT = 'bounce-left',
/**
* @zh
* 滚动视图滚动到右边界并且开始回弹时发出的事件。
*/
BOUNCE_RIGHT = 'bounce-right',
/**
* @zh
* 滚动视图正在滚动时发出的事件。
*/
SCROLLING = 'scrolling',
/**
* @zh
* 滚动视图自动滚动快要结束的时候发出的事件。
*/
SCROLL_ENG_WITH_THRESHOLD = 'scroll-ended-with-threshold',
/**
* @zh
* 当用户松手的时候会发出一个事件。
*/
TOUCH_UP = 'touch-up',
}
ccenum(ScrollViewEventType);
const eventMap = {
'scroll-to-top': ScrollViewEventType.SCROLL_TO_TOP,
'scroll-to-bottom': ScrollViewEventType.SCROLL_TO_BOTTOM,
'scroll-to-left': ScrollViewEventType.SCROLL_TO_LEFT,
'scroll-to-right': ScrollViewEventType.SCROLL_TO_RIGHT,
'scrolling': ScrollViewEventType.SCROLLING,
'bounce-bottom': ScrollViewEventType.BOUNCE_BOTTOM,
'bounce-left': ScrollViewEventType.BOUNCE_LEFT,
'bounce-right': ScrollViewEventType.BOUNCE_RIGHT,
'bounce-top': ScrollViewEventType.BOUNCE_TOP,
'scroll-ended': ScrollViewEventType.SCROLL_ENDED,
'touch-up': ScrollViewEventType.TOUCH_UP,
'scroll-ended-with-threshold': ScrollViewEventType.AUTOSCROLL_ENDED_WITH_THRESHOLD,
'scroll-began': ScrollViewEventType.SCROLL_BEGAN,
};
/**
* @zh
* 滚动视图组件。
@@ -166,7 +232,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
*/
@property({
type: Node,
tooltip:'可滚动展示内容的节点',
tooltip: '可滚动展示内容的节点',
})
get content () {
return this._content;
@@ -186,7 +252,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
*/
@property({
type: ScrollBarComponent,
tooltip:'水平滚动的 ScrollBar',
tooltip: '水平滚动的 ScrollBar',
})
get horizontalScrollBar () {
return this._horizontalScrollBar;
@@ -212,7 +278,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
*/
@property({
type: ScrollBarComponent,
tooltip:'垂直滚动的 ScrollBar',
tooltip: '垂直滚动的 ScrollBar',
})
get verticalScrollBar () {
return this._verticalScrollBar;
@@ -239,13 +305,13 @@ export class ScrollViewComponent extends ViewGroupComponent {
return this._content.parent;
}
public static EventType = ScrollViewEventType;
public static EventType = EventType;
/**
* @zh
* 是否开启水平滚动。
*/
@property({
tooltip:'是否开启水平滚动',
tooltip: '是否开启水平滚动',
})
public horizontal = true;
@@ -254,7 +320,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
* 是否开启垂直滚动。
*/
@property({
tooltip:'是否开启垂直滚动',
tooltip: '是否开启垂直滚动',
})
public vertical = true;
@@ -263,7 +329,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
* 是否开启滚动惯性。
*/
@property({
tooltip:'是否开启滚动惯性',
tooltip: '是否开启滚动惯性',
})
public inertia = true;
@@ -273,7 +339,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
*/
@property({
range: [0, 1, 0.1],
tooltip:'开启惯性后,在用户停止触摸后滚动多快停止,0 表示永不停止,1 表示立刻停止',
tooltip: '开启惯性后,在用户停止触摸后滚动多快停止,0 表示永不停止,1 表示立刻停止',
})
public brake = 0.5;
@@ -282,7 +348,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
* 是否允许滚动内容超过边界,并在停止触摸后回弹。
*/
@property({
tooltip:'是否允许滚动内容超过边界,并在停止触摸后回弹',
tooltip: '是否允许滚动内容超过边界,并在停止触摸后回弹',
})
public elastic = true;
@@ -292,7 +358,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
*/
@property({
range: [0, 10],
tooltip:'回弹持续的时间,0 表示将立即反弹',
tooltip: '回弹持续的时间,0 表示将立即反弹',
})
public bounceDuration = 1;
@@ -302,7 +368,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
*/
@property({
type: [ComponentEventHandler],
tooltip:'滚动视图的事件回调函数',
tooltip: '滚动视图的事件回调函数',
})
public scrollEvents: ComponentEventHandler[] = [];
@@ -312,7 +378,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
* 注意,子节点上的 touchstart 事件仍然会触发,触点移动距离非常短的情况下 touchmove 和 touchend 也不会受影响。
*/
@property({
tooltip:'滚动行为是否会取消子节点上注册的触摸事件',
tooltip: '滚动行为是否会取消子节点上注册的触摸事件',
})
public cancelInnerEvents = true;
@@ -325,34 +391,34 @@ export class ScrollViewComponent extends ViewGroupComponent {
@property
protected _verticalScrollBar: ScrollBarComponent | null = null;
private _topBoundary = 0;
private _bottomBoundary = 0;
private _leftBoundary = 0;
private _rightBoundary = 0;
protected _topBoundary = 0;
protected _bottomBoundary = 0;
protected _leftBoundary = 0;
protected _rightBoundary = 0;
private _touchMoveDisplacements: Vec3[] = [];
private _touchMoveTimeDeltas: number[] = [];
private _touchMovePreviousTimestamp = 0;
private _touchMoved = false;
private _autoScrollAttenuate = false;
private _autoScrollStartPosition = new Vec3();
private _autoScrollTargetDelta = new Vec3();
private _autoScrollTotalTime = 0;
private _autoScrollAccumulatedTime = 0;
private _autoScrollCurrentlyOutOfBoundary = false;
private _autoScrollBraking = false;
private _autoScrollBrakingStartPosition = new Vec3();
protected _touchMoveDisplacements: Vec3[] = [];
protected _touchMoveTimeDeltas: number[] = [];
protected _touchMovePreviousTimestamp = 0;
protected _touchMoved = false;
protected _autoScrollAttenuate = false;
protected _autoScrollStartPosition = new Vec3();
protected _autoScrollTargetDelta = new Vec3();
protected _autoScrollTotalTime = 0;
protected _autoScrollAccumulatedTime = 0;
protected _autoScrollCurrentlyOutOfBoundary = false;
protected _autoScrollBraking = false;
protected _autoScrollBrakingStartPosition = new Vec3();
private _outOfBoundaryAmount = new Vec3();
private _outOfBoundaryAmountDirty = true;
private _stopMouseWheel = false;
private _mouseWheelEventElapsedTime = 0.0;
private _isScrollEndedWithThresholdEventFired = false;
protected _outOfBoundaryAmount = new Vec3();
protected _outOfBoundaryAmountDirty = true;
protected _stopMouseWheel = false;
protected _mouseWheelEventElapsedTime = 0.0;
protected _isScrollEndedWithThresholdEventFired = false;
// use bit wise operations to indicate the direction
private _scrollEventEmitMask = 0;
private _isBouncing = false;
private _contentPos = new Vec3();
private _deltaPos = new Vec3();
protected _scrollEventEmitMask = 0;
protected _isBouncing = false;
protected _contentPos = new Vec3();
protected _deltaPos = new Vec3();
/**
* @zh
@@ -711,7 +777,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
/**
* @zh
* 停止自动滚动, 调用此 API 可以让 Scrollview 立即停止滚动。
* 停止自动滚动, 调用此 API 可以让 ScrollView 立即停止滚动。
*/
public stopAutoScroll () {
this._autoScrolling = false;
@@ -744,7 +810,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
return ZERO;
}
this._content.getPosition(this._contentPos);
this._contentPos.set(this._content.position);
return this._contentPos;
}
@@ -774,7 +840,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
public start () {
this._calculateBoundary();
// Because widget component will adjust content position and scrollview position is correct after visit
// Because widget component will adjust content position and scrollView position is correct after visit
// So this event could make sure the content is on the correct position after loading.
if (this._content) {
director.once(Director.EVENT_BEFORE_DRAW, this._adjustContentOutOfBoundary, this);
@@ -793,7 +859,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
}
}
}
this._showScrollbar();
this._showScrollBar();
}
public update (dt: number) {
@@ -814,7 +880,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
}
}
}
this._hideScrollbar();
this._hideScrollBar();
this.stopAutoScroll();
}
@@ -845,7 +911,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
}
let deltaMove = new Vec3();
let wheelPrecision = -0.1;
const wheelPrecision = -0.1;
if (this.vertical) {
deltaMove = new Vec3(0, event.getScrollY() * wheelPrecision, 0);
}
@@ -911,7 +977,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
if (!this.enabledInHierarchy || !this._content || !event) { return; }
if (this._hasNestedViewGroup(event, captureListeners)) { return; }
this._dispatchEvent('touch-up');
this._dispatchEvent(EventType.TOUCH_UP);
const touch = event.touch!;
if (this._content) {
@@ -995,7 +1061,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
if (this._scrolling) {
this._scrolling = false;
if (!this._autoScrolling) {
this._dispatchEvent('scroll-ended');
this._dispatchEvent(EventType.SCROLL_ENDED);
}
}
}
@@ -1021,10 +1087,10 @@ export class ScrollViewComponent extends ViewGroupComponent {
const targetDelta = new Vec3(deltaMove);
targetDelta.normalize();
const contentSize = this._content!.getContentSize();
const scrollviewSize = this.node.getContentSize();
const scrollViewSize = this.node.getContentSize();
const totalMoveWidth = (contentSize.width - scrollviewSize.width);
const totalMoveHeight = (contentSize.height - scrollviewSize.height);
const totalMoveWidth = (contentSize.width - scrollViewSize.width);
const totalMoveHeight = (contentSize.height - scrollViewSize.height);
const attenuatedFactorX = this._calculateAttenuatedFactor(totalMoveWidth);
const attenuatedFactorY = this._calculateAttenuatedFactor(totalMoveHeight);
@@ -1039,7 +1105,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
if (this.brake > 0 && factor > 7) {
factor = Math.sqrt(factor);
let a = new Vec3(deltaMove);
const a = new Vec3(deltaMove);
a.multiplyScalar(factor);
targetDelta.set(a);
targetDelta.add(deltaMove);
@@ -1123,22 +1189,20 @@ export class ScrollViewComponent extends ViewGroupComponent {
protected _getContentLeftBoundary () {
const contentPos = this.getContentPosition();
return contentPos.x - this._content!.getAnchorPoint().x * this._content!.getContentSize().width;
return contentPos.x - this._content!.anchorX * this._content!.width;
}
protected _getContentRightBoundary () {
const contentSize = this._content!.getContentSize();
return this._getContentLeftBoundary() + contentSize.width;
return this._getContentLeftBoundary() + this._content!.width;
}
protected _getContentTopBoundary () {
const contentSize = this._content!.getContentSize();
return this._getContentBottomBoundary() + contentSize.height;
return this._getContentBottomBoundary() + this._content!.height;
}
protected _getContentBottomBoundary () {
const contentPos = this.getContentPosition();
return contentPos.y - this._content!.getAnchorPoint().y * this._content!.getContentSize().height;
return contentPos.y - this._content!.anchorY * this._content!.height;
}
protected _getHowMuchOutOfBoundary (addition?: Vec3) {
@@ -1200,13 +1264,13 @@ export class ScrollViewComponent extends ViewGroupComponent {
}
protected _dispatchEvent (event: string) {
if (event === 'scroll-ended') {
if (event === EventType.SCROLL_ENDED) {
this._scrollEventEmitMask = 0;
} else if (event === 'scroll-to-top'
|| event === 'scroll-to-bottom'
|| event === 'scroll-to-left'
|| event === 'scroll-to-right') {
} else if (event === EventType.SCROLL_TO_TOP
|| event === EventType.SCROLL_TO_BOTTOM
|| event === EventType.SCROLL_TO_LEFT
|| event === EventType.SCROLL_TO_RIGHT) {
const flag = (1 << eventMap[event]);
if (this._scrollEventEmitMask & flag) {
@@ -1238,7 +1302,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
}
}
protected _hideScrollbar () {
protected _hideScrollBar () {
if (this._horizontalScrollBar) {
this._horizontalScrollBar.hide();
}
@@ -1248,7 +1312,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
}
}
protected _showScrollbar () {
protected _showScrollBar () {
if (this._horizontalScrollBar) {
this._horizontalScrollBar.show();
}
@@ -1258,7 +1322,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
}
}
// This is for Scrollview as children of a Button
// This is for ScrollView as children of a Button
protected _stopPropagationIfTargetIsMe (event: Event) {
if (event.eventPhase === Event.AT_TARGET && event.target === this.node) {
event.propagationStopped = true;
@@ -1292,7 +1356,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
realMove.add(outOfBoundary);
}
let scrollEventType = '';
let scrollEventType;
const pos = new Vec3();
this._content!.getPosition(pos);
@@ -1300,26 +1364,26 @@ export class ScrollViewComponent extends ViewGroupComponent {
const icBottomPos = pos.y - this._content!.anchorY * this._content!.height;
if (icBottomPos + realMove.y > this._bottomBoundary) {
scrollEventType = 'scroll-to-bottom';
scrollEventType = EventType.SCROLL_TO_BOTTOM;
}
}
else if (realMove.y < 0) { // down
const icTopPos = pos.y - this._content!.anchorY * this._content!.height + this._content!.height;
if (icTopPos + realMove.y <= this._topBoundary) {
scrollEventType = 'scroll-to-top';
scrollEventType = EventType.SCROLL_TO_TOP;
}
}
else if (realMove.x < 0) { // left
const icRightPos = pos.x - this._content!.anchorX * this._content!.width + this._content!.width;
if (icRightPos + realMove.x <= this._rightBoundary) {
scrollEventType = 'scroll-to-right';
scrollEventType = EventType.SCROLL_TO_RIGHT;
}
}
else if (realMove.x > 0) { // right
const icLeftPos = pos.x - this._content!.anchorX * this._content!.width;
if (icLeftPos + realMove.x >= this._leftBoundary) {
scrollEventType = 'scroll-to-left';
scrollEventType = EventType.SCROLL_TO_LEFT;
}
}
@@ -1328,12 +1392,12 @@ export class ScrollViewComponent extends ViewGroupComponent {
if (realMove.x !== 0 || realMove.y !== 0) {
if (!this._scrolling) {
this._scrolling = true;
this._dispatchEvent('scroll-began');
this._dispatchEvent(EventType.SCROLL_BEGAN);
}
this._dispatchEvent('scrolling');
this._dispatchEvent(EventType.SCROLLING);
}
if (scrollEventType.length > 0) {
if (scrollEventType && scrollEventType.length > 0) {
this._dispatchEvent(scrollEventType);
}
@@ -1341,7 +1405,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
protected _handlePressLogic () {
if (this._autoScrolling) {
this._dispatchEvent('scroll-ended');
this._dispatchEvent(EventType.SCROLL_ENDED);
}
this._autoScrolling = false;
@@ -1399,10 +1463,10 @@ export class ScrollViewComponent extends ViewGroupComponent {
this._startAutoScroll(bounceBackAmount, bounceBackTime, true);
if (!this._isBouncing) {
if (bounceBackAmount.y > 0) { this._dispatchEvent('bounce-top'); }
if (bounceBackAmount.y < 0) { this._dispatchEvent('bounce-bottom'); }
if (bounceBackAmount.x > 0) { this._dispatchEvent('bounce-right'); }
if (bounceBackAmount.x < 0) { this._dispatchEvent('bounce-left'); }
if (bounceBackAmount.y > 0) { this._dispatchEvent(EventType.BOUNCE_TOP); }
if (bounceBackAmount.y < 0) { this._dispatchEvent(EventType.BOUNCE_BOTTOM); }
if (bounceBackAmount.x > 0) { this._dispatchEvent(EventType.BOUNCE_RIGHT); }
if (bounceBackAmount.x < 0) { this._dispatchEvent(EventType.BOUNCE_LEFT); }
this._isBouncing = true;
}
@@ -1464,7 +1528,7 @@ export class ScrollViewComponent extends ViewGroupComponent {
const fireEvent = Math.abs(percentage - 1) <= this.getScrollEndedEventTiming();
if (fireEvent && !this._isScrollEndedWithThresholdEventFired) {
this._dispatchEvent('scroll-ended-with-threshold');
this._dispatchEvent(EventType.SCROLL_ENG_WITH_THRESHOLD);
this._isScrollEndedWithThresholdEventFired = true;
}
@@ -1493,12 +1557,12 @@ export class ScrollViewComponent extends ViewGroupComponent {
const deltaMove = new Vec3(newPosition);
deltaMove.subtract(this.getContentPosition());
this._moveContent(this._clampDelta(deltaMove), reachedEnd);
this._dispatchEvent('scrolling');
this._dispatchEvent(EventType.SCROLLING);
if (!this._autoScrolling) {
this._isBouncing = false;
this._scrolling = false;
this._dispatchEvent('scroll-ended');
this._dispatchEvent(EventType.SCROLL_ENDED);
}
}
+17 -11
View File
@@ -118,6 +118,10 @@ enum SizeMode {
ccenum(SizeMode);
enum EventType {
SPRITE_FRAME_CHANGED = 'spriteframe-changed',
}
/**
* @zh
* 渲染精灵组件。
@@ -175,7 +179,7 @@ export class SpriteComponent extends UIRenderComponent {
this._applySpriteFrame(lastSprite);
if (CC_EDITOR) {
// @ts-ignore
this.node.emit('spriteframe-changed', this);
this.node.emit(EventType.SPRITE_FRAME_CHANGED, this);
}
}
@@ -386,27 +390,29 @@ export class SpriteComponent extends UIRenderComponent {
public static FillType = FillType;
public static Type = SpriteType;
public static SizeMode = SizeMode;
public static EventType = EventType;
@property
private _spriteFrame: SpriteFrame | null = null;
protected _spriteFrame: SpriteFrame | null = null;
@property
private _type = SpriteType.SIMPLE;
protected _type = SpriteType.SIMPLE;
@property
private _fillType = FillType.HORIZONTAL;
protected _fillType = FillType.HORIZONTAL;
@property
private _sizeMode = SizeMode.TRIMMED;
protected _sizeMode = SizeMode.TRIMMED;
@property
private _fillCenter: Vec2 = new Vec2(0, 0);
protected _fillCenter: Vec2 = new Vec2(0, 0);
@property
private _fillStart = 0;
protected _fillStart = 0;
@property
private _fillRange = 0;
protected _fillRange = 0;
@property
private _isTrimmedMode = true;
protected _isTrimmedMode = true;
@property
private _useGrayscale = false;
protected _useGrayscale = false;
// _state = 0;
@property
private _atlas: SpriteAtlas | null = null;
protected _atlas: SpriteAtlas | null = null;
// static State = State;
public __preload () {
+13 -16
View File
@@ -29,10 +29,16 @@
*/
import { EventHandler as ComponentEventHandler } from '../../core/components';
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator';
import { ccclass, executionOrder, menu, property } from '../../core/data/class-decorator';
import { ButtonComponent } from './button-component';
import { SpriteComponent } from './sprite-component';
import { ToggleContainerComponent } from './toggle-container-component';
import { extendsEnum } from '../../core/data/utils/extends-enum';
import { EventType as ButtonEventType } from './button-component';
enum EventType {
TOGGLE = 'toggle',
}
/**
* @zh
@@ -124,6 +130,9 @@ export class ToggleComponent extends ButtonComponent {
// }
return null;
}
public static EventType = extendsEnum(EventType, ButtonEventType);
/**
* @zh
* Toggle 按钮的点击事件列表。
@@ -229,15 +238,15 @@ export class ToggleComponent extends ButtonComponent {
}
private _registerToggleEvent () {
this.node.on('click', this.toggle, this);
this.node.on(ToggleComponent.EventType.CLICK, this.toggle, this);
}
private _unregisterToggleEvent () {
this.node.off('click', this.toggle, this);
this.node.off(ToggleComponent.EventType.CLICK, this.toggle, this);
}
private _emitToggleEvents () {
this.node.emit('toggle', this);
this.node.emit(ToggleComponent.EventType.TOGGLE, this);
if (this.checkEvents) {
ComponentEventHandler.emitEvents(this.checkEvents, this);
}
@@ -246,18 +255,6 @@ export class ToggleComponent extends ButtonComponent {
cc.ToggleComponent = ToggleComponent;
// var js = require('../platform/js');
// js.get(Toggle.prototype, '_toggleContainer',
// function () {
// var parent = this.node.parent;
// if (cc.Node.isNode(parent)) {
// return parent.getComponent(cc.ToggleContainer);
// }
// return null;
// }
// );
/**
* @zh
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
@@ -50,7 +50,7 @@ export class ToggleContainerComponent extends Component {
})
public checkEvents: ComponentEventHandler[] = [];
@property
private _allowSwitchOff: boolean = false;
protected _allowSwitchOff: boolean = false;
private _toggleItems: ToggleComponent[] = [];
/**