summaryrefslogtreecommitdiff
path: root/Demos/WidgetGallery/main.cpp
blob: bc5a85f20bd8a48375578385d96bc7f75e848585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <LibCore/CTimer.h>
#include <LibGUI/GApplication.h>
#include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h>
#include <LibGUI/GCheckBox.h>
#include <LibGUI/GGroupBox.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GProgressBar.h>
#include <LibGUI/GRadioButton.h>
#include <LibGUI/GScrollBar.h>
#include <LibGUI/GSlider.h>
#include <LibGUI/GSpinBox.h>
#include <LibGUI/GTextBox.h>
#include <LibGUI/GWidget.h>
#include <LibGUI/GWindow.h>

int main(int argc, char** argv)
{
    GUI::Application app(argc, argv);

    auto window = GUI::Window::construct();
    window->set_rect(100, 100, 320, 620);
    window->set_title("Widget Gallery");

    auto main_widget = GUI::Widget::construct();
    window->set_main_widget(main_widget);
    main_widget->set_fill_with_background_color(true);
    main_widget->set_layout(make<GUI::VBoxLayout>());
    main_widget->layout()->set_margins({ 4, 4, 4, 4 });

    auto checkbox1 = GUI::CheckBox::construct("GCheckBox 1", main_widget);
    (void)checkbox1;
    auto checkbox2 = GUI::CheckBox::construct("GCheckBox 2", main_widget);
    checkbox2->set_enabled(false);

    auto radio1 = GUI::RadioButton::construct("GRadioButton 1", main_widget);
    (void)radio1;
    auto radio2 = GUI::RadioButton::construct("GRadioButton 2", main_widget);
    radio2->set_enabled(false);

    auto button1 = GUI::Button::construct("GButton 1", main_widget);
    (void)button1;
    auto button2 = GUI::Button::construct("GButton 2", main_widget);
    button2->set_enabled(false);

    auto progress1 = GUI::ProgressBar::construct(main_widget);
    auto timer = Core::Timer::construct(100, [&] {
        progress1->set_value(progress1->value() + 1);
        if (progress1->value() == progress1->max())
            progress1->set_value(progress1->min());
    });

    auto label1 = GUI::Label::construct("GLabel 1", main_widget);
    (void)label1;
    auto label2 = GUI::Label::construct("GLabel 2", main_widget);
    label2->set_enabled(false);

    auto textbox1 = GUI::TextBox::construct(main_widget);
    textbox1->set_text("GTextBox 1");
    auto textbox2 = GUI::TextBox::construct(main_widget);
    textbox2->set_text("GTextBox 2");
    textbox2->set_enabled(false);

    auto spinbox1 = GUI::SpinBox::construct(main_widget);
    (void)spinbox1;
    auto spinbox2 = GUI::SpinBox::construct(main_widget);
    spinbox2->set_enabled(false);

    auto vertical_slider_container = GUI::Widget::construct(main_widget.ptr());
    vertical_slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
    vertical_slider_container->set_preferred_size(0, 100);
    vertical_slider_container->set_layout(make<GUI::HBoxLayout>());
    auto vslider1 = GUI::Slider::construct(Orientation::Vertical, vertical_slider_container);
    (void)vslider1;
    auto vslider2 = GUI::Slider::construct(Orientation::Vertical, vertical_slider_container);
    vslider2->set_enabled(false);
    auto vslider3 = GUI::Slider::construct(Orientation::Vertical, vertical_slider_container);
    vslider3->set_max(5);
    vslider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional);

    auto slider1 = GUI::Slider::construct(Orientation::Horizontal, main_widget);
    (void)slider1;
    auto slider2 = GUI::Slider::construct(Orientation::Horizontal, main_widget);
    slider2->set_enabled(false);
    auto slider3 = GUI::Slider::construct(Orientation::Horizontal, main_widget);
    slider3->set_max(5);
    slider3->set_knob_size_mode(GUI::Slider::KnobSizeMode::Proportional);

    auto scrollbar1 = GUI::ScrollBar::construct(Orientation::Horizontal, main_widget);
    scrollbar1->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
    scrollbar1->set_preferred_size(0, 16);
    scrollbar1->set_min(0);
    scrollbar1->set_max(100);
    scrollbar1->set_value(50);
    auto scrollbar2 = GUI::ScrollBar::construct(Orientation::Horizontal, main_widget);
    scrollbar2->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
    scrollbar2->set_preferred_size(0, 16);
    scrollbar2->set_enabled(false);

    window->show();

    return app.exec();
}