mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14930 from ricardoquesada/rich_text_fixes
adds JS tests for RichText
This commit is contained in:
commit
ec2d29ed16
|
@ -1184,6 +1184,7 @@ void Label::disableEffect(LabelEffect effect)
|
|||
{
|
||||
_shadowEnabled = false;
|
||||
CC_SAFE_RELEASE_NULL(_shadowNode);
|
||||
updateShaderProgram();
|
||||
}
|
||||
break;
|
||||
case cocos2d::LabelEffect::GLOW:
|
||||
|
@ -1382,11 +1383,14 @@ void Label::updateContent()
|
|||
|
||||
if (_underlineNode)
|
||||
{
|
||||
const float charheight = (_textDesiredHeight / _numberOfLines);
|
||||
|
||||
_underlineNode->clear();
|
||||
|
||||
if (_numberOfLines)
|
||||
{
|
||||
const float charheight = (_textDesiredHeight / _numberOfLines);
|
||||
_underlineNode->setLineWidth(charheight/6);
|
||||
|
||||
// atlas font
|
||||
for (int i=0; i<_numberOfLines; ++i)
|
||||
{
|
||||
float offsety = 0;
|
||||
|
@ -1397,6 +1401,20 @@ void Label::updateContent()
|
|||
_underlineNode->drawLine(Vec2(_linesOffsetX[i],y), Vec2(_linesWidth[i] + _linesOffsetX[i],y), _textColorF);
|
||||
}
|
||||
}
|
||||
else if (_textSprite)
|
||||
{
|
||||
// system font
|
||||
float y = 0;
|
||||
const auto spriteSize = _textSprite->getContentSize();
|
||||
_underlineNode->setLineWidth(spriteSize.height/6);
|
||||
|
||||
if (_strikethroughEnabled)
|
||||
// FIXME: system fonts don't report the height of the font correctly. only the size of the texture, which is POT
|
||||
y += spriteSize.height / 2;
|
||||
// FIXME: Might not work with different vertical alignments
|
||||
_underlineNode->drawLine(Vec2(0,y), Vec2(spriteSize.width,y), Color4F(_textSprite->getDisplayedColor()));
|
||||
}
|
||||
}
|
||||
|
||||
if(updateFinished){
|
||||
_contentDirty = false;
|
||||
|
@ -1857,6 +1875,9 @@ void Label::updateDisplayedColor(const Color3B& parentColor)
|
|||
{
|
||||
_shadowNode->updateDisplayedColor(_displayedColor);
|
||||
}
|
||||
|
||||
if (_underlineNode)
|
||||
_contentDirty = true;
|
||||
}
|
||||
|
||||
for (auto&& it : _letters)
|
||||
|
|
|
@ -125,7 +125,7 @@ ccui.TextField.prototype._ctor = function(placeholder, fontName, fontSize){
|
|||
};
|
||||
|
||||
ccui.RichElementText.prototype._ctor = function(tag, color, opacity, text, fontName, fontSize){
|
||||
fontSize !== undefined && this.init(tag, color, opacity, text, fontName, fontSize);
|
||||
fontSize !== undefined && this.init(tag, color, opacity, text, fontName, fontSize, 0, "");
|
||||
};
|
||||
|
||||
ccui.RichElementImage.prototype._ctor = function(tag, color, opacity, filePath){
|
||||
|
|
|
@ -813,10 +813,10 @@ void RichText::handleImageRenderer(const std::string& filePath, const Color3B &c
|
|||
imageRenderer->setScaleY(height / currentSize.height);
|
||||
imageRenderer->setContentSize(Size(currentSize.width * imageRenderer->getScaleX(),
|
||||
currentSize.height * imageRenderer->getScaleY()));
|
||||
}
|
||||
|
||||
handleCustomRenderer(imageRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
void RichText::handleCustomRenderer(cocos2d::Node *renderer)
|
||||
{
|
||||
|
|
|
@ -89,3 +89,542 @@ var UIRichTextTest = UIMainLayer.extend({
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLBasic
|
||||
//
|
||||
var UIRichTextXMLBasic = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("This is just a simple text. no xml tags here. testing the basics. testing word-wrapping. testing, testing, testing");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLSmallBig
|
||||
//
|
||||
var UIRichTextXMLSmallBig = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("Regular size.<small>smaller size.</small><big>bigger.<small>normal.</small>bigger</big>.normal.");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLColor
|
||||
//
|
||||
var UIRichTextXMLColor = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("Defaul color.<font color='#ff0000'>red.<font color='#00ff00'>green</font>red again.</font>default again");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLSUIB
|
||||
//
|
||||
var UIRichTextXMLSUIB = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("system font: <u>underline</u><i>italics</i><b>bold</b><del>strike-through</del>");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLSUIB2
|
||||
//
|
||||
var UIRichTextXMLSUIB2 = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("<font face='fonts/Marker Felt.ttf' size='24'>ttf font: <u>underline</u><i>italics</i><b>bold</b><del>strike-through</del></font>");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLSUIB3
|
||||
//
|
||||
var UIRichTextXMLSUIB3 = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("<font face='fonts/Marker Felt.ttf' size='20'>ttf font: <i><u>italics and underline</u></i><del><b>bold and strike-through</b></del></font>");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLImg
|
||||
//
|
||||
var UIRichTextXMLImg = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("you should see an image here: <img src='ccs-res/cocosui/sliderballnormal.png'/> and this is text again. and this is the same image, but bigger: <img src='ccs-res/cocosui/sliderballnormal.png' width='30' height='30' /> and here goes text again");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLUrl
|
||||
//
|
||||
var UIRichTextXMLUrl = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("And this link will redirect you to google: <a href='http://www.google.com'>click me</a>");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLFace
|
||||
//
|
||||
var UIRichTextXMLFace = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("<font size='20' face='fonts/Marker Felt.ttf'>Marker Felt 20.<font face='fonts/arial.ttf'>Arial 20.</font></font><font face='font/Thonburi.ttf' size='24' color='#0000ff'>Thonburi 24 blue</font>");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLBR
|
||||
//
|
||||
var UIRichTextXMLBR = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("this is one line.<br/>this should be in another line.<br/>and this is another line");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// UIRichTextXMLInvalid
|
||||
//
|
||||
var UIRichTextXMLInvalid = UIMainLayer.extend({
|
||||
_richText:null,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
//init text
|
||||
this._topDisplayLabel.setString("");
|
||||
this._bottomDisplayLabel.setString("RichText");
|
||||
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
var button = new ccui.Button();
|
||||
button.setTouchEnabled(true);
|
||||
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
|
||||
button.setTitleText("switch");
|
||||
button.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2 + button.getContentSize().height * 2.5));
|
||||
button.addTouchEventListener(this.touchEvent,this);
|
||||
this._mainNode.addChild(button);
|
||||
|
||||
// RichText
|
||||
var richText = new ccui.RichText();
|
||||
richText.initWithXML("this is an invalid xml. <i>no closing tag");
|
||||
|
||||
richText.ignoreContentAdaptWithSize(false);
|
||||
richText.width = 120;
|
||||
richText.height = 100;
|
||||
|
||||
richText.x = widgetSize.width / 2;
|
||||
richText.y = widgetSize.height / 2;
|
||||
|
||||
this._mainNode.addChild(richText);
|
||||
this._richText = richText;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
touchEvent: function (sender, type) {
|
||||
if (type == ccui.Widget.TOUCH_ENDED) {
|
||||
if (this._richText.isIgnoreContentAdaptWithSize()) {
|
||||
this._richText.ignoreContentAdaptWithSize(false);
|
||||
this._richText.setContentSize(cc.size(120, 100));
|
||||
} else {
|
||||
this._richText.ignoreContentAdaptWithSize(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -551,6 +551,72 @@
|
|||
func: function () {
|
||||
return new UIRichTextTest();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLBasic",
|
||||
func: function () {
|
||||
return new UIRichTextXMLBasic();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLSmallBig",
|
||||
func: function () {
|
||||
return new UIRichTextXMLSmallBig();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLColor",
|
||||
func: function () {
|
||||
return new UIRichTextXMLColor();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLSUIB",
|
||||
func: function () {
|
||||
return new UIRichTextXMLSUIB();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLSUIB2",
|
||||
func: function () {
|
||||
return new UIRichTextXMLSUIB2();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLSUIB3",
|
||||
func: function () {
|
||||
return new UIRichTextXMLSUIB3();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLImg",
|
||||
func: function () {
|
||||
return new UIRichTextXMLImg();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLUrl",
|
||||
func: function () {
|
||||
return new UIRichTextXMLUrl();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLFace",
|
||||
func: function () {
|
||||
return new UIRichTextXMLFace();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLBR",
|
||||
func: function () {
|
||||
return new UIRichTextXMLBR();
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "UIRichTextXMLInvalid",
|
||||
func: function () {
|
||||
return new UIRichTextXMLInvalid();
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue