mirror of
https://github.com/RGBCube/serenity
synced 2025-07-14 20:17:35 +00:00
Welcome: Push in the buttons depending on which page is selected
This commit is contained in:
parent
783f5dc07f
commit
ce2c1e824d
4 changed files with 90 additions and 2 deletions
|
@ -1,7 +1,8 @@
|
||||||
OBJS = \
|
OBJS = \
|
||||||
main.o \
|
main.o \
|
||||||
TextWidget.o \
|
TextWidget.o \
|
||||||
BackgroundWidget.o
|
BackgroundWidget.o \
|
||||||
|
UnuncheckableButton.o
|
||||||
|
|
||||||
PROGRAM = Welcome
|
PROGRAM = Welcome
|
||||||
|
|
||||||
|
|
39
Applications/Welcome/UnuncheckableButton.cpp
Normal file
39
Applications/Welcome/UnuncheckableButton.cpp
Normal file
|
@ -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()
|
||||||
|
{
|
||||||
|
}
|
38
Applications/Welcome/UnuncheckableButton.h
Normal file
38
Applications/Welcome/UnuncheckableButton.h
Normal file
|
@ -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; }
|
||||||
|
};
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "BackgroundWidget.h"
|
#include "BackgroundWidget.h"
|
||||||
#include "TextWidget.h"
|
#include "TextWidget.h"
|
||||||
|
#include "UnuncheckableButton.h"
|
||||||
|
|
||||||
struct ContentPage {
|
struct ContentPage {
|
||||||
String menu_name;
|
String menu_name;
|
||||||
|
@ -132,6 +133,7 @@ int main(int argc, char** argv)
|
||||||
auto stack = GUI::StackWidget::construct(main_section);
|
auto stack = GUI::StackWidget::construct(main_section);
|
||||||
stack->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
stack->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
for (auto& page : pages) {
|
for (auto& page : pages) {
|
||||||
auto content = GUI::Widget::construct(stack.ptr());
|
auto content = GUI::Widget::construct(stack.ptr());
|
||||||
content->set_layout(make<GUI::VerticalBoxLayout>());
|
content->set_layout(make<GUI::VerticalBoxLayout>());
|
||||||
|
@ -155,16 +157,24 @@ int main(int argc, char** argv)
|
||||||
content_text->wrap_and_set_height();
|
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_font(Gfx::Font::default_font());
|
||||||
menu_option->set_text(page.menu_name);
|
menu_option->set_text(page.menu_name);
|
||||||
menu_option->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
menu_option->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||||
menu_option->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
menu_option->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||||
menu_option->set_preferred_size(0, 20);
|
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&) {
|
menu_option->on_click = [content = content.ptr(), &stack](auto&) {
|
||||||
stack->set_active_widget(content);
|
stack->set_active_widget(content);
|
||||||
content->invalidate_layout();
|
content->invalidate_layout();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue