1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:38:11 +00:00

LibGUI: Give some widgets a reasonable default fixed height

Instead of hard-coding 22 in random places, just make the following
widgets have a fixed height of 22 by default: Button, CheckBox,
ColorInput, ComboBox, RadioButton, SpinBox, TextBox.

In the future we can make this relative to the current font size,
but for now at least this centralizes the setting a bit better.
This commit is contained in:
Andreas Kling 2020-12-30 01:53:13 +01:00
parent 0f3b0b65ae
commit 1cca2405fc
17 changed files with 11 additions and 16 deletions

View file

@ -112,7 +112,6 @@ Tab::Tab(Type type)
toolbar.add_action(*m_reload_action); toolbar.add_action(*m_reload_action);
m_location_box = toolbar.add<GUI::TextBox>(); m_location_box = toolbar.add<GUI::TextBox>();
m_location_box->set_fixed_height(22);
m_location_box->set_placeholder("Address"); m_location_box->set_placeholder("Address");
m_location_box->on_return_pressed = [this] { m_location_box->on_return_pressed = [this] {

View file

@ -116,7 +116,6 @@ void DisplaySettingsWidget::create_frame()
wallpaper_label.set_text("Wallpaper:"); wallpaper_label.set_text("Wallpaper:");
m_wallpaper_combo = wallpaper_selection_container.add<GUI::ComboBox>(); m_wallpaper_combo = wallpaper_selection_container.add<GUI::ComboBox>();
m_wallpaper_combo->set_fixed_height(22);
m_wallpaper_combo->set_only_allow_values_from_model(true); m_wallpaper_combo->set_only_allow_values_from_model(true);
m_wallpaper_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_wallpapers)); m_wallpaper_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_wallpapers));
m_wallpaper_combo->on_change = [this](auto& text, const GUI::ModelIndex& index) { m_wallpaper_combo->on_change = [this](auto& text, const GUI::ModelIndex& index) {
@ -170,7 +169,6 @@ void DisplaySettingsWidget::create_frame()
mode_label.set_text("Mode:"); mode_label.set_text("Mode:");
m_mode_combo = mode_selection_container.add<GUI::ComboBox>(); m_mode_combo = mode_selection_container.add<GUI::ComboBox>();
m_mode_combo->set_fixed_height(22);
m_mode_combo->set_only_allow_values_from_model(true); m_mode_combo->set_only_allow_values_from_model(true);
m_mode_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_modes)); m_mode_combo->set_model(*GUI::ItemListModel<AK::String>::create(m_modes));
m_mode_combo->on_change = [this](auto&, const GUI::ModelIndex& index) { m_mode_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {
@ -190,7 +188,6 @@ void DisplaySettingsWidget::create_frame()
m_resolution_label.set_text("Resolution:"); m_resolution_label.set_text("Resolution:");
m_resolution_combo = resolution_selection_container.add<GUI::ComboBox>(); m_resolution_combo = resolution_selection_container.add<GUI::ComboBox>();
m_resolution_combo->set_fixed_height(22);
m_resolution_combo->set_only_allow_values_from_model(true); m_resolution_combo->set_only_allow_values_from_model(true);
m_resolution_combo->set_model(*GUI::ItemListModel<Gfx::IntSize>::create(m_resolutions)); m_resolution_combo->set_model(*GUI::ItemListModel<Gfx::IntSize>::create(m_resolutions));
m_resolution_combo->on_change = [this](auto&, const GUI::ModelIndex& index) { m_resolution_combo->on_change = [this](auto&, const GUI::ModelIndex& index) {

View file

@ -76,7 +76,6 @@ PropertiesDialog::PropertiesDialog(const String& path, bool disable_rename, Wind
m_parent_path = lexical_path.dirname(); m_parent_path = lexical_path.dirname();
m_name_box = file_container.add<GUI::TextBox>(); m_name_box = file_container.add<GUI::TextBox>();
m_name_box->set_fixed_height(22);
m_name_box->set_text(m_name); m_name_box->set_text(m_name);
m_name_box->set_mode(disable_rename ? GUI::TextBox::Mode::DisplayOnly : GUI::TextBox::Mode::Editable); m_name_box->set_mode(disable_rename ? GUI::TextBox::Mode::DisplayOnly : GUI::TextBox::Mode::Editable);
m_name_box->on_change = [&]() { m_name_box->on_change = [&]() {

View file

@ -72,7 +72,6 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
glyph_width_label.set_text("Glyph width:"); glyph_width_label.set_text("Glyph width:");
auto& glyph_width_spinbox = editor_container.add<GUI::SpinBox>(); auto& glyph_width_spinbox = editor_container.add<GUI::SpinBox>();
glyph_width_spinbox.set_fixed_height(22);
glyph_width_spinbox.set_min(0); glyph_width_spinbox.set_min(0);
glyph_width_spinbox.set_max(32); glyph_width_spinbox.set_max(32);
glyph_width_spinbox.set_value(0); glyph_width_spinbox.set_value(0);
@ -253,7 +252,6 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::Font>&& edite
//// Fixed checkbox Row //// Fixed checkbox Row
auto& fixed_width_checkbox = font_metadata_group_box.add<GUI::CheckBox>(); auto& fixed_width_checkbox = font_metadata_group_box.add<GUI::CheckBox>();
fixed_width_checkbox.set_fixed_height(22);
fixed_width_checkbox.set_text("Fixed width"); fixed_width_checkbox.set_text("Fixed width");
fixed_width_checkbox.set_checked(m_edited_font->is_fixed_width()); fixed_width_checkbox.set_checked(m_edited_font->is_fixed_width());

View file

@ -134,7 +134,6 @@ int main(int argc, char** argv)
character_map_file_label.set_text("Character Mapping File:"); character_map_file_label.set_text("Character Mapping File:");
auto& character_map_file_combo = character_map_file_selection_container.add<GUI::ComboBox>(); auto& character_map_file_combo = character_map_file_selection_container.add<GUI::ComboBox>();
character_map_file_combo.set_fixed_height(22);
character_map_file_combo.set_only_allow_values_from_model(true); character_map_file_combo.set_only_allow_values_from_model(true);
character_map_file_combo.set_model(*CharacterMapFileListModel::create(character_map_files)); character_map_file_combo.set_model(*CharacterMapFileListModel::create(character_map_files));
character_map_file_combo.set_selected_index(initial_keymap_index); character_map_file_combo.set_selected_index(initial_keymap_index);

View file

@ -299,9 +299,7 @@ static RefPtr<GUI::Window> create_find_window(TerminalWidget& terminal)
}; };
auto& match_case = search.add<GUI::CheckBox>("Case sensitive"); auto& match_case = search.add<GUI::CheckBox>("Case sensitive");
match_case.set_fixed_height(22);
auto& wrap_around = search.add<GUI::CheckBox>("Wrap around"); auto& wrap_around = search.add<GUI::CheckBox>("Wrap around");
wrap_around.set_fixed_height(22);
find_backwards.on_click = [&](auto) { find_backwards.on_click = [&](auto) {
auto needle = find_textbox.text(); auto needle = find_textbox.text();

View file

@ -68,7 +68,6 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv, [[maybe_unused
auto& button = main_widget.add<GUI::Button>(); auto& button = main_widget.add<GUI::Button>();
button.set_text("Good-bye"); button.set_text("Good-bye");
button.set_fixed_height(20);
button.on_click = [&](auto) { button.on_click = [&](auto) {
app->quit(); app->quit();
}; };

View file

@ -68,7 +68,6 @@ int main(int argc, char** argv)
auto& button = main_widget.add<GUI::Button>(); auto& button = main_widget.add<GUI::Button>();
button.set_text("Good-bye"); button.set_text("Good-bye");
button.set_fixed_height(20);
button.on_click = [&](auto) { button.on_click = [&](auto) {
app->quit(); app->quit();
}; };

View file

@ -175,9 +175,11 @@ int main(int argc, char** argv)
auto& checkbox2 = checkbox_container.add<GUI::CheckBox>("CheckBox 2"); auto& checkbox2 = checkbox_container.add<GUI::CheckBox>("CheckBox 2");
checkbox2.set_enabled(false); checkbox2.set_enabled(false);
[[maybe_unused]] auto& label1 = label_container.add<GUI::Label>("Label 1"); auto& label1 = label_container.add<GUI::Label>("Label 1");
label1.set_fixed_height(22);
auto& label2 = label_container.add<GUI::Label>("Label 2"); auto& label2 = label_container.add<GUI::Label>("Label 2");
label2.set_enabled(false); label2.set_enabled(false);
label2.set_fixed_height(22);
[[maybe_unused]] auto& spinbox1 = spin_container.add<GUI::SpinBox>(); [[maybe_unused]] auto& spinbox1 = spin_container.add<GUI::SpinBox>();
auto& spinbox2 = spin_container.add<GUI::SpinBox>(); auto& spinbox2 = spin_container.add<GUI::SpinBox>();
@ -424,7 +426,6 @@ int main(int argc, char** argv)
content_textbox.set_text("Demo text for message box."); content_textbox.set_text("Demo text for message box.");
auto& msgbox_button = msgbox_text_container.add<GUI::Button>("Create"); auto& msgbox_button = msgbox_text_container.add<GUI::Button>("Create");
msgbox_button.set_fixed_height(30);
msgbox_button.on_click = [&](auto) { msgbox_button.on_click = [&](auto) {
GUI::MessageBox::show(window, content_textbox.text(), title_textbox.text(), msg_box_type, msg_box_input_type); GUI::MessageBox::show(window, content_textbox.text(), title_textbox.text(), msg_box_type, msg_box_input_type);
}; };
@ -446,7 +447,6 @@ int main(int argc, char** argv)
input_button_container.layout()->set_margins({ 4, 0, 4, 0 }); input_button_container.layout()->set_margins({ 4, 0, 4, 0 });
auto& input_button = input_button_container.add<GUI::Button>("Input..."); auto& input_button = input_button_container.add<GUI::Button>("Input...");
input_button.set_fixed_height(30);
String value; String value;
input_button.on_click = [&](auto) { input_button.on_click = [&](auto) {
if (GUI::InputBox::show(value, window, "Enter input:", "Input Box") == GUI::InputBox::ExecOK && !value.is_empty()) if (GUI::InputBox::show(value, window, "Enter input:", "Input Box") == GUI::InputBox::ExecOK && !value.is_empty())

View file

@ -38,6 +38,7 @@ namespace GUI {
Button::Button(String text) Button::Button(String text)
: AbstractButton(move(text)) : AbstractButton(move(text))
{ {
set_fixed_height(22);
set_focus_policy(GUI::FocusPolicy::StrongFocus); set_focus_policy(GUI::FocusPolicy::StrongFocus);
} }

View file

@ -39,6 +39,7 @@ static const int s_box_height = 13;
CheckBox::CheckBox(String text) CheckBox::CheckBox(String text)
: AbstractButton(move(text)) : AbstractButton(move(text))
{ {
set_fixed_height(22);
} }
CheckBox::~CheckBox() CheckBox::~CheckBox()

View file

@ -35,6 +35,7 @@ namespace GUI {
ColorInput::ColorInput() ColorInput::ColorInput()
: TextEditor(TextEditor::SingleLine) : TextEditor(TextEditor::SingleLine)
{ {
set_fixed_height(22);
TextEditor::on_change = [this] { TextEditor::on_change = [this] {
auto parsed_color = Color::from_string(text()); auto parsed_color = Color::from_string(text());
if (parsed_color.has_value()) if (parsed_color.has_value())

View file

@ -58,6 +58,8 @@ private:
ComboBox::ComboBox() ComboBox::ComboBox()
{ {
set_fixed_height(22);
m_editor = add<ComboBoxEditor>(); m_editor = add<ComboBoxEditor>();
m_editor->set_frame_thickness(0); m_editor->set_frame_thickness(0);
m_editor->on_return_pressed = [this] { m_editor->on_return_pressed = [this] {

View file

@ -113,7 +113,6 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
toolbar.set_has_frame(false); toolbar.set_has_frame(false);
m_location_textbox = upper_container.add<TextBox>(); m_location_textbox = upper_container.add<TextBox>();
m_location_textbox->set_fixed_height(22);
m_location_textbox->set_text(path); m_location_textbox->set_text(path);
m_view = vertical_container.add<MultiView>(); m_view = vertical_container.add<MultiView>();

View file

@ -36,6 +36,7 @@ namespace GUI {
RadioButton::RadioButton(String text) RadioButton::RadioButton(String text)
: AbstractButton(move(text)) : AbstractButton(move(text))
{ {
set_fixed_height(22);
} }
RadioButton::~RadioButton() RadioButton::~RadioButton()

View file

@ -32,6 +32,7 @@ namespace GUI {
SpinBox::SpinBox() SpinBox::SpinBox()
{ {
set_fixed_height(22);
m_editor = add<TextBox>(); m_editor = add<TextBox>();
m_editor->set_text("0"); m_editor->set_text("0");
m_editor->on_change = [this] { m_editor->on_change = [this] {

View file

@ -31,6 +31,7 @@ namespace GUI {
TextBox::TextBox() TextBox::TextBox()
: TextEditor(TextEditor::SingleLine) : TextEditor(TextEditor::SingleLine)
{ {
set_fixed_height(22);
} }
TextBox::~TextBox() TextBox::~TextBox()