@@ -2282,6 +2282,8 @@ LabelLayoutBaseTest::LabelLayoutBaseTest()
2282
2282
2283
2283
this ->initAlignmentOption (size);
2284
2284
2285
+ this ->initUnderlineStrikethroughOption (size);
2286
+
2285
2287
this ->initDrawNode (size);
2286
2288
2287
2289
this ->initSliders (size);
@@ -2394,6 +2396,41 @@ void LabelLayoutBaseTest::initAlignmentOption(const ax::Size& size)
2394
2396
this ->addChild (menu);
2395
2397
}
2396
2398
2399
+ void LabelLayoutBaseTest::initUnderlineStrikethroughOption (const ax::Size& size)
2400
+ {
2401
+ // add text alignment settings
2402
+ MenuItemFont::setFontSize (12 );
2403
+ auto menu = Menu::create (MenuItemFont::create (" Toggle Underline" ,
2404
+ [this ](Object*) {
2405
+ if (_underline)
2406
+ {
2407
+ _label->disableEffect (LabelEffect::UNDERLINE);
2408
+ }
2409
+ else
2410
+ {
2411
+ _label->enableUnderline ();
2412
+ }
2413
+ _underline = !_underline;
2414
+ }
2415
+ ),
2416
+ MenuItemFont::create (" Toggle Strikethrough" ,
2417
+ [this ](Object*) {
2418
+ if (_strikethrough)
2419
+ {
2420
+ _label->disableEffect (LabelEffect::STRIKETHROUGH);
2421
+ }
2422
+ else
2423
+ {
2424
+ _label->enableStrikethrough ();
2425
+ }
2426
+ _strikethrough = !_strikethrough;
2427
+ }
2428
+ ), nullptr );
2429
+ menu->alignItemsVerticallyWithPadding (4 );
2430
+ menu->setPosition (Vec2 (size.width - 60 , 60 ));
2431
+ this ->addChild (menu);
2432
+ }
2433
+
2397
2434
void LabelLayoutBaseTest::initSliders (const ax::Size& size)
2398
2435
{
2399
2436
auto slider = ui::Slider::create ();
@@ -3325,61 +3362,61 @@ LabelUnderlineStrikethroughMultiline::LabelUnderlineStrikethroughMultiline()
3325
3362
ttfConfig.strikethrough = true ;
3326
3363
3327
3364
const int count = 7 ;
3328
- Label* label [count];
3365
+ Label* labels [count];
3329
3366
3330
- label [0 ] = Label::createWithSystemFont (" SystemFont TextVAlignment::TOP\n using setTextColor(255, 0, 255, 100)" , font, 14 , Vec2::ZERO, TextHAlignment::LEFT, TextVAlignment::TOP);
3331
- label [0 ]->setTextColor (Color4B (255 , 0 , 255 , 100 ));
3332
- label [0 ]->enableGlow (Color4B::BLUE);
3367
+ labels [0 ] = Label::createWithSystemFont (" SystemFont TextVAlignment::TOP\n using setTextColor(255, 0, 255, 100)" , font, 14 , Vec2::ZERO, TextHAlignment::LEFT, TextVAlignment::TOP);
3368
+ labels [0 ]->setTextColor (Color4B (255 , 0 , 255 , 100 ));
3369
+ labels [0 ]->enableGlow (Color4B::BLUE);
3333
3370
3334
- label [1 ] = Label::createWithSystemFont (" SystemFont TextVAlignment::CENTER\n using setColor(*RED*)" , font, 14 , Vec2::ZERO, TextHAlignment::RIGHT, TextVAlignment::CENTER);
3335
- label [1 ]->setColor (Color3B::RED);
3371
+ labels [1 ] = Label::createWithSystemFont (" SystemFont TextVAlignment::CENTER\n using setColor(*RED*)" , font, 14 , Vec2::ZERO, TextHAlignment::RIGHT, TextVAlignment::CENTER);
3372
+ labels [1 ]->setColor (Color3B::RED);
3336
3373
3337
- label [2 ] = Label::createWithSystemFont (" SystemFont TextVAlignment::BOTTOM\n usingsetTextColor(*YELLOW)" , font, 14 ,
3374
+ labels [2 ] = Label::createWithSystemFont (" SystemFont TextVAlignment::BOTTOM\n usingsetTextColor(*YELLOW)" , font, 14 ,
3338
3375
Vec2::ZERO, TextHAlignment::CENTER, TextVAlignment::BOTTOM);
3339
- label [2 ]->setTextColor (Color4B::YELLOW);
3376
+ labels [2 ]->setTextColor (Color4B::YELLOW);
3340
3377
3341
- label [3 ] = Label::createWithBMFont (" fonts/bitmapFontTest5.fnt" , " BMFont\n with default color" , TextHAlignment::CENTER, s.width );
3378
+ labels [3 ] = Label::createWithBMFont (" fonts/bitmapFontTest5.fnt" , " BMFont\n with default color" , TextHAlignment::CENTER, s.width );
3342
3379
3343
- label [4 ] = Label::createWithBMFont (" fonts/bitmapFontTest5.fnt" , " BMFont\n using setTextColor(0, 255, 0, 100)" ,
3380
+ labels [4 ] = Label::createWithBMFont (" fonts/bitmapFontTest5.fnt" , " BMFont\n using setTextColor(0, 255, 0, 100)" ,
3344
3381
TextHAlignment::CENTER, s.width );
3345
- label [4 ]->setTextColor (Color4B (0 , 255 , 0 , 100 ));
3382
+ labels [4 ]->setTextColor (Color4B (0 , 255 , 0 , 100 ));
3346
3383
3347
- label [5 ] = Label::createWithTTF (ttfConfig, " TTF setColor(*BLUE*)\n with multiline 1\n and a much more longer multiline 2" ,
3384
+ labels [5 ] = Label::createWithTTF (ttfConfig, " TTF setColor(*BLUE*)\n with multiline 1\n and a much more longer multiline 2" ,
3348
3385
TextHAlignment::LEFT, s.width );
3349
- label [5 ]->setColor (Color3B::BLUE);
3386
+ labels [5 ]->setColor (Color3B::BLUE);
3350
3387
3351
- label [6 ] = Label::createWithTTF (" TTF setTextColor(*RED*)\n with multiline 1\n and a much more longer multiline 2" ,
3388
+ labels [6 ] = Label::createWithTTF (" TTF setTextColor(*RED*)\n with multiline 1\n and a much more longer multiline 2" ,
3352
3389
font, 14 );
3353
- label [6 ]->setTextColor (Color4B::RED);
3390
+ labels [6 ]->setTextColor (Color4B::RED);
3354
3391
3355
3392
for (int i = 0 ; i < count; i++)
3356
3393
{
3357
- label [i]->setPosition (Vec2 (label [i]->getBoundingBox ().getMaxX () +10 , s.height * 0 .13f * (i + 1 )));
3358
- label [i]->enableUnderline ();
3359
- label [i]->enableStrikethrough ();
3360
- addChild (label [i]);
3394
+ labels [i]->setPosition (Vec2 (labels [i]->getBoundingBox ().getMaxX () +10 , s.height * 0 .13f * (i + 1 )));
3395
+ labels [i]->enableUnderline ();
3396
+ labels [i]->enableStrikethrough ();
3397
+ addChild (labels [i]);
3361
3398
}
3362
3399
3363
3400
Label* labelSize[10 ];
3364
3401
float y = 0 ;
3365
3402
for (int i = 0 ; i < 10 ; i++)
3366
3403
{
3367
3404
float fs = (i + 1 ) * 3 ;
3368
- labelSize[i] = Label::createWithTTF (" UNTERLINE " , " fonts/arial.ttf" , fs);
3405
+ labelSize[i] = Label::createWithTTF (" UNDERLINE " , " fonts/arial.ttf" , fs);
3369
3406
labelSize[i]->setPosition (s.width / 1.3 , s.height -50 - y);
3370
3407
y += (i + 2 ) * 3 ;
3371
3408
labelSize[i]->enableUnderline ();
3372
3409
addChild (labelSize[i]);
3373
3410
}
3374
3411
3375
- auto menuItemU = MenuItemFont::create (" disable/enable underline" , [=](ax::Object* sender) {
3412
+ auto menuItemU = MenuItemFont::create (" toggle underline" , [=](ax::Object* sender) {
3376
3413
static bool isEnabled = true ;
3377
3414
for (int i = 0 ; i < count; i++)
3378
3415
{
3379
3416
if (isEnabled)
3380
- label [i]->disableEffect (LabelEffect::UNDERLINE);
3417
+ labels [i]->disableEffect (LabelEffect::UNDERLINE);
3381
3418
else
3382
- label [i]->enableUnderline ();
3419
+ labels [i]->enableUnderline ();
3383
3420
}
3384
3421
for (int i = 0 ; i < 10 ; i++)
3385
3422
{
@@ -3388,21 +3425,22 @@ LabelUnderlineStrikethroughMultiline::LabelUnderlineStrikethroughMultiline()
3388
3425
else
3389
3426
labelSize[i]->enableUnderline ();
3390
3427
}
3391
- isEnabled = ( isEnabled) ? false : true ;
3428
+ isEnabled = ! isEnabled;
3392
3429
});
3393
3430
menuItemU->setFontSizeObj (12 );
3394
- auto menuItemS = MenuItemFont::create (" disable/enable strikethrough" , [=](ax::Object* sender) {
3431
+ auto menuItemS = MenuItemFont::create (" toggle strikethrough" , [=](ax::Object* sender) {
3395
3432
static bool isEnabled = true ;
3396
3433
for (int i = 0 ; i < count; i++)
3397
3434
{
3398
3435
if (isEnabled)
3399
- label [i]->disableEffect (LabelEffect::STRIKETHROUGH);
3436
+ labels [i]->disableEffect (LabelEffect::STRIKETHROUGH);
3400
3437
else
3401
- label [i]->enableStrikethrough ();
3438
+ labels [i]->enableStrikethrough ();
3402
3439
}
3403
- isEnabled = ( isEnabled) ? false : true ;
3440
+ isEnabled = ! isEnabled;
3404
3441
});
3405
3442
menuItemS->setFontSizeObj (12 );
3443
+
3406
3444
auto menu = Menu::create (menuItemU, menuItemS, NULL );
3407
3445
addChild (menu);
3408
3446
@@ -3442,15 +3480,15 @@ LabelStrikethrough::LabelStrikethrough()
3442
3480
addChild (_label2a, 0 , kTagBitmapAtlas2 );
3443
3481
_label2a->setPosition (Vec2 (s.width / 2 , s.height * 1 / 3 ));
3444
3482
3445
- auto menuItem = MenuItemFont::create (" disable underline " , [&](ax::Object* sender) {
3483
+ auto menuItem = MenuItemFont::create (" disable strikethrough " , [&](ax::Object* sender) {
3446
3484
_label2a->disableEffect (LabelEffect::STRIKETHROUGH);
3447
3485
_label1a->disableEffect (LabelEffect::STRIKETHROUGH);
3448
3486
});
3449
3487
menuItem->setFontSizeObj (12 );
3450
3488
auto menu = Menu::createWithItem (menuItem);
3451
3489
addChild (menu);
3452
3490
auto winSize = Director::getInstance ()->getWinSize ();
3453
- menu->setPosition (winSize.width * 0.9 , winSize.height * 0 .25f );
3491
+ menu->setPosition (winSize.width * 0.86 , winSize.height * 0 .25f );
3454
3492
}
3455
3493
3456
3494
std::string LabelStrikethrough::title () const
0 commit comments