|
30 | 30 | #include <RmlUi/Core/Context.h>
|
31 | 31 | #include <RmlUi/Core/Element.h>
|
32 | 32 | #include <RmlUi/Core/ElementDocument.h>
|
| 33 | +#include <RmlUi/Core/Profiling.h> |
33 | 34 | #include <RmlUi/Core/Types.h>
|
34 | 35 | #include <doctest.h>
|
35 | 36 | #include <nanobench.h>
|
@@ -491,3 +492,82 @@ TEST_CASE("flexbox")
|
491 | 492 | document->Close();
|
492 | 493 | }
|
493 | 494 | }
|
| 495 | + |
| 496 | +static const String rml_flexbox_chatbox = R"( |
| 497 | +<rml> |
| 498 | +<head> |
| 499 | + <title>Chat</title> |
| 500 | + <link type="text/rcss" href="/../Tests/Data/style.rcss"/> |
| 501 | + <style> |
| 502 | + body { |
| 503 | + font-size: 16px; |
| 504 | + overflow: auto; |
| 505 | + height: 300px; |
| 506 | + width: 300px; |
| 507 | + } |
| 508 | + #chat { |
| 509 | + display: flex; |
| 510 | + flex-direction: column; |
| 511 | + border: 2px #caa; |
| 512 | + } |
| 513 | + #chat > div { |
| 514 | + word-break: break-word; |
| 515 | + border: 2px #aac; |
| 516 | + } |
| 517 | + </style> |
| 518 | +</head> |
| 519 | +
|
| 520 | +<body> |
| 521 | + <div id="chat"/> |
| 522 | +</body> |
| 523 | +</rml> |
| 524 | +)"; |
| 525 | + |
| 526 | +TEST_CASE("flexbox.chat") |
| 527 | +{ |
| 528 | + Context* context = TestsShell::GetContext(); |
| 529 | + REQUIRE(context); |
| 530 | + |
| 531 | + nanobench::Bench bench; |
| 532 | + bench.title("Flexbox chat"); |
| 533 | + bench.relative(true); |
| 534 | + // bench.epochs(100); |
| 535 | + |
| 536 | + auto MakeFlexItemsRml = [](int number_items, const String& item_text) { |
| 537 | + String rml; |
| 538 | + for (int i = 0; i < number_items; i++) |
| 539 | + rml += "<div>" + item_text + "</div>"; |
| 540 | + return rml; |
| 541 | + }; |
| 542 | + |
| 543 | + const String short_words = |
| 544 | + MakeFlexItemsRml(10, "aaaaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa"); |
| 545 | + const String long_words = |
| 546 | + MakeFlexItemsRml(10, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 547 | + |
| 548 | + // The flex items will essentially be formatted four times each: |
| 549 | + // - Two times during flex formatting, first to get their height, then to do their actual formatting. |
| 550 | + // - Then flex formatting is itself done twice, since the body adds a scrollbar, thereby modifying the available width. |
| 551 | + // The long words take longer to format, since we do a naive approach to breaking up words in ElementText::GenerateLine, making us calculate |
| 552 | + // string widths repeatedly. Removing the 'word-break' property should make the long word-case much faster. |
| 553 | + ElementDocument* document = context->LoadDocumentFromMemory(rml_flexbox_chatbox); |
| 554 | + Element* chat = document->GetElementById("chat"); |
| 555 | + chat->SetInnerRML(short_words + long_words); |
| 556 | + document->Show(); |
| 557 | + TestsShell::RenderLoop(); |
| 558 | + |
| 559 | + bench.run("Short words", [&] { |
| 560 | + chat->SetInnerRML(short_words); |
| 561 | + context->Update(); |
| 562 | + context->Render(); |
| 563 | + RMLUI_FrameMark; |
| 564 | + }); |
| 565 | + bench.run("Long words", [&] { |
| 566 | + chat->SetInnerRML(long_words); |
| 567 | + context->Update(); |
| 568 | + context->Render(); |
| 569 | + RMLUI_FrameMark; |
| 570 | + }); |
| 571 | + |
| 572 | + document->Close(); |
| 573 | +} |
0 commit comments