Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolai Mortensen committed Jul 3, 2017
1 parent 34e7179 commit 14c9736
Show file tree
Hide file tree
Showing 12 changed files with 961 additions and 231 deletions.
580 changes: 473 additions & 107 deletions bin/pixi-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/pixi-ui.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions bin/pixi-ui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/pixi-ui.min.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ var InputBase = require('./InputBase'),
* @param [options.text=null] {PIXI.UI.Text} optional text
* @param [options.tabIndex=0] {Number} input tab index
* @param [options.tabGroup=0] {Number|String} input tab group
* @param [options.width=options.background.width] {Number|String} width
* @param [options.height=options.background.height] {Number|String} height
*/

function Button(options) {
InputBase.call(this, options.background.width, options.background.height, options.tabIndex || 0, options.tabGroup || 0);
InputBase.call(this, options.width || options.background.width, options.height || options.background.height, options.tabIndex || 0, options.tabGroup || 0);
this.background = options.background;
this.background.width = "100%";
this.background.height = "100%";
this.background.pivot = 0.5;
this.background.verticalAlign = "middle";
this.background.horizontalAlign = "center";
this.addChild(this.background);

this.isHover = false;

this.uiText = options.text;
if (this.uiText) {
Expand All @@ -43,10 +45,12 @@ function Button(options) {

var clickEvent = new ClickEvent(this);
clickEvent.onHover = function (e) {
this.isHover = true;
self.emit("hover", true);
};

clickEvent.onLeave = function (e) {
this.isHover = false;
self.emit("hover", false);
};

Expand Down
60 changes: 30 additions & 30 deletions src/DynamicText/DynamicText.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function DynamicText(text, options) {
var autoHeight = !options.height;

//defaultstyle for this textobject
var defaultStyle = this.defaultStyle = new DynamicTextStyle();
var defaultStyle = this._style = new DynamicTextStyle(this);
defaultStyle.merge(options.style);

//collection of all processed char
Expand All @@ -52,7 +52,6 @@ function DynamicText(text, options) {

this.dirtyText = true;
this.dirtyStyle = true;
this.dirtySize = true;
this.dirtyRender = true;


Expand Down Expand Up @@ -432,26 +431,32 @@ function DynamicText(text, options) {
charCount = charIndex;
};

//PIXIUI update, called every time parent emits a change
//PIXIUI update, lazy update (bad solution needs rewrite when converted to pixi plugin)
this.lazyUpdate = null;
var self = this;
this.update = function () {
this.dirtySize = !autoWidth && (this._width != lastWidth || this._height != lastHeight || this.dirtyText);
if (self.lazyUpdate !== null) return;
self.lazyUpdate = setTimeout(function () {

console.log("UPDATING TEXT");
var dirtySize = !autoWidth && (self._width != lastWidth || self._height != lastHeight || self.dirtyText);

if (this.dirtyText || this.dirtyStyle) {
this.dirtyText = this.dirtyStyle = false;
this.dirtyRender = true; //force render after textchange
this.processInputText();
}
if (self.dirtyText || self.dirtyStyle) {
self.dirtyText = self.dirtyStyle = false;
self.dirtyRender = true; //force render after textchange
self.processInputText();
}

if (this.dirtySize || this.dirtyRender) {
this.dirtySize = this.dirtyRender = false;
lastWidth = this._width;
lastHeight = this.height;
this.prepareForRender();
this.render();
}
if (dirtySize || self.dirtyRender) {
self.dirtyRender = false;
lastWidth = self._width;
lastHeight = self.height;
self.prepareForRender();
self.render();
}
self.lazyUpdate = null;
}, 0);



};
}

Expand All @@ -474,6 +479,7 @@ Object.defineProperties(DynamicText.prototype, {
this._inputText = val;
this.dirtyText = true;
this.update();
console.log("Updating Text to: " + val);
}
}
},
Expand All @@ -482,30 +488,24 @@ Object.defineProperties(DynamicText.prototype, {
return this.value;
},
set: function (val) {

this.value = val;
}
},
style: {
get: function () {
return this.defaultStyle;
return this._style;
},
set: function (val) {
//get a clean default style
var style = new DynamicTextStyle();
var style = new DynamicTextStyle(this);

//merge it with new style
style.merge(val);

//merge it onto this default style
this.defaultStyle.merge(style);
this._style.merge(style);

this.dirtyStyle = true;
this.update();
}
},
mergeStyle: {
set: function (val) {
this.defaultStyle.merge(val);
this.dirtyStyle = true;
this.update();
}
Expand Down
Loading

0 comments on commit 14c9736

Please sign in to comment.