TextFit190ooTests.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Round 190oo (design review 2, group "fit"): translated texts that pushed toolbar panels out or ran into each other.
  2. // WG-11: at 1920 px the German / Russian menu titles set the hint column's width and the Chord panel and the output
  3. // scope dropped; the titles now give up width first (condensed face, then a squeeze of at least 0.9).
  4. // WG-31: knob captions keep >= 4 px between them, squeezed to 80 % at most, else the 9 px face (two lines if they can).
  5. #include <array>
  6. #include <cmath>
  7. #include "core/TextFit.h"
  8. #include "core/ToolbarLayout.h"
  9. TEST (textfit190oo_menu_squeeze_keeps_the_panels_at_1920)
  10. {
  11. using namespace lynx;
  12. using toolbarlayout::Group;
  13. // the Pattern toolbar's panels in their tight form at 1920 px (MainComponent::layoutToolbar: 31 px rows, gaps 12)
  14. std::array<int, toolbarlayout::groupCount> widths {};
  15. widths[(std::size_t) Group::transport] = 452;
  16. widths[(std::size_t) Group::master] = 118;
  17. widths[(std::size_t) Group::record] = 163;
  18. widths[(std::size_t) Group::snap] = 204;
  19. widths[(std::size_t) Group::windows] = 97;
  20. widths[(std::size_t) Group::file] = 97;
  21. widths[(std::size_t) Group::meters] = 118;
  22. widths[(std::size_t) Group::output] = 104;
  23. widths[(std::size_t) Group::chord] = 88;
  24. const auto layout = toolbarlayout::Layout::makeDefault();
  25. constexpr int room = 1904, gap = 12, items = 8, padding = 8 * items;
  26. int panels = 0;
  27. for (const auto& e : layout.entries)
  28. if (e.shown)
  29. panels += widths[(std::size_t) e.group] + gap;
  30. CHECK (panels == 1549);
  31. // German's titles with the tight padding (~392 px + 8): the Chord panel drops (the bug)
  32. const auto before = toolbarlayout::fit (layout, widths, gap, room, 400);
  33. CHECK (! before[(std::size_t) Group::chord]);
  34. // the condensed titles (~300 px of text) squeezed just enough: every panel stays, the squeeze is >= 0.9
  35. const auto scale = textfit::menuSqueeze (room, panels, 300, padding, items);
  36. CHECK (scale >= 0.9 && scale < 1.0);
  37. const auto hint = (int) std::ceil (300.0 * scale) + padding + 8;
  38. const auto after = toolbarlayout::fit (layout, widths, gap, room, hint);
  39. for (const auto& e : layout.entries)
  40. if (e.shown)
  41. CHECK (after[(std::size_t) e.group]);
  42. // English's titles fit as they are: no squeeze; a menu far too long stops at 0.9 (a panel may drop then)
  43. CHECK (textfit::menuSqueeze (room, panels, 222, padding, items) == 1.0);
  44. CHECK (textfit::menuSqueeze (room, panels, 500, padding, items) == 0.9);
  45. CHECK (textfit::menuSqueeze (room, panels, 0, padding, items) == 1.0);
  46. }
  47. TEST (textfit190oo_knob_captions)
  48. {
  49. using lynx::textfit::CaptionFit;
  50. using lynx::textfit::captionFit;
  51. // the Misc page: 50 px pitch, 46 px for the caption
  52. CHECK (captionFit (40.0f, 46.0f, true, true) == CaptionFit::normal); // en "CUT GROUP"
  53. CHECK (captionFit (57.0f, 46.0f, false, true) == CaptionFit::normal); // de "WIEDERHOLEN": squeezed to ~0.81
  54. CHECK (captionFit (69.0f, 46.0f, true, true) == CaptionFit::twoLines); // ru "ГРУППА ОБРЕЗКИ"
  55. CHECK (captionFit (69.0f, 46.0f, true, false) == CaptionFit::smallFace); // no room for a second line
  56. CHECK (captionFit (65.0f, 46.0f, false, true) == CaptionFit::smallFace); // one long word never breaks
  57. }