CComponent.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*
  2. * CComponent.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CComponent.h"
  12. #include "Images.h"
  13. #include <vcmi/spells/Service.h>
  14. #include <vcmi/spells/Spell.h>
  15. #include "../gui/CGuiHandler.h"
  16. #include "../gui/CursorHandler.h"
  17. #include "../gui/TextAlignment.h"
  18. #include "../gui/Shortcut.h"
  19. #include "../render/Canvas.h"
  20. #include "../render/IFont.h"
  21. #include "../render/IRenderHandler.h"
  22. #include "../render/Graphics.h"
  23. #include "../windows/CMessage.h"
  24. #include "../windows/InfoWindows.h"
  25. #include "../widgets/TextControls.h"
  26. #include "../CGameInfo.h"
  27. #include "../../lib/ArtifactUtils.h"
  28. #include "../../lib/CHeroHandler.h"
  29. #include "../../lib/entities/building/CBuilding.h"
  30. #include "../../lib/entities/faction/CFaction.h"
  31. #include "../../lib/entities/faction/CTown.h"
  32. #include "../../lib/entities/faction/CTownHandler.h"
  33. #include "../../lib/networkPacks/Component.h"
  34. #include "../../lib/spells/CSpellHandler.h"
  35. #include "../../lib/CCreatureHandler.h"
  36. #include "../../lib/CSkillHandler.h"
  37. #include "../../lib/texts/CGeneralTextHandler.h"
  38. #include "../../lib/CArtHandler.h"
  39. #include "../../lib/CArtifactInstance.h"
  40. CComponent::CComponent(ComponentType Type, ComponentSubType Subtype, std::optional<int32_t> Val, ESize imageSize, EFonts font)
  41. {
  42. init(Type, Subtype, Val, imageSize, font, "");
  43. }
  44. CComponent::CComponent(ComponentType Type, ComponentSubType Subtype, const std::string & Val, ESize imageSize, EFonts font)
  45. {
  46. init(Type, Subtype, std::nullopt, imageSize, font, Val);
  47. }
  48. CComponent::CComponent(const Component & c, ESize imageSize, EFonts font)
  49. {
  50. init(c.type, c.subType, c.value, imageSize, font, "");
  51. }
  52. void CComponent::init(ComponentType Type, ComponentSubType Subtype, std::optional<int32_t> Val, ESize imageSize, EFonts fnt, const std::string & ValText)
  53. {
  54. OBJECT_CONSTRUCTION;
  55. addUsedEvents(SHOW_POPUP);
  56. data.type = Type;
  57. data.subType = Subtype;
  58. data.value = Val;
  59. customSubtitle = ValText;
  60. size = imageSize;
  61. font = fnt;
  62. newLine = false;
  63. assert(size < sizeInvalid);
  64. setSurface(getFileName()[size], (int)getIndex());
  65. pos.w = image->pos.w;
  66. pos.h = image->pos.h;
  67. if (imageSize < small)
  68. font = FONT_TINY; //for tiny images - tiny font
  69. pos.h += 4; //distance between text and image
  70. // WARNING: too low values will lead to bad line-breaks in CPlayerOptionTooltipBox - check right-click on starting town in pregame
  71. int max = 80;
  72. if (size < large)
  73. max = 72;
  74. if (size < medium)
  75. max = 60;
  76. if (size < small)
  77. max = 55;
  78. if(Type == ComponentType::RESOURCE && !ValText.empty())
  79. max = 80;
  80. std::vector<std::string> textLines = CMessage::breakText(getSubtitle(), std::max<int>(max, pos.w), font);
  81. const auto & fontPtr = GH.renderHandler().loadFont(font);
  82. const int height = static_cast<int>(fontPtr->getLineHeight());
  83. for(auto & line : textLines)
  84. {
  85. auto label = std::make_shared<CLabel>(pos.w/2, pos.h + height/2, font, ETextAlignment::CENTER, Colors::WHITE, line);
  86. pos.h += height;
  87. if(label->pos.w > pos.w)
  88. {
  89. pos.x -= (label->pos.w - pos.w)/2;
  90. pos.w = label->pos.w;
  91. }
  92. lines.push_back(label);
  93. }
  94. }
  95. std::vector<AnimationPath> CComponent::getFileName() const
  96. {
  97. static const std::array<std::string, 4> primSkillsArr = {"PSKIL32", "PSKIL32", "PSKIL42", "PSKILL"};
  98. static const std::array<std::string, 4> secSkillsArr = {"SECSK32", "SECSK32", "SECSKILL", "SECSK82"};
  99. static const std::array<std::string, 4> resourceArr = {"SMALRES", "RESOURCE", "RESOURCE", "RESOUR82"};
  100. static const std::array<std::string, 4> creatureArr = {"CPRSMALL", "CPRSMALL", "CPRSMALL", "TWCRPORT"};
  101. static const std::array<std::string, 4> artifactArr = {"Artifact", "Artifact", "Artifact", "Artifact"};
  102. static const std::array<std::string, 4> spellsArr = {"SpellInt", "SpellInt", "SpellInt", "SPELLSCR"};
  103. static const std::array<std::string, 4> moraleArr = {"IMRL22", "IMRL30", "IMRL42", "imrl82"};
  104. static const std::array<std::string, 4> luckArr = {"ILCK22", "ILCK30", "ILCK42", "ilck82"};
  105. static const std::array<std::string, 4> heroArr = {"PortraitsSmall", "PortraitsSmall", "PortraitsSmall", "PortraitsLarge"};
  106. static const std::array<std::string, 4> flagArr = {"CREST58", "CREST58", "CREST58", "CREST58"};
  107. auto gen = [](const std::array<std::string, 4> & arr) -> std::vector<AnimationPath>
  108. {
  109. return { AnimationPath::builtin(arr[0]), AnimationPath::builtin(arr[1]), AnimationPath::builtin(arr[2]), AnimationPath::builtin(arr[3]) };
  110. };
  111. switch(data.type)
  112. {
  113. case ComponentType::PRIM_SKILL:
  114. case ComponentType::EXPERIENCE:
  115. case ComponentType::MANA:
  116. case ComponentType::LEVEL:
  117. return gen(primSkillsArr);
  118. case ComponentType::NONE:
  119. case ComponentType::SEC_SKILL:
  120. return gen(secSkillsArr);
  121. case ComponentType::RESOURCE:
  122. case ComponentType::RESOURCE_PER_DAY:
  123. return gen(resourceArr);
  124. case ComponentType::CREATURE:
  125. return gen(creatureArr);
  126. case ComponentType::ARTIFACT:
  127. return gen(artifactArr);
  128. case ComponentType::SPELL_SCROLL:
  129. case ComponentType::SPELL:
  130. return gen(spellsArr);
  131. case ComponentType::MORALE:
  132. return gen(moraleArr);
  133. case ComponentType::LUCK:
  134. return gen(luckArr);
  135. case ComponentType::BUILDING:
  136. return std::vector<AnimationPath>(4, (*CGI->townh)[data.subType.as<BuildingTypeUniqueID>().getFaction()]->town->clientInfo.buildingsIcons);
  137. case ComponentType::HERO_PORTRAIT:
  138. return gen(heroArr);
  139. case ComponentType::FLAG:
  140. return gen(flagArr);
  141. default:
  142. assert(0);
  143. return {};
  144. }
  145. }
  146. size_t CComponent::getIndex() const
  147. {
  148. switch(data.type)
  149. {
  150. case ComponentType::NONE:
  151. return 0;
  152. case ComponentType::PRIM_SKILL:
  153. return data.subType.getNum();
  154. case ComponentType::EXPERIENCE:
  155. case ComponentType::LEVEL:
  156. return 4; // for whatever reason, in H3 experience icon is located in primary skills icons
  157. case ComponentType::MANA:
  158. return 5; // for whatever reason, in H3 mana points icon is located in primary skills icons
  159. case ComponentType::SEC_SKILL:
  160. return data.subType.getNum() * 3 + 3 + data.value.value_or(0) - 1;
  161. case ComponentType::RESOURCE:
  162. case ComponentType::RESOURCE_PER_DAY:
  163. return data.subType.getNum();
  164. case ComponentType::CREATURE:
  165. return CGI->creatures()->getById(data.subType.as<CreatureID>())->getIconIndex();
  166. case ComponentType::ARTIFACT:
  167. return CGI->artifacts()->getById(data.subType.as<ArtifactID>())->getIconIndex();
  168. case ComponentType::SPELL_SCROLL:
  169. case ComponentType::SPELL:
  170. return (size < large) ? data.subType.getNum() + 1 : data.subType.getNum();
  171. case ComponentType::MORALE:
  172. return data.value.value_or(0) + 3;
  173. case ComponentType::LUCK:
  174. return data.value.value_or(0) + 3;
  175. case ComponentType::BUILDING:
  176. return data.subType.as<BuildingTypeUniqueID>().getBuilding();
  177. case ComponentType::HERO_PORTRAIT:
  178. return CGI->heroTypes()->getById(data.subType.as<HeroTypeID>())->getIconIndex();
  179. case ComponentType::FLAG:
  180. return data.subType.getNum();
  181. default:
  182. assert(0);
  183. return 0;
  184. }
  185. }
  186. std::string CComponent::getDescription() const
  187. {
  188. switch(data.type)
  189. {
  190. case ComponentType::PRIM_SKILL:
  191. return CGI->generaltexth->arraytxt[2+data.subType.getNum()];
  192. case ComponentType::EXPERIENCE:
  193. case ComponentType::LEVEL:
  194. return CGI->generaltexth->allTexts[241];
  195. case ComponentType::MANA:
  196. return CGI->generaltexth->allTexts[149];
  197. case ComponentType::SEC_SKILL:
  198. return CGI->skillh->getByIndex(data.subType.getNum())->getDescriptionTranslated(data.value.value_or(0));
  199. case ComponentType::RESOURCE:
  200. case ComponentType::RESOURCE_PER_DAY:
  201. return CGI->generaltexth->allTexts[242];
  202. case ComponentType::NONE:
  203. case ComponentType::CREATURE:
  204. return "";
  205. case ComponentType::ARTIFACT:
  206. return CGI->artifacts()->getById(data.subType.as<ArtifactID>())->getDescriptionTranslated();
  207. case ComponentType::SPELL_SCROLL:
  208. {
  209. auto description = ArtifactID(ArtifactID::SPELL_SCROLL).toEntity(CGI)->getDescriptionTranslated();
  210. ArtifactUtils::insertScrrollSpellName(description, data.subType.as<SpellID>());
  211. return description;
  212. }
  213. case ComponentType::SPELL:
  214. return CGI->spells()->getById(data.subType.as<SpellID>())->getDescriptionTranslated(std::max(0, data.value.value_or(0)));
  215. case ComponentType::MORALE:
  216. return CGI->generaltexth->heroscrn[ 4 - (data.value.value_or(0)>0) + (data.value.value_or(0)<0)];
  217. case ComponentType::LUCK:
  218. return CGI->generaltexth->heroscrn[ 7 - (data.value.value_or(0)>0) + (data.value.value_or(0)<0)];
  219. case ComponentType::BUILDING:
  220. {
  221. auto index = data.subType.as<BuildingTypeUniqueID>();
  222. return (*CGI->townh)[index.getFaction()]->town->buildings[index.getBuilding()]->getDescriptionTranslated();
  223. }
  224. case ComponentType::HERO_PORTRAIT:
  225. return "";
  226. case ComponentType::FLAG:
  227. return "";
  228. default:
  229. assert(0);
  230. return "";
  231. }
  232. }
  233. std::string CComponent::getSubtitle() const
  234. {
  235. if (!customSubtitle.empty())
  236. return customSubtitle;
  237. switch(data.type)
  238. {
  239. case ComponentType::PRIM_SKILL:
  240. if (data.value)
  241. return boost::str(boost::format("%+d %s") % data.value.value_or(0) % CGI->generaltexth->primarySkillNames[data.subType.getNum()]);
  242. else
  243. return CGI->generaltexth->primarySkillNames[data.subType.getNum()];
  244. case ComponentType::EXPERIENCE:
  245. return std::to_string(data.value.value_or(0));
  246. case ComponentType::LEVEL:
  247. {
  248. std::string level = CGI->generaltexth->allTexts[442];
  249. boost::replace_first(level, "1", std::to_string(data.value.value_or(0)));
  250. return level;
  251. }
  252. case ComponentType::MANA:
  253. return boost::str(boost::format("%+d %s") % data.value.value_or(0) % CGI->generaltexth->allTexts[387]);
  254. case ComponentType::SEC_SKILL:
  255. return CGI->generaltexth->levels[data.value.value_or(0)-1] + "\n" + CGI->skillh->getById(data.subType.as<SecondarySkill>())->getNameTranslated();
  256. case ComponentType::RESOURCE:
  257. return std::to_string(data.value.value_or(0));
  258. case ComponentType::RESOURCE_PER_DAY:
  259. return boost::str(boost::format(CGI->generaltexth->allTexts[3]) % data.value.value_or(0));
  260. case ComponentType::CREATURE:
  261. {
  262. auto creature = CGI->creh->getById(data.subType.as<CreatureID>());
  263. if(data.value)
  264. return std::to_string(*data.value) + " " + (*data.value > 1 ? creature->getNamePluralTranslated() : creature->getNameSingularTranslated());
  265. else
  266. return creature->getNamePluralTranslated();
  267. }
  268. case ComponentType::ARTIFACT:
  269. return CGI->artifacts()->getById(data.subType.as<ArtifactID>())->getNameTranslated();
  270. case ComponentType::SPELL_SCROLL:
  271. case ComponentType::SPELL:
  272. if (data.value.value_or(0) < 0)
  273. return "{#A9A9A9|" + CGI->spells()->getById(data.subType.as<SpellID>())->getNameTranslated() + "}";
  274. else
  275. return CGI->spells()->getById(data.subType.as<SpellID>())->getNameTranslated();
  276. case ComponentType::NONE:
  277. case ComponentType::MORALE:
  278. case ComponentType::LUCK:
  279. case ComponentType::HERO_PORTRAIT:
  280. return "";
  281. case ComponentType::BUILDING:
  282. {
  283. auto index = data.subType.as<BuildingTypeUniqueID>();
  284. auto building = (*CGI->townh)[index.getFaction()]->town->buildings[index.getBuilding()];
  285. if(!building)
  286. {
  287. logGlobal->error("Town of faction %s has no building #%d", (*CGI->townh)[index.getFaction()]->town->faction->getNameTranslated(), index.getBuilding().getNum());
  288. return (boost::format("Missing building #%d") % index.getBuilding().getNum()).str();
  289. }
  290. return building->getNameTranslated();
  291. }
  292. case ComponentType::FLAG:
  293. return CGI->generaltexth->capColors[data.subType.as<PlayerColor>().getNum()];
  294. default:
  295. assert(0);
  296. return "";
  297. }
  298. }
  299. void CComponent::setSurface(const AnimationPath & defName, int imgPos)
  300. {
  301. OBJECT_CONSTRUCTION;
  302. image = std::make_shared<CAnimImage>(defName, imgPos);
  303. }
  304. void CComponent::showPopupWindow(const Point & cursorPosition)
  305. {
  306. if(!getDescription().empty())
  307. CRClickPopup::createAndPush(getDescription());
  308. }
  309. void CSelectableComponent::clickPressed(const Point & cursorPosition)
  310. {
  311. if(onSelect)
  312. onSelect();
  313. }
  314. void CSelectableComponent::clickDouble(const Point & cursorPosition)
  315. {
  316. if (!selected)
  317. {
  318. clickPressed(cursorPosition);
  319. }
  320. else
  321. {
  322. if (onChoose)
  323. onChoose();
  324. }
  325. }
  326. void CSelectableComponent::init()
  327. {
  328. selected = false;
  329. }
  330. CSelectableComponent::CSelectableComponent(const Component &c, std::function<void()> OnSelect):
  331. CComponent(c),onSelect(OnSelect)
  332. {
  333. setRedrawParent(true);
  334. addUsedEvents(LCLICK | DOUBLECLICK | KEYBOARD);
  335. init();
  336. }
  337. CSelectableComponent::CSelectableComponent(ComponentType Type, ComponentSubType Sub, int Val, ESize imageSize, std::function<void()> OnSelect):
  338. CComponent(Type,Sub,Val, imageSize),onSelect(OnSelect)
  339. {
  340. setRedrawParent(true);
  341. addUsedEvents(LCLICK | DOUBLECLICK | KEYBOARD);
  342. init();
  343. }
  344. void CSelectableComponent::select(bool on)
  345. {
  346. if(on != selected)
  347. {
  348. selected = on;
  349. redraw();
  350. }
  351. }
  352. void CSelectableComponent::showAll(Canvas & to)
  353. {
  354. CComponent::showAll(to);
  355. if(selected)
  356. {
  357. to.drawBorder(Rect::createAround(image->pos, 1), Colors::BRIGHT_YELLOW);
  358. }
  359. }
  360. void CComponentBox::selectionChanged(std::shared_ptr<CSelectableComponent> newSelection)
  361. {
  362. if (newSelection == selected)
  363. return;
  364. if (selected)
  365. selected->select(false);
  366. selected = newSelection;
  367. if (onSelect)
  368. onSelect(selectedIndex());
  369. if (selected)
  370. selected->select(true);
  371. }
  372. int CComponentBox::selectedIndex()
  373. {
  374. if (selected)
  375. return static_cast<int>(std::find(components.begin(), components.end(), selected) - components.begin());
  376. return -1;
  377. }
  378. Point CComponentBox::getOrTextPos(CComponent *left, CComponent *right)
  379. {
  380. int leftSubtitle = ( left->pos.w - left->image->pos.w) / 2;
  381. int rightSubtitle = (right->pos.w - right->image->pos.w) / 2;
  382. int fullDistance = getDistance(left, right) + leftSubtitle + rightSubtitle;
  383. return Point(fullDistance/2 - leftSubtitle, (left->image->pos.h + right->image->pos.h) / 4);
  384. }
  385. int CComponentBox::getDistance(CComponent *left, CComponent *right)
  386. {
  387. int leftSubtitle = ( left->pos.w - left->image->pos.w) / 2;
  388. int rightSubtitle = (right->pos.w - right->image->pos.w) / 2;
  389. int subtitlesOffset = leftSubtitle + rightSubtitle;
  390. return std::max(betweenSubtitlesMin, betweenImagesMin - subtitlesOffset);
  391. }
  392. void CComponentBox::placeComponents(bool selectable)
  393. {
  394. OBJECT_CONSTRUCTION;
  395. if (components.empty())
  396. return;
  397. //prepare components
  398. for(auto & comp : components)
  399. {
  400. addChild(comp.get());
  401. comp->moveTo(Point(pos.x, pos.y));
  402. }
  403. struct RowData
  404. {
  405. size_t comps;
  406. int width;
  407. int height;
  408. RowData (size_t Comps, int Width, int Height):
  409. comps(Comps), width (Width), height (Height){};
  410. };
  411. std::vector<RowData> rows;
  412. rows.push_back (RowData (0,0,0));
  413. //split components in rows
  414. std::shared_ptr<CComponent> prevComp;
  415. for(std::shared_ptr<CComponent> comp : components)
  416. {
  417. //make sure that components are smaller than our width
  418. //assert(pos.w == 0 || pos.w < comp->pos.w);
  419. const int distance = prevComp ? getDistance(prevComp.get(), comp.get()) : 0;
  420. //start next row
  421. if ((pos.w != 0 && rows.back().width + comp->pos.w + distance > pos.w) // row is full
  422. || rows.back().comps >= componentsInRow
  423. || (prevComp && prevComp->newLine))
  424. {
  425. prevComp = nullptr;
  426. rows.push_back (RowData (0,0,0));
  427. }
  428. if (prevComp)
  429. rows.back().width += distance;
  430. rows.back().comps++;
  431. rows.back().width += comp->pos.w;
  432. vstd::amax(rows.back().height, comp->pos.h);
  433. prevComp = comp;
  434. }
  435. if (pos.w == 0)
  436. {
  437. for(auto & row : rows)
  438. vstd::amax(pos.w, row.width);
  439. }
  440. int height = ((int)rows.size() - 1) * betweenRows;
  441. for(auto & row : rows)
  442. height += row.height;
  443. //assert(pos.h == 0 || pos.h < height);
  444. if (pos.h == 0)
  445. pos.h = height;
  446. auto iter = components.begin();
  447. int currentY = (pos.h - height) / 2;
  448. //move components to their positions
  449. for (auto & rows_row : rows)
  450. {
  451. // amount of free space we may add on each side of every component
  452. int freeSpace = (pos.w - rows_row.width) / ((int)rows_row.comps * 2);
  453. prevComp = nullptr;
  454. int currentX = 0;
  455. for (size_t col = 0; col < rows_row.comps; col++)
  456. {
  457. currentX += freeSpace;
  458. if (prevComp)
  459. {
  460. if (selectable)
  461. {
  462. Point orPos = Point(currentX - freeSpace, currentY) + getOrTextPos(prevComp.get(), iter->get());
  463. orLabels.push_back(std::make_shared<CLabel>(orPos.x, orPos.y, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[4]));
  464. }
  465. currentX += getDistance(prevComp.get(), iter->get());
  466. }
  467. (*iter)->moveBy(Point(currentX, currentY));
  468. currentX += (*iter)->pos.w;
  469. currentX += freeSpace;
  470. prevComp = *(iter++);
  471. }
  472. currentY += rows_row.height + betweenRows;
  473. }
  474. }
  475. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position):
  476. CComponentBox(_components, position, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
  477. {
  478. }
  479. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
  480. components(_components),
  481. betweenImagesMin(betweenImagesMin),
  482. betweenSubtitlesMin(betweenSubtitlesMin),
  483. betweenRows(betweenRows),
  484. componentsInRow(componentsInRow)
  485. {
  486. setRedrawParent(true);
  487. pos = position + pos.topLeft();
  488. placeComponents(false);
  489. }
  490. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect):
  491. CComponentBox(_components, position, _onSelect, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
  492. {
  493. }
  494. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
  495. components(_components.begin(), _components.end()),
  496. onSelect(_onSelect),
  497. betweenImagesMin(betweenImagesMin),
  498. betweenSubtitlesMin(betweenSubtitlesMin),
  499. betweenRows(betweenRows),
  500. componentsInRow(componentsInRow)
  501. {
  502. setRedrawParent(true);
  503. pos = position + pos.topLeft();
  504. placeComponents(true);
  505. assert(!components.empty());
  506. auto key = EShortcut::SELECT_INDEX_1;
  507. for(auto & comp : _components)
  508. {
  509. comp->onSelect = std::bind(&CComponentBox::selectionChanged, this, comp);
  510. comp->assignedKey = key;
  511. key = vstd::next(key, 1);
  512. }
  513. selectionChanged(_components.front());
  514. }