GlyphMapWidget.cpp 21 KB

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