diff options
author | thatlittlegit <personal@thatlittlegit.tk> | 2020-02-14 12:17:21 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-15 20:46:10 +0100 |
commit | ce2c1e824dae523c4f90b6760a2fae3684d50264 (patch) | |
tree | 119ffc050d51cc8e5389b2f5154c6b7147ce115b /Applications/Welcome | |
parent | 783f5dc07f3f9568e094c7b9d0bc87b6042f307e (diff) | |
download | serenity-ce2c1e824dae523c4f90b6760a2fae3684d50264.zip |
Welcome: Push in the buttons depending on which page is selected
Diffstat (limited to 'Applications/Welcome')
-rw-r--r-- | Applications/Welcome/Makefile | 3 | ||||
-rw-r--r-- | Applications/Welcome/UnuncheckableButton.cpp | 39 | ||||
-rw-r--r-- | Applications/Welcome/UnuncheckableButton.h | 38 | ||||
-rw-r--r-- | Applications/Welcome/main.cpp | 12 |
4 files changed, 90 insertions, 2 deletions
diff --git a/Applications/Welcome/Makefile b/Applications/Welcome/Makefile index 585c582173..6fc8d97585 100644 --- a/Applications/Welcome/Makefile +++ b/Applications/Welcome/Makefile @@ -1,7 +1,8 @@ OBJS = \ main.o \ TextWidget.o \ - BackgroundWidget.o + BackgroundWidget.o \ + UnuncheckableButton.o PROGRAM = Welcome diff --git a/Applications/Welcome/UnuncheckableButton.cpp b/Applications/Welcome/UnuncheckableButton.cpp new file mode 100644 index 0000000000..d7d486b406 --- /dev/null +++ b/Applications/Welcome/UnuncheckableButton.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 "UnuncheckableButton.h" +#include <LibGUI/Painter.h> +#include <LibGfx/Color.h> +#include <LibGfx/Palette.h> + +UnuncheckableButton::UnuncheckableButton(GUI::Widget* parent) + : GUI::Button(parent) +{ +} + +UnuncheckableButton::~UnuncheckableButton() +{ +} diff --git a/Applications/Welcome/UnuncheckableButton.h b/Applications/Welcome/UnuncheckableButton.h new file mode 100644 index 0000000000..ae6bb6a7d5 --- /dev/null +++ b/Applications/Welcome/UnuncheckableButton.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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. + */ + +#pragma once + +#include <LibGUI/Button.h> + +class UnuncheckableButton : public GUI::Button { + C_OBJECT(UnuncheckableButton) +public: + explicit UnuncheckableButton(GUI::Widget* parent = nullptr); + virtual ~UnuncheckableButton() override; + + virtual bool is_uncheckable() const override { return false; } +}; diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp index 90e64aa4ef..d01af4a8c8 100644 --- a/Applications/Welcome/main.cpp +++ b/Applications/Welcome/main.cpp @@ -37,6 +37,7 @@ #include "BackgroundWidget.h" #include "TextWidget.h" +#include "UnuncheckableButton.h" struct ContentPage { String menu_name; @@ -132,6 +133,7 @@ int main(int argc, char** argv) auto stack = GUI::StackWidget::construct(main_section); stack->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + bool first = true; for (auto& page : pages) { auto content = GUI::Widget::construct(stack.ptr()); content->set_layout(make<GUI::VerticalBoxLayout>()); @@ -155,16 +157,24 @@ int main(int argc, char** argv) content_text->wrap_and_set_height(); } - auto menu_option = GUI::Button::construct(menu); + auto menu_option = UnuncheckableButton::construct(menu); menu_option->set_font(Gfx::Font::default_font()); menu_option->set_text(page.menu_name); menu_option->set_text_alignment(Gfx::TextAlignment::CenterLeft); menu_option->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); menu_option->set_preferred_size(0, 20); + menu_option->set_checkable(true); + menu_option->set_exclusive(true); + + if (first) + menu_option->set_checked(true); + menu_option->on_click = [content = content.ptr(), &stack](auto&) { stack->set_active_widget(content); content->invalidate_layout(); }; + + first = false; } window->show(); |