diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-24 22:47:01 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-24 22:47:41 +0200 |
commit | 149b7f92a7d22f4e472fe2b30f8652792439bec2 (patch) | |
tree | 459ac9c3588ccab3f0101e8be2285a264f60531c | |
parent | d0bc21b96ffbe01913fcde072d475e864fa432e3 (diff) | |
download | serenity-149b7f92a7d22f4e472fe2b30f8652792439bec2.zip |
Demos: Start working on a simple WidgetGallery app.
It's good to have a place where we can try out all the different widgets.
This needs some more work on a nice layout, and should also include more
of the widgets. :^)
-rw-r--r-- | Demos/WidgetGallery/.gitignore | 3 | ||||
-rw-r--r-- | Demos/WidgetGallery/Makefile | 22 | ||||
-rw-r--r-- | Demos/WidgetGallery/main.cpp | 82 | ||||
-rwxr-xr-x | Kernel/makeall.sh | 1 | ||||
-rwxr-xr-x | Kernel/sync.sh | 2 | ||||
-rw-r--r-- | LibGUI/GButton.cpp | 5 | ||||
-rw-r--r-- | LibGUI/GButton.h | 1 | ||||
-rw-r--r-- | LibGUI/GCheckBox.cpp | 12 | ||||
-rw-r--r-- | LibGUI/GCheckBox.h | 1 |
9 files changed, 126 insertions, 3 deletions
diff --git a/Demos/WidgetGallery/.gitignore b/Demos/WidgetGallery/.gitignore new file mode 100644 index 0000000000..98d9ec1619 --- /dev/null +++ b/Demos/WidgetGallery/.gitignore @@ -0,0 +1,3 @@ +*.o +*.d +WidgetGallery diff --git a/Demos/WidgetGallery/Makefile b/Demos/WidgetGallery/Makefile new file mode 100644 index 0000000000..f7f87cbc57 --- /dev/null +++ b/Demos/WidgetGallery/Makefile @@ -0,0 +1,22 @@ +include ../../Makefile.common + +OBJS = \ + main.o + +APP = WidgetGallery + +DEFINES += -DUSERLAND + +all: $(APP) + +$(APP): $(OBJS) + $(LD) -o $(APP) $(LDFLAGS) $(OBJS) -lgui -lcore -lc + +.cpp.o: + @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< + +-include $(OBJS:%.o=%.d) + +clean: + @echo "CLEAN"; rm -f $(APP) $(OBJS) *.d + diff --git a/Demos/WidgetGallery/main.cpp b/Demos/WidgetGallery/main.cpp new file mode 100644 index 0000000000..81f219b51e --- /dev/null +++ b/Demos/WidgetGallery/main.cpp @@ -0,0 +1,82 @@ +#include <LibGUI/GApplication.h> +#include <LibGUI/GWindow.h> +#include <LibGUI/GWidget.h> +#include <LibGUI/GLabel.h> +#include <LibGUI/GButton.h> +#include <LibGUI/GBoxLayout.h> +#include <LibGUI/GCheckBox.h> +#include <LibGUI/GRadioButton.h> +#include <LibGUI/GTextBox.h> +#include <LibGUI/GProgressBar.h> +#include <LibGUI/GScrollBar.h> +#include <LibGUI/GSlider.h> +#include <LibGUI/GSpinBox.h> +#include <LibGUI/GGroupBox.h> +#include <LibCore/CTimer.h> + +int main(int argc, char** argv) +{ + GApplication app(argc, argv); + + auto* window = new GWindow; + window->set_rect(100, 100, 320, 480); + window->set_title("Widget Gallery"); + + auto* main_widget = new GWidget; + window->set_main_widget(main_widget); + main_widget->set_fill_with_background_color(true); + main_widget->set_layout(make<GBoxLayout>(Orientation::Vertical)); + main_widget->layout()->set_margins({ 4, 4, 4, 4 }); + + auto* checkbox1 = new GCheckBox("GCheckBox 1", main_widget); + auto* checkbox2 = new GCheckBox("GCheckBox 2", main_widget); + checkbox2->set_enabled(false); + + auto* radio1 = new GRadioButton("GRadioButton 1", main_widget); + auto* radio2 = new GRadioButton("GRadioButton 2", main_widget); + radio2->set_enabled(false); + + auto* button1 = new GButton("GButton 1", main_widget); + auto* button2 = new GButton("GButton 2", main_widget); + button2->set_enabled(false); + + auto* progress1 = new GProgressBar(main_widget); + new CTimer(100, [progress1] { + progress1->set_value(progress1->value() + 1); + if (progress1->value() == progress1->max()) + progress1->set_value(progress1->min()); + }); + + auto* label1 = new GLabel("GLabel 1", main_widget); + auto* label2 = new GLabel("GLabel 2", main_widget); + label2->set_enabled(false); + + auto* textbox1 = new GTextBox(main_widget); + textbox1->set_text("GTextBox 1"); + auto* textbox2 = new GTextBox(main_widget); + textbox2->set_text("GTextBox 2"); + textbox2->set_enabled(false); + + auto* spinbox1 = new GSpinBox(main_widget); + auto* spinbox2 = new GSpinBox(main_widget); + spinbox2->set_enabled(false); + + auto* slider1 = new GSlider(main_widget); + auto* slider2 = new GSlider(main_widget); + slider2->set_enabled(false); + + auto* scrollbar1 = new GScrollBar(Orientation::Horizontal, main_widget); + scrollbar1->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); + scrollbar1->set_preferred_size({ 0, 16 }); + scrollbar1->set_min(0); + scrollbar1->set_max(100); + scrollbar1->set_value(50); + auto* scrollbar2 = new GScrollBar(Orientation::Horizontal, main_widget); + scrollbar2->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); + scrollbar2->set_preferred_size({ 0, 16 }); + scrollbar2->set_enabled(false); + + window->show(); + + return app.exec(); +} diff --git a/Kernel/makeall.sh b/Kernel/makeall.sh index 78f74ab407..09dbc40463 100755 --- a/Kernel/makeall.sh +++ b/Kernel/makeall.sh @@ -33,6 +33,7 @@ build_targets="$build_targets ../Games/Snake" build_targets="$build_targets ../Shell" build_targets="$build_targets ../Demos/HelloWorld" build_targets="$build_targets ../Demos/RetroFetch" +build_targets="$build_targets ../Demos/WidgetGallery" build_targets="$build_targets ." # the kernel for targ in $build_targets; do diff --git a/Kernel/sync.sh b/Kernel/sync.sh index b548bcb283..f514bce19c 100755 --- a/Kernel/sync.sh +++ b/Kernel/sync.sh @@ -81,6 +81,8 @@ cp -v kernel.map mnt/ cp -v ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld ln -s HelloWorld mnt/bin/hw cp -v ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch +cp -v ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery +ln -s WidgetGallery mnt/bin/wg # Run local sync script, if it exists if [ -f sync-local.sh ]; then diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp index 6c382dbe6e..39ed387de5 100644 --- a/LibGUI/GButton.cpp +++ b/LibGUI/GButton.cpp @@ -10,6 +10,11 @@ GButton::GButton(GWidget* parent) { } +GButton::GButton(const String& text, GWidget* parent) + : GAbstractButton(text, parent) +{ +} + GButton::~GButton() { if (m_action) diff --git a/LibGUI/GButton.h b/LibGUI/GButton.h index ef0d1fc111..c0d185a21e 100644 --- a/LibGUI/GButton.h +++ b/LibGUI/GButton.h @@ -11,6 +11,7 @@ class GAction; class GButton : public GAbstractButton { public: + GButton(const String& text, GWidget* parent); explicit GButton(GWidget* parent); virtual ~GButton() override; diff --git a/LibGUI/GCheckBox.cpp b/LibGUI/GCheckBox.cpp index c2411ebb79..7b7606c177 100644 --- a/LibGUI/GCheckBox.cpp +++ b/LibGUI/GCheckBox.cpp @@ -25,8 +25,11 @@ static const int s_box_height = 13; GCheckBox::GCheckBox(GWidget* parent) : GAbstractButton(parent) { - if (!s_checked_bitmap) - s_checked_bitmap = &CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref(); +} + +GCheckBox::GCheckBox(const String& text, GWidget* parent) + : GAbstractButton(text, parent) +{ } GCheckBox::~GCheckBox() @@ -57,8 +60,11 @@ void GCheckBox::paint_event(GPaintEvent& event) if (is_being_pressed()) painter.draw_rect(box_rect.shrunken(4, 4), Color::MidGray); - if (is_checked()) + if (is_checked()) { + if (!s_checked_bitmap) + s_checked_bitmap = &CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref(); painter.draw_bitmap(box_rect.shrunken(4, 4).location(), *s_checked_bitmap, foreground_color()); + } if (!text().is_empty()) { painter.draw_text(text_rect, text(), TextAlignment::TopLeft, foreground_color()); diff --git a/LibGUI/GCheckBox.h b/LibGUI/GCheckBox.h index 7757a82c89..57e644aa9b 100644 --- a/LibGUI/GCheckBox.h +++ b/LibGUI/GCheckBox.h @@ -6,6 +6,7 @@ class GCheckBox : public GAbstractButton { public: + GCheckBox(const String&, GWidget* parent); explicit GCheckBox(GWidget* parent); virtual ~GCheckBox() override; |