diff options
4 files changed, 58 insertions, 17 deletions
diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp index 19e46f66a3..3437b62816 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp @@ -17,7 +17,9 @@ #include <LibGUI/FontPicker.h> #include <LibGUI/Icon.h> #include <LibGUI/InputBox.h> +#include <LibGUI/ItemListModel.h> #include <LibGUI/Label.h> +#include <LibGUI/ListView.h> #include <LibGUI/Menu.h> #include <LibGUI/TextBox.h> #include <LibGUI/Toolbar.h> @@ -33,6 +35,7 @@ CharacterMapWidget::CharacterMapWidget() m_output_box = find_descendant_of_type_named<GUI::TextBox>("output_box"); m_copy_output_button = find_descendant_of_type_named<GUI::Button>("copy_output_button"); m_statusbar = find_descendant_of_type_named<GUI::Statusbar>("statusbar"); + m_unicode_block_listview = find_descendant_of_type_named<GUI::ListView>("unicode_block_listview"); m_choose_font_action = GUI::Action::create("Choose Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { auto font_picker = GUI::FontPicker::construct(window(), &font(), false); @@ -71,7 +74,8 @@ CharacterMapWidget::CharacterMapWidget() auto maybe_code_point = AK::StringUtils::convert_to_uint_from_hex(input); if (!maybe_code_point.has_value()) return; - auto code_point = clamp(maybe_code_point.value(), 0x0000, 0x10FFFF); + auto code_point = maybe_code_point.value(); + code_point = clamp(code_point, m_range.first, m_range.last); m_glyph_map->set_focus(true); m_glyph_map->set_active_glyph(code_point); m_glyph_map->scroll_to_glyph(code_point); @@ -120,6 +124,25 @@ CharacterMapWidget::CharacterMapWidget() GUI::Clipboard::the().set_plain_text(m_output_box->text()); }; + 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->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_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); + did_change_font(); update_statusbar(); } diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.h b/Userland/Applications/CharacterMap/CharacterMapWidget.h index 5775536d1a..3d82a18c1d 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.h +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.h @@ -32,6 +32,8 @@ private: RefPtr<GUI::Button> m_copy_output_button; RefPtr<GUI::Statusbar> m_statusbar; RefPtr<GUI::Window> m_find_window; + RefPtr<GUI::ListView> m_unicode_block_listview; + RefPtr<GUI::Model> m_unicode_block_model; RefPtr<GUI::Action> m_choose_font_action; RefPtr<GUI::Action> m_copy_selection_action; @@ -39,4 +41,7 @@ private: RefPtr<GUI::Action> m_next_glyph_action; RefPtr<GUI::Action> m_go_to_glyph_action; RefPtr<GUI::Action> m_find_glyphs_action; + + Vector<String> m_unicode_block_list; + Unicode::CodePointRange m_range { 0x0000, 0x10FFFF }; }; diff --git a/Userland/Applications/CharacterMap/CharacterMapWindow.gml b/Userland/Applications/CharacterMap/CharacterMapWindow.gml index 6b82aeba65..4ebde6900d 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWindow.gml +++ b/Userland/Applications/CharacterMap/CharacterMapWindow.gml @@ -29,25 +29,38 @@ } } - @GUI::GlyphMapWidget { - name: "glyph_map" - } + @GUI::HorizontalSplitter { - @GUI::Widget { - shrink_to_fit: true - layout: @GUI::HorizontalBoxLayout { - spacing: 4 - margins: [0, 2, 0, 2] - } + @GUI::Widget { + layout: @GUI::VerticalBoxLayout { + } - @GUI::TextBox { - name: "output_box" + @GUI::GlyphMapWidget { + name: "glyph_map" + } + + @GUI::Widget { + shrink_to_fit: true + layout: @GUI::HorizontalBoxLayout { + spacing: 4 + margins: [0, 2, 0, 2] + } + + @GUI::TextBox { + name: "output_box" + } + + @GUI::Button { + name: "copy_output_button" + icon: "/res/icons/16x16/edit-copy.png" + fixed_width: 22 + } + } } - @GUI::Button { - name: "copy_output_button" - icon: "/res/icons/16x16/edit-copy.png" - fixed_width: 22 + @GUI::ListView { + max_width: 175 + name: "unicode_block_listview" } } diff --git a/Userland/Applications/CharacterMap/main.cpp b/Userland/Applications/CharacterMap/main.cpp index c2f238ab95..bbedd60a3f 100644 --- a/Userland/Applications/CharacterMap/main.cpp +++ b/Userland/Applications/CharacterMap/main.cpp @@ -66,7 +66,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto window = TRY(GUI::Window::try_create()); window->set_title("Character Map"); window->set_icon(app_icon.bitmap_for_size(16)); - window->resize(400, 400); + window->resize(600, 400); auto character_map_widget = TRY(window->try_set_main_widget<CharacterMapWidget>()); character_map_widget->initialize_menubar(*window); |