summaryrefslogtreecommitdiff
path: root/Userland/Applications/FontEditor
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-02-16 10:12:46 -0500
committerTim Flynn <trflynn89@pm.me>2022-02-18 07:38:29 -0500
commit0061af170fda70f2c52d2a7f6ba2dc28bf00c948 (patch)
tree3c8f5e4d17ec8a27de4d0c98f668dd4fed9c53c5 /Userland/Applications/FontEditor
parentbb23377b48c7cfc01e62bedcde2e611efa24c450 (diff)
downloadserenity-0061af170fda70f2c52d2a7f6ba2dc28bf00c948.zip
FontEditor: Add a search box to filter Unicode blocks
Diffstat (limited to 'Userland/Applications/FontEditor')
-rw-r--r--Userland/Applications/FontEditor/FontEditor.cpp42
-rw-r--r--Userland/Applications/FontEditor/FontEditor.h4
-rw-r--r--Userland/Applications/FontEditor/FontEditorWindow.gml16
3 files changed, 50 insertions, 12 deletions
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp
index 82f17bbaef..bf64ecaf0c 100644
--- a/Userland/Applications/FontEditor/FontEditor.cpp
+++ b/Userland/Applications/FontEditor/FontEditor.cpp
@@ -134,6 +134,8 @@ FontEditorWidget::FontEditorWidget()
m_fixed_width_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("fixed_width_checkbox");
m_font_metadata_groupbox = *find_descendant_of_type_named<GUI::GroupBox>("font_metadata_groupbox");
m_unicode_block_listview = *find_descendant_of_type_named<GUI::ListView>("unicode_block_listview");
+ m_search_textbox = *find_descendant_of_type_named<GUI::TextBox>("search_textbox");
+ m_unicode_block_container = *find_descendant_of_type_named<GUI::Widget>("unicode_block_container");
m_glyph_editor_widget = m_glyph_editor_container->add<GlyphEditorWidget>();
m_glyph_map_widget = glyph_map_container.add<GUI::GlyphMapWidget>();
@@ -435,24 +437,46 @@ FontEditorWidget::FontEditorWidget()
};
auto unicode_blocks = Unicode::block_display_names();
- m_unicode_block_listview->on_activation = [this, unicode_blocks](auto& index) {
- if (index.row() > 0)
- m_range = unicode_blocks[index.row() - 1].code_point_range;
- else
- m_range = { 0x0000, 0x10FFFF };
- m_glyph_map_widget->set_active_range(m_range);
- };
-
m_unicode_block_list.append("Show All");
for (auto& block : unicode_blocks)
m_unicode_block_list.append(block.display_name);
m_unicode_block_model = GUI::ItemListModel<String>::create(m_unicode_block_list);
- m_unicode_block_listview->set_model(*m_unicode_block_model);
+ m_filter_model = MUST(GUI::FilteringProxyModel::create(*m_unicode_block_model));
+ m_filter_model->set_filter_term("");
+
+ m_unicode_block_listview->on_activation = [this, unicode_blocks](auto& index) {
+ auto mapped_index = m_filter_model->map(index);
+ if (mapped_index.row() > 0)
+ m_range = unicode_blocks[mapped_index.row() - 1].code_point_range;
+ else
+ m_range = { 0x0000, 0x10FFFF };
+ m_glyph_map_widget->set_active_range(m_range);
+ };
+ m_unicode_block_listview->set_model(*m_filter_model);
m_unicode_block_listview->set_activates_on_selection(true);
m_unicode_block_listview->horizontal_scrollbar().set_visible(false);
m_unicode_block_listview->set_cursor(m_unicode_block_model->index(0, 0), GUI::AbstractView::SelectionUpdate::Set);
+ m_search_textbox->on_return_pressed = [this] {
+ if (!m_unicode_block_listview->selection().is_empty())
+ m_unicode_block_listview->activate_selected();
+ };
+
+ m_search_textbox->on_down_pressed = [this] {
+ m_unicode_block_listview->move_cursor(GUI::AbstractView::CursorMovement::Down, GUI::AbstractView::SelectionUpdate::Set);
+ };
+
+ m_search_textbox->on_up_pressed = [this] {
+ m_unicode_block_listview->move_cursor(GUI::AbstractView::CursorMovement::Up, GUI::AbstractView::SelectionUpdate::Set);
+ };
+
+ m_search_textbox->on_change = [this] {
+ m_filter_model->set_filter_term(m_search_textbox->text());
+ if (m_filter_model->row_count() != 0)
+ m_unicode_block_listview->set_cursor(m_filter_model->index(0, 0), GUI::AbstractView::SelectionUpdate::Set);
+ };
+
GUI::Application::the()->on_action_enter = [this](GUI::Action& action) {
auto text = action.status_tip();
if (text.is_empty())
diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/FontEditor.h
index 90e1c2a92f..1d013190cb 100644
--- a/Userland/Applications/FontEditor/FontEditor.h
+++ b/Userland/Applications/FontEditor/FontEditor.h
@@ -10,6 +10,7 @@
#include "UndoGlyph.h"
#include <LibConfig/Listener.h>
#include <LibGUI/ActionGroup.h>
+#include <LibGUI/FilteringProxyModel.h>
#include <LibGUI/GlyphMapWidget.h>
#include <LibGUI/UndoStack.h>
#include <LibGUI/Widget.h>
@@ -111,6 +112,7 @@ private:
RefPtr<GUI::Window> m_font_preview_window;
RefPtr<GUI::Widget> m_left_column_container;
RefPtr<GUI::Widget> m_glyph_editor_container;
+ RefPtr<GUI::Widget> m_unicode_block_container;
RefPtr<GUI::ComboBox> m_weight_combobox;
RefPtr<GUI::ComboBox> m_slope_combobox;
RefPtr<GUI::SpinBox> m_spacing_spinbox;
@@ -121,10 +123,12 @@ private:
RefPtr<GUI::CheckBox> m_glyph_editor_present_checkbox;
RefPtr<GUI::TextBox> m_name_textbox;
RefPtr<GUI::TextBox> m_family_textbox;
+ RefPtr<GUI::TextBox> m_search_textbox;
RefPtr<GUI::CheckBox> m_fixed_width_checkbox;
RefPtr<GUI::GroupBox> m_font_metadata_groupbox;
RefPtr<GUI::ListView> m_unicode_block_listview;
RefPtr<GUI::Model> m_unicode_block_model;
+ RefPtr<GUI::FilteringProxyModel> m_filter_model;
String m_path;
Vector<String> m_font_weight_list;
diff --git a/Userland/Applications/FontEditor/FontEditorWindow.gml b/Userland/Applications/FontEditor/FontEditorWindow.gml
index cf6b1185ba..a1bbf7c9ed 100644
--- a/Userland/Applications/FontEditor/FontEditorWindow.gml
+++ b/Userland/Applications/FontEditor/FontEditorWindow.gml
@@ -219,9 +219,19 @@
}
}
- @GUI::ListView {
- name: "unicode_block_listview"
- max_width: 175
+ @GUI::Widget {
+ name: "unicode_block_container"
+ fixed_width: 175
+ layout: @GUI::VerticalBoxLayout {}
+
+ @GUI::TextBox {
+ name: "search_textbox"
+ placeholder: "Search"
+ }
+
+ @GUI::ListView {
+ name: "unicode_block_listview"
+ }
}
}
}