mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibGUI: Adjust size and layout of InputBox
Increases default dimensions of InputBox, giving it slightly more divine proportions. Prompt text now always appears above the editor.
This commit is contained in:
parent
f3a6da580f
commit
a03fb66216
Notes:
sideshowbarker
2024-07-17 05:05:51 +09:00
Author: https://github.com/thankyouverycool Commit: https://github.com/SerenityOS/serenity/commit/a03fb66216 Pull-request: https://github.com/SerenityOS/serenity/pull/18988
1 changed files with 20 additions and 34 deletions
|
@ -128,47 +128,35 @@ void InputBox::on_done(ExecResult result)
|
||||||
ErrorOr<void> InputBox::build()
|
ErrorOr<void> InputBox::build()
|
||||||
{
|
{
|
||||||
auto main_widget = TRY(set_main_widget<Widget>());
|
auto main_widget = TRY(set_main_widget<Widget>());
|
||||||
TRY(main_widget->try_set_layout<VerticalBoxLayout>(4, 6));
|
TRY(main_widget->try_set_layout<VerticalBoxLayout>(6, 6));
|
||||||
main_widget->set_fill_with_background_color(true);
|
main_widget->set_fill_with_background_color(true);
|
||||||
|
|
||||||
auto top_container = TRY(main_widget->try_add<Widget>());
|
|
||||||
TRY(top_container->try_set_layout<HorizontalBoxLayout>(0, 8));
|
|
||||||
|
|
||||||
if (m_icon) {
|
|
||||||
auto image_widget = TRY(top_container->try_add<ImageWidget>());
|
|
||||||
image_widget->set_bitmap(m_icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto input_container = TRY(top_container->try_add<Widget>());
|
|
||||||
auto orientation = m_icon ? Gfx::Orientation::Vertical : Gfx::Orientation::Horizontal;
|
|
||||||
TRY(input_container->try_set_layout<BoxLayout>(orientation));
|
|
||||||
TRY(input_container->add_spacer());
|
|
||||||
|
|
||||||
if (!m_prompt.is_empty()) {
|
if (!m_prompt.is_empty()) {
|
||||||
m_label_container = TRY(input_container->try_add<Widget>());
|
auto prompt_container = TRY(main_widget->try_add<Widget>());
|
||||||
TRY(m_label_container->try_set_layout<HorizontalBoxLayout>());
|
TRY(prompt_container->try_set_layout<HorizontalBoxLayout>(0, 8));
|
||||||
m_prompt_label = TRY(m_label_container->try_add<Label>());
|
if (m_icon) {
|
||||||
|
auto image_widget = TRY(prompt_container->try_add<ImageWidget>());
|
||||||
|
image_widget->set_bitmap(m_icon);
|
||||||
|
}
|
||||||
|
m_prompt_label = TRY(prompt_container->try_add<Label>());
|
||||||
m_prompt_label->set_autosize(true);
|
m_prompt_label->set_autosize(true);
|
||||||
m_prompt_label->set_text_wrapping(Gfx::TextWrapping::DontWrap);
|
m_prompt_label->set_text_wrapping(Gfx::TextWrapping::DontWrap);
|
||||||
m_prompt_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
m_prompt_label->set_text(m_prompt);
|
||||||
m_prompt_label->set_text(move(m_prompt));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_input_type) {
|
switch (m_input_type) {
|
||||||
case InputType::Text:
|
case InputType::Text:
|
||||||
case InputType::NonemptyText:
|
case InputType::NonemptyText:
|
||||||
m_text_editor = TRY(input_container->try_add<TextBox>());
|
m_text_editor = TRY(main_widget->try_add<TextBox>());
|
||||||
break;
|
break;
|
||||||
case InputType::Password:
|
case InputType::Password:
|
||||||
m_text_editor = TRY(input_container->try_add<PasswordBox>());
|
m_text_editor = TRY(main_widget->try_add<PasswordBox>());
|
||||||
break;
|
break;
|
||||||
case InputType::Numeric:
|
case InputType::Numeric:
|
||||||
m_spinbox = TRY(input_container->try_add<SpinBox>());
|
m_spinbox = TRY(main_widget->try_add<SpinBox>());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY(input_container->add_spacer());
|
|
||||||
|
|
||||||
auto button_container = TRY(main_widget->try_add<Widget>());
|
auto button_container = TRY(main_widget->try_add<Widget>());
|
||||||
TRY(button_container->try_set_layout<HorizontalBoxLayout>(0, 6));
|
TRY(button_container->try_set_layout<HorizontalBoxLayout>(0, 6));
|
||||||
TRY(button_container->add_spacer());
|
TRY(button_container->add_spacer());
|
||||||
|
@ -184,17 +172,15 @@ ErrorOr<void> InputBox::build()
|
||||||
m_cancel_button = TRY(button_container->try_add<DialogButton>("Cancel"_short_string));
|
m_cancel_button = TRY(button_container->try_add<DialogButton>("Cancel"_short_string));
|
||||||
m_cancel_button->on_click = [this](auto) { done(ExecResult::Cancel); };
|
m_cancel_button->on_click = [this](auto) { done(ExecResult::Cancel); };
|
||||||
|
|
||||||
auto resize_editor = [this, button_container] {
|
auto guarantee_width = [this, button_container] {
|
||||||
auto width = button_container->effective_min_size().width().as_int();
|
if (m_prompt.is_empty())
|
||||||
if (m_text_editor)
|
return;
|
||||||
m_text_editor->set_min_width(width);
|
auto width = button_container->calculated_min_size().value().width().as_int();
|
||||||
if (m_spinbox)
|
auto constexpr golden_ratio = 1.618;
|
||||||
m_spinbox->set_min_width(width);
|
button_container->set_min_width(width * golden_ratio);
|
||||||
if (!m_icon && m_label_container)
|
|
||||||
m_label_container->set_fixed_width(m_prompt_label->max_width());
|
|
||||||
};
|
};
|
||||||
resize_editor();
|
guarantee_width();
|
||||||
on_font_change = [resize_editor] { resize_editor(); };
|
on_font_change = [guarantee_width] { guarantee_width(); };
|
||||||
|
|
||||||
if (m_text_editor) {
|
if (m_text_editor) {
|
||||||
m_text_editor->set_text(m_text_value);
|
m_text_editor->set_text(m_text_value);
|
||||||
|
|
Loading…
Reference in a new issue