Serenity Operating System
at hosted 128 lines 5.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <LibCore/Timer.h> 28#include <LibGUI/Application.h> 29#include <LibGUI/BoxLayout.h> 30#include <LibGUI/Button.h> 31#include <LibGUI/CheckBox.h> 32#include <LibGUI/GroupBox.h> 33#include <LibGUI/Label.h> 34#include <LibGUI/ProgressBar.h> 35#include <LibGUI/RadioButton.h> 36#include <LibGUI/ScrollBar.h> 37#include <LibGUI/Slider.h> 38#include <LibGUI/SpinBox.h> 39#include <LibGUI/TextBox.h> 40#include <LibGUI/Widget.h> 41#include <LibGUI/Window.h> 42 43int main(int argc, char** argv) 44{ 45 GUI::Application app(argc, argv); 46 47 auto window = GUI::Window::construct(); 48 window->set_rect(100, 100, 320, 620); 49 window->set_title("Widget Gallery"); 50 51 auto& main_widget = window->set_main_widget<GUI::Widget>(); 52 main_widget.set_fill_with_background_color(true); 53 main_widget.set_layout<GUI::VerticalBoxLayout>(); 54 main_widget.layout()->set_margins({ 4, 4, 4, 4 }); 55 56 auto& checkbox1 = main_widget.add<GUI::CheckBox>("CheckBox 1"); 57 (void)checkbox1; 58 auto& checkbox2 = main_widget.add<GUI::CheckBox>("CheckBox 2"); 59 checkbox2.set_enabled(false); 60 61 auto& radio1 = main_widget.add<GUI::RadioButton>("RadioButton 1"); 62 (void)radio1; 63 auto& radio2 = main_widget.add<GUI::RadioButton>("RadioButton 2"); 64 radio2.set_enabled(false); 65 66 auto& button1 = main_widget.add<GUI::Button>("Button 1"); 67 (void)button1; 68 auto& button2 = main_widget.add<GUI::Button>("Button 2"); 69 button2.set_enabled(false); 70 71 auto& progress1 = main_widget.add<GUI::ProgressBar>(); 72 progress1.add<Core::Timer>(100, [&] { 73 progress1.set_value(progress1.value() + 1); 74 if (progress1.value() == progress1.max()) 75 progress1.set_value(progress1.min()); 76 }); 77 78 auto& label1 = main_widget.add<GUI::Label>("Label 1"); 79 (void)label1; 80 auto& label2 = main_widget.add<GUI::Label>("Label 2"); 81 label2.set_enabled(false); 82 83 auto& textbox1 = main_widget.add<GUI::TextBox>(); 84 textbox1.set_text("TextBox 1"); 85 auto& textbox2 = main_widget.add<GUI::TextBox>(); 86 textbox2.set_text("TextBox 2"); 87 textbox2.set_enabled(false); 88 89 auto& spinbox1 = main_widget.add<GUI::SpinBox>(); 90 (void)spinbox1; 91 auto& spinbox2 = main_widget.add<GUI::SpinBox>(); 92 spinbox2.set_enabled(false); 93 94 auto& vertical_slider_container = main_widget.add<GUI::Widget>(); 95 vertical_slider_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); 96 vertical_slider_container.set_preferred_size(0, 100); 97 vertical_slider_container.set_layout<GUI::HorizontalBoxLayout>(); 98 auto& vslider1 = vertical_slider_container.add<GUI::VerticalSlider>(); 99 (void)vslider1; 100 auto& vslider2 = vertical_slider_container.add<GUI::VerticalSlider>(); 101 vslider2.set_enabled(false); 102 auto& vslider3 = vertical_slider_container.add<GUI::VerticalSlider>(); 103 vslider3.set_max(5); 104 vslider3.set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); 105 106 auto& slider1 = main_widget.add<GUI::HorizontalSlider>(); 107 (void)slider1; 108 auto& slider2 = main_widget.add<GUI::HorizontalSlider>(); 109 slider2.set_enabled(false); 110 auto& slider3 = main_widget.add<GUI::HorizontalSlider>(); 111 slider3.set_max(5); 112 slider3.set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional); 113 114 auto& scrollbar1 = main_widget.add<GUI::ScrollBar>(Orientation::Horizontal); 115 scrollbar1.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); 116 scrollbar1.set_preferred_size(0, 16); 117 scrollbar1.set_min(0); 118 scrollbar1.set_max(100); 119 scrollbar1.set_value(50); 120 auto& scrollbar2 = main_widget.add<GUI::ScrollBar>(Orientation::Horizontal); 121 scrollbar2.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); 122 scrollbar2.set_preferred_size(0, 16); 123 scrollbar2.set_enabled(false); 124 125 window->show(); 126 127 return app.exec(); 128}