mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:27:35 +00:00
CharacterMap: Add a ListView to sort glyphs by their Unicode block
This commit is contained in:
parent
170afc2f47
commit
6704bc0072
4 changed files with 59 additions and 18 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
|
@ -29,6 +29,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
@GUI::HorizontalSplitter {
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
}
|
||||
|
||||
@GUI::GlyphMapWidget {
|
||||
name: "glyph_map"
|
||||
}
|
||||
|
@ -50,6 +56,13 @@
|
|||
fixed_width: 22
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::ListView {
|
||||
max_width: 175
|
||||
name: "unicode_block_listview"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Statusbar {
|
||||
name: "statusbar"
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue