Serenity Operating System
at master 76 lines 2.4 kB view raw
1/* 2 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include "CreateNewLayerDialog.h" 8#include <LibGUI/BoxLayout.h> 9#include <LibGUI/Button.h> 10#include <LibGUI/Label.h> 11#include <LibGUI/SpinBox.h> 12#include <LibGUI/TextBox.h> 13 14namespace PixelPaint { 15 16CreateNewLayerDialog::CreateNewLayerDialog(Gfx::IntSize suggested_size, GUI::Window* parent_window) 17 : Dialog(parent_window) 18{ 19 set_title("Create new layer"); 20 set_icon(parent_window->icon()); 21 resize(200, 200); 22 23 auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors(); 24 main_widget->set_fill_with_background_color(true); 25 main_widget->set_layout<GUI::VerticalBoxLayout>(4); 26 27 auto& name_label = main_widget->add<GUI::Label>("Name:"); 28 name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); 29 30 m_name_textbox = main_widget->add<GUI::TextBox>(); 31 m_name_textbox->set_text("Layer"sv); 32 m_name_textbox->select_all(); 33 m_name_textbox->on_change = [this] { 34 m_layer_name = m_name_textbox->text(); 35 }; 36 37 auto& width_label = main_widget->add<GUI::Label>("Width:"); 38 width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); 39 40 auto& width_spinbox = main_widget->add<GUI::SpinBox>(); 41 42 auto& height_label = main_widget->add<GUI::Label>("Height:"); 43 height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); 44 45 auto& height_spinbox = main_widget->add<GUI::SpinBox>(); 46 47 auto& button_container = main_widget->add<GUI::Widget>(); 48 button_container.set_layout<GUI::HorizontalBoxLayout>(); 49 50 auto& ok_button = button_container.add<GUI::Button>("OK"_short_string); 51 ok_button.on_click = [this](auto) { 52 done(ExecResult::OK); 53 }; 54 ok_button.set_default(true); 55 56 auto& cancel_button = button_container.add<GUI::Button>("Cancel"_short_string); 57 cancel_button.on_click = [this](auto) { 58 done(ExecResult::Cancel); 59 }; 60 61 width_spinbox.on_change = [this](int value) { 62 m_layer_size.set_width(value); 63 }; 64 65 height_spinbox.on_change = [this](int value) { 66 m_layer_size.set_height(value); 67 }; 68 69 width_spinbox.set_range(1, 16384); 70 height_spinbox.set_range(1, 16384); 71 72 width_spinbox.set_value(suggested_size.width()); 73 height_spinbox.set_value(suggested_size.height()); 74} 75 76}