GlyphMapWidget.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org>
  4. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  5. * Copyright (c) 2022, the SerenityOS developers.
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #include "GlyphMapWidget.h"
  10. #include <LibGUI/Painter.h>
  11. #include <LibGfx/Font/BitmapFont.h>
  12. #include <LibGfx/Font/Emoji.h>
  13. #include <LibGfx/Palette.h>
  14. REGISTER_WIDGET(GUI, GlyphMapWidget);
  15. namespace GUI {
  16. GlyphMapWidget::Selection GlyphMapWidget::Selection::normalized() const
  17. {
  18. if (m_size > 0)
  19. return *this;
  20. return { m_start + m_size, -m_size + 1 };
  21. }
  22. void GlyphMapWidget::Selection::resize_by(int i)
  23. {
  24. m_size += i;
  25. if (m_size == 0) {
  26. if (i < 0)
  27. m_size--;
  28. else
  29. m_size++;
  30. }
  31. }
  32. bool GlyphMapWidget::Selection::contains(int i) const
  33. {
  34. auto this_normalized = normalized();
  35. return i >= this_normalized.m_start && i < this_normalized.m_start + this_normalized.m_size;
  36. }
  37. void GlyphMapWidget::Selection::extend_to(int glyph)
  38. {
  39. m_size = glyph - m_start;
  40. if (m_size >= 0)
  41. m_size++;
  42. }
  43. GlyphMapWidget::GlyphMapWidget()
  44. {
  45. set_focus_policy(FocusPolicy::StrongFocus);
  46. horizontal_scrollbar().set_visible(false);
  47. did_change_font();
  48. set_active_glyph('A');
  49. }
  50. void GlyphMapWidget::resize_event(ResizeEvent& event)
  51. {
  52. recalculate_content_size();
  53. AbstractScrollableWidget::resize_event(event);
  54. }
  55. void GlyphMapWidget::set_active_glyph(int glyph, ShouldResetSelection should_reset_selection)
  56. {
  57. if (m_active_glyph == glyph && should_reset_selection == ShouldResetSelection::No)
  58. return;
  59. m_active_glyph = glyph;
  60. if (should_reset_selection == ShouldResetSelection::Yes) {
  61. m_selection.set_start(glyph);
  62. m_selection.set_size(1);
  63. }
  64. if (on_active_glyph_changed)
  65. on_active_glyph_changed(glyph);
  66. update();
  67. }
  68. void GlyphMapWidget::set_selection(int start, int size, Optional<u32> active_glyph)
  69. {
  70. m_selection.set_start(start);
  71. m_selection.set_size(size);
  72. if (active_glyph.has_value())
  73. set_active_glyph(active_glyph.value(), ShouldResetSelection::No);
  74. }
  75. void GlyphMapWidget::restore_selection(int start, int size, int active_glyph)
  76. {
  77. if (start == active_glyph && size > 1) {
  78. start = active_glyph + size - 1;
  79. size = -size + 1;
  80. }
  81. m_selection.set_start(start);
  82. m_selection.set_size(size);
  83. set_active_glyph(active_glyph, ShouldResetSelection::No);
  84. }
  85. Gfx::IntRect GlyphMapWidget::get_outer_rect(int glyph) const
  86. {
  87. glyph -= m_active_range.first;
  88. int row = glyph / columns();
  89. int column = glyph % columns();
  90. return Gfx::IntRect {
  91. column * (font().max_glyph_width() + m_horizontal_spacing),
  92. row * (font().glyph_height() + m_vertical_spacing),
  93. font().max_glyph_width() + m_horizontal_spacing,
  94. font().glyph_height() + m_vertical_spacing
  95. }
  96. .translated(frame_thickness() - horizontal_scrollbar().value(), frame_thickness() - vertical_scrollbar().value());
  97. }
  98. void GlyphMapWidget::update_glyph(int glyph)
  99. {
  100. set_glyph_modified(glyph, true);
  101. update(get_outer_rect(glyph));
  102. }
  103. void GlyphMapWidget::paint_event(PaintEvent& event)
  104. {
  105. Frame::paint_event(event);
  106. Painter painter(*this);
  107. painter.add_clip_rect(widget_inner_rect());
  108. painter.add_clip_rect(event.rect());
  109. painter.set_font(font());
  110. painter.fill_rect(widget_inner_rect(), palette().window().darkened(0.8f));
  111. auto first_row = vertical_scrollbar().value() / vertical_scrollbar().step();
  112. auto first_glyph = first_row * columns() + m_active_range.first;
  113. auto last_glyph = m_active_range.last;
  114. for (u32 glyph = first_glyph; glyph <= first_glyph + m_visible_glyphs && glyph <= last_glyph; ++glyph) {
  115. Gfx::IntRect outer_rect = get_outer_rect(glyph);
  116. Gfx::IntRect inner_rect(
  117. outer_rect.x() + m_horizontal_spacing / 2,
  118. outer_rect.y() + m_vertical_spacing / 2,
  119. font().max_glyph_width(),
  120. font().glyph_height());
  121. if (m_selection.contains(glyph)) {
  122. painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection());
  123. if (font().contains_glyph(glyph))
  124. painter.draw_glyph(inner_rect.location(), glyph, is_focused() ? palette().selection_text() : palette().inactive_selection_text());
  125. else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph); emoji && m_show_system_emoji)
  126. painter.draw_emoji(inner_rect.location(), *emoji, font());
  127. } else if (font().contains_glyph(glyph)) {
  128. if (m_highlight_modifications && m_modified_glyphs.contains(glyph)) {
  129. if (m_original_font->contains_glyph(glyph)) {
  130. // Modified
  131. if (palette().is_dark())
  132. painter.fill_rect(outer_rect, Gfx::Color { 0, 65, 159 });
  133. else
  134. painter.fill_rect(outer_rect, Gfx::Color { 138, 185, 252 });
  135. } else {
  136. // Newly created
  137. if (palette().is_dark())
  138. painter.fill_rect(outer_rect, Gfx::Color { 8, 127, 0 });
  139. else
  140. painter.fill_rect(outer_rect, Gfx::Color { 133, 251, 116 });
  141. }
  142. } else {
  143. painter.fill_rect(outer_rect, palette().base());
  144. }
  145. painter.draw_glyph(inner_rect.location(), glyph, palette().base_text());
  146. } else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph); emoji && m_show_system_emoji) {
  147. painter.draw_emoji(inner_rect.location(), *emoji, font());
  148. } else {
  149. if (m_highlight_modifications && m_original_font->contains_glyph(glyph)) {
  150. // Deleted
  151. if (palette().is_dark())
  152. painter.fill_rect(outer_rect, Gfx::Color { 127, 0, 0 });
  153. else
  154. painter.fill_rect(outer_rect, Gfx::Color { 255, 150, 150 });
  155. } else {
  156. painter.fill_rect(outer_rect, palette().window());
  157. }
  158. }
  159. }
  160. painter.draw_focus_rect(get_outer_rect(m_active_glyph), palette().focus_outline());
  161. }
  162. Optional<int> GlyphMapWidget::glyph_at_position(Gfx::IntPoint position) const
  163. {
  164. Gfx::IntPoint map_offset { frame_thickness() - horizontal_scrollbar().value(), frame_thickness() - vertical_scrollbar().value() };
  165. auto map_position = position - map_offset;
  166. auto col = (map_position.x() - 1) / ((font().max_glyph_width() + m_horizontal_spacing));
  167. auto row = (map_position.y() - 1) / ((font().glyph_height() + m_vertical_spacing));
  168. auto glyph = row * columns() + col + m_active_range.first;
  169. if (row >= 0 && row < rows() && col >= 0 && col < columns() && glyph < m_glyph_count + m_active_range.first)
  170. return glyph;
  171. return {};
  172. }
  173. int GlyphMapWidget::glyph_at_position_clamped(Gfx::IntPoint position) const
  174. {
  175. Gfx::IntPoint map_offset { frame_thickness() - horizontal_scrollbar().value(), frame_thickness() - vertical_scrollbar().value() };
  176. auto map_position = position - map_offset;
  177. auto col = clamp((map_position.x() - 1) / ((font().max_glyph_width() + m_horizontal_spacing)), 0, columns() - 1);
  178. auto row = clamp((map_position.y() - 1) / ((font().glyph_height() + m_vertical_spacing)), 0, rows() - 1);
  179. auto glyph = row * columns() + col + m_active_range.first;
  180. if (row == rows() - 1)
  181. glyph = min(glyph, m_glyph_count + m_active_range.first - 1);
  182. return glyph;
  183. }
  184. void GlyphMapWidget::context_menu_event(GUI::ContextMenuEvent& event)
  185. {
  186. if (on_context_menu_request)
  187. on_context_menu_request(event);
  188. }
  189. void GlyphMapWidget::mousedown_event(MouseEvent& event)
  190. {
  191. if (event.button() == MouseButton::Secondary)
  192. return;
  193. if (auto maybe_glyph = glyph_at_position(event.position()); maybe_glyph.has_value()) {
  194. auto glyph = maybe_glyph.value();
  195. if (event.shift())
  196. m_selection.extend_to(glyph);
  197. m_in_drag_select = true;
  198. set_active_glyph(glyph, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
  199. }
  200. }
  201. void GlyphMapWidget::mouseup_event(GUI::MouseEvent& event)
  202. {
  203. if (event.button() == MouseButton::Secondary)
  204. return;
  205. if (!m_in_drag_select)
  206. return;
  207. auto constrained = event.position().constrained(widget_inner_rect());
  208. if (auto maybe_glyph = glyph_at_position(constrained); maybe_glyph.has_value()) {
  209. auto glyph = maybe_glyph.value();
  210. m_selection.extend_to(glyph);
  211. set_active_glyph(glyph, ShouldResetSelection::No);
  212. }
  213. m_in_drag_select = false;
  214. }
  215. void GlyphMapWidget::mousemove_event(GUI::MouseEvent& event)
  216. {
  217. m_last_mousemove_position = event.position();
  218. if (m_in_drag_select) {
  219. auto constrained = event.position().constrained(widget_inner_rect());
  220. auto glyph = glyph_at_position_clamped(constrained);
  221. m_selection.extend_to(glyph);
  222. set_active_glyph(glyph, ShouldResetSelection::No);
  223. scroll_to_glyph(glyph);
  224. update();
  225. }
  226. }
  227. void GlyphMapWidget::automatic_scrolling_timer_did_fire()
  228. {
  229. if (!m_in_drag_select) {
  230. set_automatic_scrolling_timer_active(false);
  231. return;
  232. }
  233. auto glyph = glyph_at_position_clamped(m_last_mousemove_position);
  234. m_selection.extend_to(glyph);
  235. set_active_glyph(glyph, ShouldResetSelection::No);
  236. scroll_to_glyph(glyph);
  237. update();
  238. }
  239. void GlyphMapWidget::doubleclick_event(MouseEvent& event)
  240. {
  241. if (on_glyph_double_clicked) {
  242. if (auto maybe_glyph = glyph_at_position(event.position()); maybe_glyph.has_value())
  243. on_glyph_double_clicked(maybe_glyph.value());
  244. }
  245. }
  246. void GlyphMapWidget::keydown_event(KeyEvent& event)
  247. {
  248. if (event.key() == KeyCode::Key_Tab) {
  249. AbstractScrollableWidget::keydown_event(event);
  250. return;
  251. }
  252. if (event.key() == KeyCode::Key_Escape) {
  253. m_selection.set_size(1);
  254. m_selection.set_start(m_active_glyph);
  255. if (on_escape_pressed)
  256. on_escape_pressed();
  257. return;
  258. }
  259. if (!event.modifiers() && event.is_arrow_key()) {
  260. m_selection.set_size(1);
  261. m_selection.set_start(m_active_glyph);
  262. }
  263. if (event.shift() && event.is_arrow_key()) {
  264. auto resizing_end = m_selection.start() + m_selection.size() - (m_selection.size() > 0 ? 1 : 0);
  265. set_active_glyph(resizing_end, ShouldResetSelection::No);
  266. scroll_to_glyph(resizing_end);
  267. }
  268. int first_glyph = m_active_range.first;
  269. int last_glyph = m_active_range.last;
  270. auto selection = m_selection.normalized();
  271. if (event.key() == KeyCode::Key_Up) {
  272. if (m_active_glyph - m_columns < first_glyph)
  273. return;
  274. if (event.ctrl() && selection.start() - m_columns < first_glyph)
  275. return;
  276. if (event.shift())
  277. m_selection.extend_to(m_active_glyph - m_columns);
  278. else
  279. m_selection.set_start(m_selection.start() - m_columns);
  280. set_active_glyph(m_active_glyph - m_columns, ShouldResetSelection::No);
  281. scroll_to_glyph(m_active_glyph);
  282. return;
  283. }
  284. if (event.key() == KeyCode::Key_Down) {
  285. if (m_active_glyph + m_columns > last_glyph)
  286. return;
  287. if (event.ctrl() && selection.start() + selection.size() - 1 + m_columns > last_glyph)
  288. return;
  289. if (event.shift())
  290. m_selection.extend_to(m_active_glyph + m_columns);
  291. else
  292. m_selection.set_start(m_selection.start() + m_columns);
  293. set_active_glyph(m_active_glyph + m_columns, ShouldResetSelection::No);
  294. scroll_to_glyph(m_active_glyph);
  295. return;
  296. }
  297. if (event.key() == KeyCode::Key_Left) {
  298. if (m_active_glyph - 1 < first_glyph)
  299. return;
  300. if (event.ctrl() && selection.start() - 1 < first_glyph)
  301. return;
  302. if (event.shift())
  303. m_selection.resize_by(-1);
  304. else
  305. m_selection.set_start(m_selection.start() - 1);
  306. set_active_glyph(m_active_glyph - 1, ShouldResetSelection::No);
  307. scroll_to_glyph(m_active_glyph);
  308. return;
  309. }
  310. if (event.key() == KeyCode::Key_Right) {
  311. if (m_active_glyph + 1 > last_glyph)
  312. return;
  313. if (event.ctrl() && selection.start() + selection.size() > last_glyph)
  314. return;
  315. if (event.shift())
  316. m_selection.resize_by(1);
  317. else
  318. m_selection.set_start(m_selection.start() + 1);
  319. set_active_glyph(m_active_glyph + 1, ShouldResetSelection::No);
  320. scroll_to_glyph(m_active_glyph);
  321. return;
  322. }
  323. if (event.key() == KeyCode::Key_Home) {
  324. if (event.alt()) {
  325. set_active_glyph(first_glyph);
  326. scroll_to_glyph(m_active_glyph);
  327. return;
  328. }
  329. if (event.ctrl() && event.shift()) {
  330. m_selection.extend_to(first_glyph);
  331. set_active_glyph(first_glyph, ShouldResetSelection::No);
  332. scroll_to_glyph(m_active_glyph);
  333. return;
  334. }
  335. auto start_of_row = (m_active_glyph - first_glyph) / m_columns * m_columns;
  336. if (event.shift())
  337. m_selection.extend_to(start_of_row + first_glyph);
  338. set_active_glyph(start_of_row + first_glyph, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
  339. return;
  340. }
  341. if (event.key() == KeyCode::Key_End) {
  342. if (event.alt()) {
  343. set_active_glyph(last_glyph);
  344. scroll_to_glyph(m_active_glyph);
  345. return;
  346. }
  347. if (event.ctrl() && event.shift()) {
  348. m_selection.extend_to(last_glyph);
  349. set_active_glyph(last_glyph, ShouldResetSelection::No);
  350. scroll_to_glyph(m_active_glyph);
  351. return;
  352. }
  353. auto end_of_row = (m_active_glyph - first_glyph) / m_columns * m_columns + (m_columns - 1);
  354. end_of_row = clamp(end_of_row + first_glyph, first_glyph, last_glyph);
  355. if (event.shift())
  356. m_selection.extend_to(end_of_row);
  357. set_active_glyph(end_of_row, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
  358. return;
  359. }
  360. {
  361. auto first_visible_row = vertical_scrollbar().value() / vertical_scrollbar().step();
  362. auto last_visible_row = first_visible_row + m_visible_rows;
  363. auto current_row = (m_active_glyph - first_glyph) / columns();
  364. auto page = m_active_glyph;
  365. if (event.key() == KeyCode::Key_PageDown) {
  366. auto current_page = m_active_glyph + m_columns * (last_visible_row - current_row);
  367. auto next_page = m_active_glyph + m_columns * m_visible_rows;
  368. auto remainder = m_active_glyph + m_columns * ((last_glyph - first_glyph) / columns() - current_row);
  369. if (current_row < last_visible_row && current_page <= last_glyph)
  370. page = current_page;
  371. else if (next_page <= last_glyph)
  372. page = next_page;
  373. else if (remainder <= last_glyph)
  374. page = remainder;
  375. else
  376. page = remainder - m_columns; // Bottom rows do not always extend across all columns
  377. if (event.shift())
  378. m_selection.extend_to(page);
  379. set_active_glyph(page, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
  380. scroll_to_glyph(m_active_glyph);
  381. return;
  382. }
  383. if (event.key() == KeyCode::Key_PageUp) {
  384. auto current_page = m_active_glyph - m_columns * (current_row - first_visible_row);
  385. auto previous_page = m_active_glyph - m_columns * m_visible_rows;
  386. auto remainder = m_active_glyph - m_columns * current_row;
  387. if (current_row > first_visible_row && current_page >= first_glyph)
  388. page = current_page;
  389. else if (previous_page >= first_glyph)
  390. page = previous_page;
  391. else
  392. page = remainder;
  393. if (event.shift())
  394. m_selection.extend_to(page);
  395. set_active_glyph(page, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
  396. scroll_to_glyph(m_active_glyph);
  397. return;
  398. }
  399. }
  400. event.ignore();
  401. }
  402. void GlyphMapWidget::did_change_font()
  403. {
  404. recalculate_content_size();
  405. vertical_scrollbar().set_step(font().glyph_height() + m_vertical_spacing);
  406. }
  407. void GlyphMapWidget::scroll_to_glyph(int glyph)
  408. {
  409. glyph -= m_active_range.first;
  410. int row = glyph / columns();
  411. int column = glyph % columns();
  412. auto scroll_rect = Gfx::IntRect {
  413. column * (font().max_glyph_width() + m_horizontal_spacing),
  414. row * (font().glyph_height() + m_vertical_spacing),
  415. font().max_glyph_width() + m_horizontal_spacing,
  416. font().glyph_height() + m_vertical_spacing
  417. };
  418. scroll_into_view(scroll_rect, true, true);
  419. }
  420. void GlyphMapWidget::select_previous_existing_glyph()
  421. {
  422. bool search_wrapped = false;
  423. int first_glyph = m_active_range.first;
  424. int last_glyph = m_active_range.last;
  425. for (int i = active_glyph() - 1;; --i) {
  426. if (i < first_glyph && !search_wrapped) {
  427. i = last_glyph;
  428. search_wrapped = true;
  429. } else if (i < first_glyph && search_wrapped) {
  430. break;
  431. }
  432. if (font().contains_glyph(i)) {
  433. set_focus(true);
  434. set_active_glyph(i);
  435. scroll_to_glyph(i);
  436. break;
  437. }
  438. }
  439. }
  440. void GlyphMapWidget::select_next_existing_glyph()
  441. {
  442. bool search_wrapped = false;
  443. int first_glyph = m_active_range.first;
  444. int last_glyph = m_active_range.last;
  445. for (int i = active_glyph() + 1;; ++i) {
  446. if (i > last_glyph && !search_wrapped) {
  447. i = first_glyph;
  448. search_wrapped = true;
  449. } else if (i > last_glyph && search_wrapped) {
  450. break;
  451. }
  452. if (font().contains_glyph(i)) {
  453. set_focus(true);
  454. set_active_glyph(i);
  455. scroll_to_glyph(i);
  456. break;
  457. }
  458. }
  459. }
  460. void GlyphMapWidget::recalculate_content_size()
  461. {
  462. auto event_width = widget_inner_rect().width();
  463. auto event_height = widget_inner_rect().height();
  464. m_columns = max(event_width / (font().max_glyph_width() + m_horizontal_spacing), 1);
  465. m_rows = ceil_div(m_glyph_count, m_columns);
  466. constexpr auto overdraw_margins = 2;
  467. auto max_visible_rows = event_height / (font().glyph_height() + m_vertical_spacing);
  468. m_visible_rows = min(max_visible_rows, m_rows);
  469. m_visible_glyphs = (m_visible_rows + overdraw_margins) * m_columns;
  470. int content_width = columns() * (font().max_glyph_width() + m_horizontal_spacing);
  471. int content_height = rows() * (font().glyph_height() + m_vertical_spacing);
  472. set_content_size({ content_width, content_height });
  473. scroll_to_glyph(m_active_glyph);
  474. }
  475. void GlyphMapWidget::set_active_range(Unicode::CodePointRange range)
  476. {
  477. if (m_active_range.first == range.first && m_active_range.last == range.last)
  478. return;
  479. m_active_range = range;
  480. m_glyph_count = range.last - range.first + 1;
  481. set_active_glyph(range.first);
  482. vertical_scrollbar().set_value(0);
  483. recalculate_content_size();
  484. update();
  485. }
  486. void GlyphMapWidget::set_highlight_modifications(bool highlight_modifications)
  487. {
  488. if (m_highlight_modifications == highlight_modifications)
  489. return;
  490. m_highlight_modifications = highlight_modifications;
  491. update();
  492. }
  493. void GlyphMapWidget::set_show_system_emoji(bool show)
  494. {
  495. if (m_show_system_emoji == show)
  496. return;
  497. m_show_system_emoji = show;
  498. update();
  499. }
  500. void GlyphMapWidget::set_glyph_modified(u32 glyph, bool modified)
  501. {
  502. if (modified)
  503. m_modified_glyphs.set(glyph);
  504. else
  505. m_modified_glyphs.remove(glyph);
  506. }
  507. bool GlyphMapWidget::glyph_is_modified(u32 glyph)
  508. {
  509. return m_modified_glyphs.contains(glyph);
  510. }
  511. ErrorOr<void> GlyphMapWidget::set_font(Gfx::Font const& font)
  512. {
  513. m_original_font = TRY(font.try_clone());
  514. m_modified_glyphs.clear();
  515. AbstractScrollableWidget::set_font(font);
  516. return {};
  517. }
  518. void GlyphMapWidget::enter_event(Core::Event&)
  519. {
  520. set_automatic_scrolling_timer_active(false);
  521. }
  522. void GlyphMapWidget::leave_event(Core::Event&)
  523. {
  524. if (m_in_drag_select)
  525. set_automatic_scrolling_timer_active(true);
  526. }
  527. Optional<UISize> GlyphMapWidget::calculated_min_size() const
  528. {
  529. auto scrollbar = vertical_scrollbar().effective_min_size().height().as_int();
  530. auto min_height = max(font().glyph_height() + m_vertical_spacing, scrollbar);
  531. auto min_width = font().max_glyph_width() + m_horizontal_spacing + width_occupied_by_vertical_scrollbar();
  532. return { { min_width + frame_thickness() * 2, min_height + frame_thickness() * 2 } };
  533. }
  534. }