summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-01-11 20:50:59 +0000
committerAndreas Kling <kling@serenityos.org>2022-01-16 11:17:03 +0100
commite975db23c0ad6fdbad4b376da614135cc62fd6a2 (patch)
tree12dae18ae92027504573315b67e99edde351b3db /Userland
parent9ca8428238cdb08a60bf1e09798e284fe2bd6285 (diff)
downloadserenity-e975db23c0ad6fdbad4b376da614135cc62fd6a2.zip
LibGUI+FontEditor: Move seek-prev/next-glyph logic into GlyphMapWidget
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/FontEditor/FontEditor.cpp32
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.cpp38
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.h3
3 files changed, 43 insertions, 30 deletions
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp
index 53c28fb9a5..9f2dd045ce 100644
--- a/Userland/Applications/FontEditor/FontEditor.cpp
+++ b/Userland/Applications/FontEditor/FontEditor.cpp
@@ -233,39 +233,11 @@ FontEditorWidget::FontEditorWidget()
});
m_go_to_glyph_action->set_status_tip("Go to the specified code point");
m_previous_glyph_action = GUI::Action::create("Pre&vious Glyph", { Mod_Alt, Key_Left }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
- bool search_wrapped = false;
- for (int i = m_glyph_map_widget->active_glyph() - 1;; --i) {
- if (i < 0 && !search_wrapped) {
- i = 0x10FFFF;
- search_wrapped = true;
- } else if (i < 0 && search_wrapped) {
- break;
- }
- if (m_edited_font->contains_raw_glyph(i)) {
- m_glyph_map_widget->set_focus(true);
- m_glyph_map_widget->set_active_glyph(i);
- m_glyph_map_widget->scroll_to_glyph(i);
- break;
- }
- }
+ m_glyph_map_widget->select_previous_existing_glyph();
});
m_previous_glyph_action->set_status_tip("Seek the previous visible glyph");
m_next_glyph_action = GUI::Action::create("&Next Glyph", { Mod_Alt, Key_Right }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
- bool search_wrapped = false;
- for (int i = m_glyph_map_widget->active_glyph() + 1;; ++i) {
- if (i > 0x10FFFF && !search_wrapped) {
- i = 0;
- search_wrapped = true;
- } else if (i > 0x10FFFF && search_wrapped) {
- break;
- }
- if (m_edited_font->contains_raw_glyph(i)) {
- m_glyph_map_widget->set_focus(true);
- m_glyph_map_widget->set_active_glyph(i);
- m_glyph_map_widget->scroll_to_glyph(i);
- break;
- }
- }
+ m_glyph_map_widget->select_next_existing_glyph();
});
m_next_glyph_action->set_status_tip("Seek the next visible glyph");
diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
index 6b379d2dba..002705b0c9 100644
--- a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
@@ -270,6 +270,44 @@ void GlyphMapWidget::scroll_to_glyph(int glyph)
scroll_into_view(scroll_rect, true, true);
}
+void GlyphMapWidget::select_previous_existing_glyph()
+{
+ bool search_wrapped = false;
+ for (int i = active_glyph() - 1;; --i) {
+ if (i < 0 && !search_wrapped) {
+ i = 0x10FFFF;
+ search_wrapped = true;
+ } else if (i < 0 && search_wrapped) {
+ break;
+ }
+ if (font().contains_glyph(i)) {
+ set_focus(true);
+ set_active_glyph(i);
+ scroll_to_glyph(i);
+ break;
+ }
+ }
+}
+
+void GlyphMapWidget::select_next_existing_glyph()
+{
+ bool search_wrapped = false;
+ for (int i = active_glyph() + 1;; ++i) {
+ if (i > 0x10FFFF && !search_wrapped) {
+ i = 0;
+ search_wrapped = true;
+ } else if (i > 0x10FFFF && search_wrapped) {
+ break;
+ }
+ if (font().contains_glyph(i)) {
+ set_focus(true);
+ set_active_glyph(i);
+ scroll_to_glyph(i);
+ break;
+ }
+ }
+}
+
void GlyphMapWidget::recalculate_content_size()
{
auto inner_rect = frame_inner_rect();
diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.h b/Userland/Libraries/LibGUI/GlyphMapWidget.h
index ed258225ad..a634e5f409 100644
--- a/Userland/Libraries/LibGUI/GlyphMapWidget.h
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.h
@@ -56,6 +56,9 @@ public:
void scroll_to_glyph(int);
void update_glyph(int);
+ void select_previous_existing_glyph();
+ void select_next_existing_glyph();
+
int rows() const { return m_rows; }
int columns() const { return m_columns; }