/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include namespace GUI { static Vector supported_emoji_code_points() { Vector code_points; Core::DirIterator dt("/res/emoji", Core::DirIterator::SkipDots); while (dt.has_next()) { auto filename = dt.next_path(); auto lexical_path = LexicalPath(filename); if (lexical_path.extension() != "png") continue; auto& basename = lexical_path.basename(); if (!basename.starts_with("U+")) continue; u32 code_point = strtoul(basename.to_string().characters() + 2, nullptr, 16); code_points.append(code_point); } return code_points; } EmojiInputDialog::EmojiInputDialog(Window* parent_window) : Dialog(parent_window) { set_frameless(true); auto& main_widget = set_main_widget(); main_widget.set_frame_shape(Gfx::FrameShape::Container); main_widget.set_frame_shadow(Gfx::FrameShadow::Raised); main_widget.set_fill_with_background_color(true); auto& main_layout = main_widget.set_layout(); main_layout.set_margins({ 1, 1, 1, 1 }); main_layout.set_spacing(0); auto code_points = supported_emoji_code_points(); size_t index = 0; size_t columns = 6; size_t rows = ceil_div(code_points.size(), columns); for (size_t row = 0; row < rows && index < code_points.size(); ++row) { auto& horizontal_container = main_widget.add(); auto& horizontal_layout = horizontal_container.set_layout(); horizontal_layout.set_spacing(0); for (size_t column = 0; column < columns; ++column) { if (index < code_points.size()) { StringBuilder builder; builder.append(Utf32View(&code_points[index++], 1)); auto emoji_text = builder.to_string(); auto& button = horizontal_container.add