LibGUI: Add an emoji category filter for SerenityOS custom emojis

Most of the emoji are 7x10px (or close to that). But some are larger, on
the order of 128x128px. The icon used for the SerenityOS category is one
such large emoji, and must be scaled down to an appropriate size for
rendering.
This commit is contained in:
Timothy Flynn 2022-09-09 11:40:46 -04:00 committed by Linus Groh
parent 4cb9472f97
commit a2eb42a9c0
Notes: sideshowbarker 2024-07-17 21:11:12 +09:00

View File

@ -42,8 +42,22 @@ static constexpr auto s_emoji_groups = Array {
EmojiCateogry { Unicode::EmojiGroup::Objects, "/res/emoji/U+1F4E6.png"sv },
EmojiCateogry { Unicode::EmojiGroup::Symbols, "/res/emoji/U+2764.png"sv },
EmojiCateogry { Unicode::EmojiGroup::Flags, "/res/emoji/U+1F6A9.png"sv },
EmojiCateogry { Unicode::EmojiGroup::SerenityOS, "/res/emoji/U+10CD0B.png"sv },
};
static void resize_bitmap_if_needed(NonnullRefPtr<Gfx::Bitmap>& bitmap)
{
constexpr int max_icon_size = 12;
if ((bitmap->width() > max_icon_size) || (bitmap->height() > max_icon_size)) {
auto x_ratio = static_cast<float>(max_icon_size) / static_cast<float>(bitmap->width());
auto y_ratio = static_cast<float>(max_icon_size) / static_cast<float>(bitmap->height());
auto ratio = min(x_ratio, y_ratio);
bitmap = bitmap->scaled(ratio, ratio).release_value_but_fixme_should_propagate_errors();
}
}
EmojiInputDialog::EmojiInputDialog(Window* parent_window)
: Dialog(parent_window)
, m_category_action_group(make<ActionGroup>())
@ -70,7 +84,9 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
for (auto const& category : s_emoji_groups) {
auto name = Unicode::emoji_group_to_string(category.group);
auto tooltip = name.replace("&"sv, "&&"sv, ReplaceMode::FirstOnly);
auto bitmap = Gfx::Bitmap::try_load_from_file(category.emoji).release_value_but_fixme_should_propagate_errors();
resize_bitmap_if_needed(bitmap);
auto set_filter_action = Action::create_checkable(
tooltip, bitmap, [this, group = category.group](auto& action) {