Skip to content

Commit

Permalink
Welcome: Push in the buttons depending on which page is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
thatlittlegit authored and awesomekling committed Feb 15, 2020
1 parent 783f5dc commit ce2c1e8
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Applications/Welcome/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
OBJS = \
main.o \
TextWidget.o \
BackgroundWidget.o
BackgroundWidget.o \
UnuncheckableButton.o

PROGRAM = Welcome

Expand Down
39 changes: 39 additions & 0 deletions Applications/Welcome/UnuncheckableButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2020, Andreas Kling <[email protected]>
* 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()
{
}
38 changes: 38 additions & 0 deletions Applications/Welcome/UnuncheckableButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2020, Andreas Kling <[email protected]>
* 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; }
};
12 changes: 11 additions & 1 deletion Applications/Welcome/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "BackgroundWidget.h"
#include "TextWidget.h"
#include "UnuncheckableButton.h"

struct ContentPage {
String menu_name;
Expand Down Expand Up @@ -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>());
Expand All @@ -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();
Expand Down

0 comments on commit ce2c1e8

Please sign in to comment.