mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibGUI: add a rudimentary framework for Wizards.
This patch provides the basic components needed for developers to create consistent wizard interface experiences in their applications. `WizardDialog` provides the dialog frame for the wizard, handling navigation and presentation. `AbstractWizardPage`s form the base class of Wizard pages, which are pushed onto the `WizardDialog` page stack via `WizardDialog::push_page`. `CoverWizardPage` and `WizardPage` are provided to ease the creation of Wizard interfaces consistent with the Serenity visual language.
This commit is contained in:
parent
610cec6e72
commit
e241dba8d3
12 changed files with 621 additions and 0 deletions
BIN
Base/res/graphics/wizard-banner-simple.png
Normal file
BIN
Base/res/graphics/wizard-banner-simple.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
0
Userland/Demos/WidgetGallery/DemoWizardPage1.gml
Normal file
0
Userland/Demos/WidgetGallery/DemoWizardPage1.gml
Normal file
0
Userland/Demos/WidgetGallery/DemoWizardPage2.gml
Normal file
0
Userland/Demos/WidgetGallery/DemoWizardPage2.gml
Normal file
|
@ -97,6 +97,10 @@ set(SOURCES
|
||||||
Widget.cpp
|
Widget.cpp
|
||||||
Window.cpp
|
Window.cpp
|
||||||
WindowServerConnection.cpp
|
WindowServerConnection.cpp
|
||||||
|
Wizards/WizardDialog.cpp
|
||||||
|
Wizards/AbstractWizardPage.cpp
|
||||||
|
Wizards/CoverWizardPage.cpp
|
||||||
|
Wizards/WizardPage.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(GENERATED_SOURCES
|
set(GENERATED_SOURCES
|
||||||
|
|
63
Userland/Libraries/LibGUI/Wizards/AbstractWizardPage.cpp
Normal file
63
Userland/Libraries/LibGUI/Wizards/AbstractWizardPage.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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 <LibGUI/Wizards/AbstractWizardPage.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
AbstractWizardPage::AbstractWizardPage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractWizardPage::~AbstractWizardPage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<AbstractWizardPage> AbstractWizardPage::next_page()
|
||||||
|
{
|
||||||
|
if (on_next_page)
|
||||||
|
return on_next_page();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AbstractWizardPage::can_go_next()
|
||||||
|
{
|
||||||
|
return !!on_next_page;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractWizardPage::page_enter()
|
||||||
|
{
|
||||||
|
if (on_page_enter)
|
||||||
|
return on_page_enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractWizardPage::page_leave()
|
||||||
|
{
|
||||||
|
if (on_page_leave)
|
||||||
|
return on_page_leave();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
Userland/Libraries/LibGUI/Wizards/AbstractWizardPage.h
Normal file
60
Userland/Libraries/LibGUI/Wizards/AbstractWizardPage.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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 <AK/NonnullRefPtrVector.h>
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
class AbstractWizardPage : public Widget {
|
||||||
|
C_OBJECT_ABSTRACT(AbstractWizardPage);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~AbstractWizardPage() override;
|
||||||
|
|
||||||
|
Function<RefPtr<AbstractWizardPage>()> on_next_page;
|
||||||
|
virtual RefPtr<AbstractWizardPage> next_page();
|
||||||
|
virtual bool can_go_next();
|
||||||
|
|
||||||
|
Function<void()> on_page_enter;
|
||||||
|
virtual void page_enter();
|
||||||
|
|
||||||
|
Function<void()> on_page_leave;
|
||||||
|
virtual void page_leave();
|
||||||
|
|
||||||
|
bool is_final_page() const { return m_is_final_page; }
|
||||||
|
void set_is_final_page(bool val) { m_is_final_page = val; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
AbstractWizardPage();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_is_final_page { false };
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
69
Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp
Normal file
69
Userland/Libraries/LibGUI/Wizards/CoverWizardPage.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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 <LibGUI/BoxLayout.h>
|
||||||
|
#include <LibGUI/ImageWidget.h>
|
||||||
|
#include <LibGUI/Label.h>
|
||||||
|
#include <LibGUI/Wizards/CoverWizardPage.h>
|
||||||
|
#include <LibGfx/FontDatabase.h>
|
||||||
|
#include <LibGfx/SystemTheme.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
CoverWizardPage::CoverWizardPage()
|
||||||
|
: AbstractWizardPage()
|
||||||
|
{
|
||||||
|
set_fill_with_background_color(true);
|
||||||
|
set_background_role(Gfx::ColorRole::Base);
|
||||||
|
set_layout<HorizontalBoxLayout>();
|
||||||
|
m_banner_image_widget = add<ImageWidget>();
|
||||||
|
m_banner_image_widget->set_fixed_size(160, 315);
|
||||||
|
m_banner_image_widget->load_from_file("/res/graphics/wizard-banner-simple.png");
|
||||||
|
|
||||||
|
m_content_widget = add<Widget>();
|
||||||
|
m_content_widget->set_layout<VerticalBoxLayout>();
|
||||||
|
m_content_widget->layout()->set_margins({ 20, 20, 20, 20 });
|
||||||
|
|
||||||
|
m_header_label = m_content_widget->add<Label>();
|
||||||
|
m_header_label->set_font(Gfx::FontDatabase::the().get("Pebbleton", 14, 700));
|
||||||
|
m_header_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||||
|
m_header_label->set_fixed_height(48);
|
||||||
|
|
||||||
|
m_body_label = m_content_widget->add<Label>();
|
||||||
|
m_body_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoverWizardPage::set_header_text(const String& text)
|
||||||
|
{
|
||||||
|
m_header_label->set_text(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoverWizardPage::set_body_text(const String& text)
|
||||||
|
{
|
||||||
|
m_body_label->set_text(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
Userland/Libraries/LibGUI/Wizards/CoverWizardPage.h
Normal file
54
Userland/Libraries/LibGUI/Wizards/CoverWizardPage.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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/ImageWidget.h>
|
||||||
|
#include <LibGUI/Label.h>
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
#include <LibGUI/Wizards/AbstractWizardPage.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
class CoverWizardPage : public AbstractWizardPage {
|
||||||
|
C_OBJECT(CoverWizardPage);
|
||||||
|
|
||||||
|
ImageWidget& banner_image_widget() { return *m_banner_image_widget; }
|
||||||
|
|
||||||
|
void set_header_text(const String& text);
|
||||||
|
void set_body_text(const String& text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit CoverWizardPage();
|
||||||
|
|
||||||
|
RefPtr<ImageWidget> m_banner_image_widget;
|
||||||
|
RefPtr<Widget> m_content_widget;
|
||||||
|
|
||||||
|
RefPtr<Label> m_header_label;
|
||||||
|
RefPtr<Label> m_body_label;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
168
Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp
Normal file
168
Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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 <LibGUI/BoxLayout.h>
|
||||||
|
#include <LibGUI/Button.h>
|
||||||
|
#include <LibGUI/SeparatorWidget.h>
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
#include <LibGUI/Wizards/AbstractWizardPage.h>
|
||||||
|
#include <LibGUI/Wizards/WizardDialog.h>
|
||||||
|
#include <LibGfx/Orientation.h>
|
||||||
|
#include <LibGfx/SystemTheme.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
WizardDialog::WizardDialog(Window* parent_window)
|
||||||
|
: Dialog(parent_window)
|
||||||
|
, m_page_stack()
|
||||||
|
{
|
||||||
|
resize(500, 360);
|
||||||
|
set_title(String::formatted("Sample wizard"));
|
||||||
|
set_resizable(false);
|
||||||
|
|
||||||
|
if (parent_window)
|
||||||
|
set_icon(parent_window->icon());
|
||||||
|
|
||||||
|
auto& main_widget = set_main_widget<Widget>();
|
||||||
|
main_widget.set_fill_with_background_color(true);
|
||||||
|
main_widget.set_layout<VerticalBoxLayout>();
|
||||||
|
main_widget.layout()->set_spacing(0);
|
||||||
|
|
||||||
|
m_page_container_widget = main_widget.add<Widget>();
|
||||||
|
m_page_container_widget->set_fixed_size(500, 315);
|
||||||
|
m_page_container_widget->set_layout<VerticalBoxLayout>();
|
||||||
|
|
||||||
|
auto& separator = main_widget.add<SeparatorWidget>(Gfx::Orientation::Horizontal);
|
||||||
|
separator.set_fixed_height(2);
|
||||||
|
|
||||||
|
auto& nav_container_widget = main_widget.add<Widget>();
|
||||||
|
nav_container_widget.set_layout<HorizontalBoxLayout>();
|
||||||
|
nav_container_widget.set_fixed_height(42);
|
||||||
|
nav_container_widget.layout()->set_margins({ 10, 0, 10, 0 });
|
||||||
|
nav_container_widget.layout()->set_spacing(0);
|
||||||
|
nav_container_widget.layout()->add_spacer();
|
||||||
|
|
||||||
|
m_back_button = nav_container_widget.add<Button>("< Back");
|
||||||
|
m_back_button->set_fixed_width(75);
|
||||||
|
m_back_button->on_click = [&]() {
|
||||||
|
pop_page();
|
||||||
|
};
|
||||||
|
|
||||||
|
m_next_button = nav_container_widget.add<Button>("Next >");
|
||||||
|
m_next_button->set_fixed_width(75);
|
||||||
|
m_next_button->on_click = [&]() {
|
||||||
|
VERIFY(has_pages());
|
||||||
|
|
||||||
|
if (!current_page().can_go_next())
|
||||||
|
return done(ExecOK);
|
||||||
|
|
||||||
|
push_page(*current_page().next_page());
|
||||||
|
};
|
||||||
|
|
||||||
|
auto& button_spacer = nav_container_widget.add<Widget>();
|
||||||
|
button_spacer.set_fixed_width(10);
|
||||||
|
|
||||||
|
m_cancel_button = nav_container_widget.add<Button>("Cancel");
|
||||||
|
m_cancel_button->set_fixed_width(75);
|
||||||
|
m_cancel_button->on_click = [&]() {
|
||||||
|
handle_cancel();
|
||||||
|
};
|
||||||
|
|
||||||
|
update_navigation();
|
||||||
|
}
|
||||||
|
|
||||||
|
WizardDialog::~WizardDialog()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardDialog::push_page(AbstractWizardPage& page)
|
||||||
|
{
|
||||||
|
if (!m_page_stack.is_empty())
|
||||||
|
m_page_stack.last().page_leave();
|
||||||
|
|
||||||
|
m_page_stack.append(page);
|
||||||
|
m_page_container_widget->remove_all_children();
|
||||||
|
m_page_container_widget->add_child(page);
|
||||||
|
|
||||||
|
update_navigation();
|
||||||
|
page.page_enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardDialog::replace_page(AbstractWizardPage& page)
|
||||||
|
{
|
||||||
|
if (!m_page_stack.is_empty())
|
||||||
|
m_page_stack.take_last()->page_leave();
|
||||||
|
|
||||||
|
m_page_stack.append(page);
|
||||||
|
m_page_container_widget->remove_all_children();
|
||||||
|
m_page_container_widget->add_child(page);
|
||||||
|
|
||||||
|
update_navigation();
|
||||||
|
page.page_enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardDialog::pop_page()
|
||||||
|
{
|
||||||
|
if (m_page_stack.size() <= 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto page = m_page_stack.take_last();
|
||||||
|
page->page_leave();
|
||||||
|
|
||||||
|
m_page_container_widget->remove_all_children();
|
||||||
|
m_page_container_widget->add_child(m_page_stack.last());
|
||||||
|
|
||||||
|
update_navigation();
|
||||||
|
m_page_stack.last().page_enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardDialog::update_navigation()
|
||||||
|
{
|
||||||
|
m_back_button->set_enabled(m_page_stack.size() > 1);
|
||||||
|
if (has_pages()) {
|
||||||
|
m_next_button->set_enabled(current_page().is_final_page() || current_page().can_go_next());
|
||||||
|
m_next_button->set_text(current_page().is_final_page() ? "Finish" : "Next >");
|
||||||
|
} else {
|
||||||
|
m_next_button->set_text("Next >");
|
||||||
|
m_next_button->set_enabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractWizardPage& WizardDialog::current_page()
|
||||||
|
{
|
||||||
|
VERIFY(has_pages());
|
||||||
|
return m_page_stack.last();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardDialog::handle_cancel()
|
||||||
|
{
|
||||||
|
if (on_cancel)
|
||||||
|
return on_cancel();
|
||||||
|
|
||||||
|
done(ExecCancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
Userland/Libraries/LibGUI/Wizards/WizardDialog.h
Normal file
73
Userland/Libraries/LibGUI/Wizards/WizardDialog.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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 <AK/NonnullRefPtrVector.h>
|
||||||
|
#include <LibGUI/Dialog.h>
|
||||||
|
#include <LibGUI/Wizards/AbstractWizardPage.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
class WizardDialog : public Dialog {
|
||||||
|
C_OBJECT(WizardDialog)
|
||||||
|
public:
|
||||||
|
virtual ~WizardDialog() override;
|
||||||
|
|
||||||
|
static void show(AbstractWizardPage& first_page, Window* parent_window = nullptr)
|
||||||
|
{
|
||||||
|
auto dialog = WizardDialog::construct(parent_window);
|
||||||
|
dialog->push_page(first_page);
|
||||||
|
dialog->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
Function<void()> on_cancel;
|
||||||
|
|
||||||
|
/// Push a page onto the page stack and display it, preserving the previous page on the stack.
|
||||||
|
void push_page(AbstractWizardPage& page);
|
||||||
|
/// Replace the current page on the stack with a new page, preventing the user from returning to the current page.
|
||||||
|
void replace_page(AbstractWizardPage& page);
|
||||||
|
void pop_page();
|
||||||
|
AbstractWizardPage& current_page();
|
||||||
|
|
||||||
|
inline bool has_pages() const { return !m_page_stack.is_empty(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
WizardDialog(Window* parent_window);
|
||||||
|
|
||||||
|
virtual void handle_cancel();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void update_navigation();
|
||||||
|
|
||||||
|
RefPtr<Widget> m_page_container_widget;
|
||||||
|
RefPtr<Button> m_back_button;
|
||||||
|
RefPtr<Button> m_next_button;
|
||||||
|
RefPtr<Button> m_cancel_button;
|
||||||
|
|
||||||
|
NonnullRefPtrVector<AbstractWizardPage> m_page_stack;
|
||||||
|
};
|
||||||
|
}
|
77
Userland/Libraries/LibGUI/Wizards/WizardPage.cpp
Normal file
77
Userland/Libraries/LibGUI/Wizards/WizardPage.cpp
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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 <LibGUI/BoxLayout.h>
|
||||||
|
#include <LibGUI/Label.h>
|
||||||
|
#include <LibGUI/SeparatorWidget.h>
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
#include <LibGUI/Wizards/WizardPage.h>
|
||||||
|
#include <LibGfx/FontDatabase.h>
|
||||||
|
#include <LibGfx/SystemTheme.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
WizardPage::WizardPage(const String& title_text, const String& subtitle_text)
|
||||||
|
: AbstractWizardPage()
|
||||||
|
{
|
||||||
|
set_layout<VerticalBoxLayout>();
|
||||||
|
layout()->set_spacing(0);
|
||||||
|
|
||||||
|
auto& header_widget = add<Widget>();
|
||||||
|
header_widget.set_fill_with_background_color(true);
|
||||||
|
header_widget.set_background_role(Gfx::ColorRole::Base);
|
||||||
|
header_widget.set_fixed_height(58);
|
||||||
|
|
||||||
|
header_widget.set_layout<VerticalBoxLayout>();
|
||||||
|
header_widget.layout()->set_margins({ 30, 15, 30, 0 });
|
||||||
|
m_title_label = header_widget.add<Label>(title_text);
|
||||||
|
m_title_label->set_font(Gfx::FontDatabase::the().default_bold_font());
|
||||||
|
m_title_label->set_fixed_height(Gfx::FontDatabase::the().default_bold_font().glyph_height() + 2);
|
||||||
|
m_title_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||||
|
m_subtitle_label = header_widget.add<Label>(subtitle_text);
|
||||||
|
m_subtitle_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||||
|
m_title_label->set_fixed_height(Gfx::FontDatabase::the().default_font().glyph_height());
|
||||||
|
header_widget.layout()->add_spacer();
|
||||||
|
|
||||||
|
auto& separator = add<SeparatorWidget>(Gfx::Orientation::Horizontal);
|
||||||
|
separator.set_fixed_height(2);
|
||||||
|
|
||||||
|
m_body_widget = add<Widget>();
|
||||||
|
m_body_widget->set_layout<VerticalBoxLayout>();
|
||||||
|
m_body_widget->layout()->set_margins({ 20, 20, 20, 20 });
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardPage::set_page_title(const String& text)
|
||||||
|
{
|
||||||
|
m_title_label->set_text(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WizardPage::set_page_subtitle(const String& text)
|
||||||
|
{
|
||||||
|
m_subtitle_label->set_text(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
Userland/Libraries/LibGUI/Wizards/WizardPage.h
Normal file
53
Userland/Libraries/LibGUI/Wizards/WizardPage.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Nick Vella <nick@nxk.io>
|
||||||
|
* 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/ImageWidget.h>
|
||||||
|
#include <LibGUI/Label.h>
|
||||||
|
#include <LibGUI/Widget.h>
|
||||||
|
#include <LibGUI/Wizards/AbstractWizardPage.h>
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
class WizardPage : public AbstractWizardPage {
|
||||||
|
C_OBJECT(WizardPage);
|
||||||
|
|
||||||
|
Widget& body_widget() { return *m_body_widget; };
|
||||||
|
|
||||||
|
void set_page_title(const String& text);
|
||||||
|
void set_page_subtitle(const String& text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit WizardPage(const String& title_text, const String& subtitle_text);
|
||||||
|
|
||||||
|
RefPtr<Widget> m_body_widget;
|
||||||
|
|
||||||
|
RefPtr<Label> m_title_label;
|
||||||
|
RefPtr<Label> m_subtitle_label;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue