summaryrefslogtreecommitdiff
path: root/Userland/Applications/CharacterMap
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Applications/CharacterMap')
-rw-r--r--Userland/Applications/CharacterMap/CharacterSearchWidget.cpp25
-rw-r--r--Userland/Applications/CharacterMap/CharacterSearchWidget.h4
-rw-r--r--Userland/Applications/CharacterMap/CharacterSearchWindow.gml4
3 files changed, 18 insertions, 15 deletions
diff --git a/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp b/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp
index f52335e107..49f0ee13e7 100644
--- a/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp
+++ b/Userland/Applications/CharacterMap/CharacterSearchWidget.cpp
@@ -10,6 +10,7 @@
struct SearchResult {
u32 code_point;
+ String code_point_string;
String display_text;
};
@@ -18,13 +19,16 @@ public:
CharacterSearchModel() { }
int row_count(GUI::ModelIndex const&) const override { return m_data.size(); }
- int column_count(GUI::ModelIndex const&) const override { return 1; }
+ int column_count(GUI::ModelIndex const&) const override { return 2; }
GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole role) const override
{
auto& result = m_data.at(index.row());
- if (role == GUI::ModelRole::Display)
+ if (role == GUI::ModelRole::Display) {
+ if (index.column() == 0)
+ return result.code_point_string;
return result.display_text;
+ }
if (role == GUI::ModelRole::Custom)
return result.code_point;
return {};
@@ -52,15 +56,16 @@ CharacterSearchWidget::CharacterSearchWidget()
m_search_input = find_descendant_of_type_named<GUI::TextBox>("search_input");
m_search_button = find_descendant_of_type_named<GUI::Button>("search_button");
- m_results_list = find_descendant_of_type_named<GUI::ListView>("results_list");
+ m_results_table = find_descendant_of_type_named<GUI::TableView>("results_table");
m_search_input->on_return_pressed = [this] { search(); };
m_search_button->on_click = [this](auto) { search(); };
- m_results_list->horizontal_scrollbar().set_visible(false);
- m_results_list->set_model(adopt_ref(*new CharacterSearchModel()));
- m_results_list->on_activation = [&](GUI::ModelIndex const& index) {
- auto& model = static_cast<CharacterSearchModel&>(*m_results_list->model());
+ m_results_table->horizontal_scrollbar().set_visible(false);
+ m_results_table->set_column_headers_visible(false);
+ m_results_table->set_model(adopt_ref(*new CharacterSearchModel()));
+ m_results_table->on_activation = [&](GUI::ModelIndex const& index) {
+ auto& model = static_cast<CharacterSearchModel&>(*m_results_table->model());
auto code_point = model.data(index, GUI::ModelRole::Custom).as_u32();
if (on_character_selected)
on_character_selected(code_point);
@@ -75,7 +80,7 @@ void CharacterSearchWidget::search()
{
// TODO: Sort the results nicely. They're sorted by code-point for now, which is easy, but not the most useful.
// Sorting intelligently in a style similar to Assistant would be nicer.
- auto& model = static_cast<CharacterSearchModel&>(*m_results_list->model());
+ auto& model = static_cast<CharacterSearchModel&>(*m_results_table->model());
model.clear();
auto query = m_search_input->text();
if (query.is_empty())
@@ -83,9 +88,7 @@ void CharacterSearchWidget::search()
for_each_character_containing(query, [&](auto code_point, auto& display_name) {
StringBuilder builder;
builder.append_code_point(code_point);
- builder.append(" - ");
- builder.append(display_name);
- model.add_result({ code_point, builder.to_string() });
+ model.add_result({ code_point, builder.build(), display_name });
});
}
diff --git a/Userland/Applications/CharacterMap/CharacterSearchWidget.h b/Userland/Applications/CharacterMap/CharacterSearchWidget.h
index 8109246663..51672dfdec 100644
--- a/Userland/Applications/CharacterMap/CharacterSearchWidget.h
+++ b/Userland/Applications/CharacterMap/CharacterSearchWidget.h
@@ -8,7 +8,7 @@
#include "CharacterMapWidget.h"
#include <LibGUI/Button.h>
-#include <LibGUI/ListView.h>
+#include <LibGUI/TableView.h>
#include <LibGUI/TextBox.h>
class CharacterSearchWidget final : public GUI::Widget {
@@ -26,5 +26,5 @@ private:
RefPtr<GUI::TextBox> m_search_input;
RefPtr<GUI::Button> m_search_button;
- RefPtr<GUI::ListView> m_results_list;
+ RefPtr<GUI::TableView> m_results_table;
};
diff --git a/Userland/Applications/CharacterMap/CharacterSearchWindow.gml b/Userland/Applications/CharacterMap/CharacterSearchWindow.gml
index aa7079a097..4024dca2ea 100644
--- a/Userland/Applications/CharacterMap/CharacterSearchWindow.gml
+++ b/Userland/Applications/CharacterMap/CharacterSearchWindow.gml
@@ -15,7 +15,7 @@
}
}
- @GUI::ListView {
- name: "results_list"
+ @GUI::TableView {
+ name: "results_table"
}
}