diff --git a/Libraries/LibGUI/CMakeLists.txt b/Libraries/LibGUI/CMakeLists.txt index 3dab0a2460..36c55e25ff 100644 --- a/Libraries/LibGUI/CMakeLists.txt +++ b/Libraries/LibGUI/CMakeLists.txt @@ -21,6 +21,7 @@ set(SOURCES Dialog.cpp DisplayLink.cpp DragOperation.cpp + EmojiInputDialog.cpp Event.cpp FilePicker.cpp FileSystemModel.cpp diff --git a/Libraries/LibGUI/EmojiInputDialog.cpp b/Libraries/LibGUI/EmojiInputDialog.cpp new file mode 100644 index 0000000000..3a29ddc21c --- /dev/null +++ b/Libraries/LibGUI/EmojiInputDialog.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace GUI { + +static Vector supported_emoji_codepoints() +{ + Vector codepoints; + Core::DirIterator dt("/res/emoji", Core::DirIterator::SkipDots); + while (dt.has_next()) { + auto filename = dt.next_path(); + auto fspath = FileSystemPath(filename); + if (fspath.extension() != "png") + continue; + auto basename = fspath.basename(); + if (!basename.starts_with("U+")) + continue; + u32 codepoint = strtoul(basename.characters() + 2, nullptr, 16); + codepoints.append(codepoint); + } + return codepoints; +} + +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_spacing(0); + + auto codepoints = supported_emoji_codepoints(); + + size_t index = 0; + size_t columns = 5; + size_t rows = ceil_div(codepoints.size(), columns); + + for (size_t row = 0; row < rows && index < codepoints.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) { + StringBuilder builder; + builder.append(Utf32View(&codepoints[index++], 1)); + auto emoji_text = builder.to_string(); + auto& button = horizontal_container.add