mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +00:00
LibGUI/EmojiInputDialog: Automatically calculate the dialog size
This was getting way too crowded again. Let's just fix the FIXME. :^)
This commit is contained in:
parent
2e49368b28
commit
8b790c4ff8
1 changed files with 11 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -38,10 +39,6 @@ static Vector<u32> supported_emoji_code_points()
|
||||||
EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
||||||
: Dialog(parent_window)
|
: Dialog(parent_window)
|
||||||
{
|
{
|
||||||
// FIXME: Dialog should automatically adjust to content
|
|
||||||
set_minimum_size(190, 190);
|
|
||||||
set_frameless(true);
|
|
||||||
|
|
||||||
auto& main_widget = set_main_widget<Frame>();
|
auto& main_widget = set_main_widget<Frame>();
|
||||||
main_widget.set_frame_shape(Gfx::FrameShape::Container);
|
main_widget.set_frame_shape(Gfx::FrameShape::Container);
|
||||||
main_widget.set_frame_shadow(Gfx::FrameShadow::Raised);
|
main_widget.set_frame_shadow(Gfx::FrameShadow::Raised);
|
||||||
|
@ -56,6 +53,15 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
||||||
size_t columns = 10;
|
size_t columns = 10;
|
||||||
size_t rows = ceil_div(code_points.size(), columns);
|
size_t rows = ceil_div(code_points.size(), columns);
|
||||||
|
|
||||||
|
constexpr int button_size = 18;
|
||||||
|
// FIXME: I have no idea why this is needed, you'd think that button width * number of buttons would make them fit, but the last one gets cut off.
|
||||||
|
constexpr int magic_offset = 7;
|
||||||
|
int dialog_width = button_size * columns + magic_offset;
|
||||||
|
int dialog_height = button_size * rows;
|
||||||
|
|
||||||
|
set_minimum_size(dialog_width, dialog_height);
|
||||||
|
set_frameless(true);
|
||||||
|
|
||||||
for (size_t row = 0; row < rows && index < code_points.size(); ++row) {
|
for (size_t row = 0; row < rows && index < code_points.size(); ++row) {
|
||||||
auto& horizontal_container = main_widget.add<Widget>();
|
auto& horizontal_container = main_widget.add<Widget>();
|
||||||
auto& horizontal_layout = horizontal_container.set_layout<HorizontalBoxLayout>();
|
auto& horizontal_layout = horizontal_container.set_layout<HorizontalBoxLayout>();
|
||||||
|
@ -66,7 +72,7 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
|
||||||
builder.append(Utf32View(&code_points[index++], 1));
|
builder.append(Utf32View(&code_points[index++], 1));
|
||||||
auto emoji_text = builder.to_string();
|
auto emoji_text = builder.to_string();
|
||||||
auto& button = horizontal_container.add<Button>(emoji_text);
|
auto& button = horizontal_container.add<Button>(emoji_text);
|
||||||
button.set_fixed_size(18, 18);
|
button.set_fixed_size(button_size, button_size);
|
||||||
button.set_button_style(Gfx::ButtonStyle::Coolbar);
|
button.set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||||
button.on_click = [this, button = &button](auto) {
|
button.on_click = [this, button = &button](auto) {
|
||||||
m_selected_emoji_text = button->text();
|
m_selected_emoji_text = button->text();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue