mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:27:45 +00:00
Applications+Demos+LibGUI: Migrate to fallible WizardDialogs and Pages
And port page text to String. Also removes WizardDialog::show() helper as all current implementations prefer to derive their own Dialog.
This commit is contained in:
parent
96e60c98cf
commit
caa8f43dbe
12 changed files with 178 additions and 115 deletions
|
@ -13,36 +13,44 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
CoverWizardPage::CoverWizardPage()
|
||||
: AbstractWizardPage()
|
||||
ErrorOr<NonnullRefPtr<CoverWizardPage>> CoverWizardPage::create(StringView title, StringView subtitle)
|
||||
{
|
||||
auto page = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) CoverWizardPage()));
|
||||
TRY(page->build(TRY(String::from_utf8(title)), TRY(String::from_utf8(subtitle))));
|
||||
return page;
|
||||
}
|
||||
|
||||
ErrorOr<void> CoverWizardPage::build(String title, String subtitle)
|
||||
{
|
||||
set_fill_with_background_color(true);
|
||||
set_background_role(Gfx::ColorRole::Base);
|
||||
set_layout<HorizontalBoxLayout>();
|
||||
m_banner_image_widget = add<ImageWidget>();
|
||||
TRY(try_set_layout<HorizontalBoxLayout>());
|
||||
m_banner_image_widget = TRY(try_add<ImageWidget>());
|
||||
m_banner_image_widget->set_fixed_size(160, 315);
|
||||
m_banner_image_widget->load_from_file("/res/graphics/wizard-banner-simple.png"sv);
|
||||
|
||||
m_content_widget = add<Widget>();
|
||||
m_content_widget->set_layout<VerticalBoxLayout>(20);
|
||||
m_content_widget = TRY(try_add<Widget>());
|
||||
TRY(m_content_widget->try_set_layout<VerticalBoxLayout>(20));
|
||||
|
||||
m_header_label = m_content_widget->add<Label>();
|
||||
m_header_label = TRY(m_content_widget->try_add<Label>(move(title)));
|
||||
m_header_label->set_font(Gfx::FontDatabase::the().get("Pebbleton", 14, 700, Gfx::FontWidth::Normal, 0));
|
||||
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 = TRY(m_content_widget->try_add<Label>(move(subtitle)));
|
||||
m_body_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void CoverWizardPage::set_header_text(DeprecatedString const& text)
|
||||
void CoverWizardPage::set_header_text(String text)
|
||||
{
|
||||
m_header_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors());
|
||||
m_header_label->set_text(move(text));
|
||||
}
|
||||
|
||||
void CoverWizardPage::set_body_text(DeprecatedString const& text)
|
||||
void CoverWizardPage::set_body_text(String text)
|
||||
{
|
||||
m_body_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors());
|
||||
m_body_label->set_text(move(text));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,15 +14,20 @@
|
|||
namespace GUI {
|
||||
|
||||
class CoverWizardPage : public AbstractWizardPage {
|
||||
C_OBJECT(CoverWizardPage);
|
||||
C_OBJECT_ABSTRACT(CoverWizardPage);
|
||||
|
||||
static ErrorOr<NonnullRefPtr<CoverWizardPage>> create(StringView title, StringView subtitle);
|
||||
|
||||
ImageWidget& banner_image_widget() { return *m_banner_image_widget; }
|
||||
|
||||
void set_header_text(DeprecatedString const& text);
|
||||
void set_body_text(DeprecatedString const& text);
|
||||
void set_header_text(String);
|
||||
void set_body_text(String);
|
||||
|
||||
protected:
|
||||
virtual ErrorOr<void> build(String title, String subtitle);
|
||||
|
||||
private:
|
||||
explicit CoverWizardPage();
|
||||
CoverWizardPage() = default;
|
||||
|
||||
RefPtr<ImageWidget> m_banner_image_widget;
|
||||
RefPtr<Widget> m_content_widget;
|
||||
|
|
|
@ -16,39 +16,37 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
WizardDialog::WizardDialog(Window* parent_window)
|
||||
: Dialog(parent_window)
|
||||
, m_page_stack()
|
||||
ErrorOr<NonnullRefPtr<WizardDialog>> WizardDialog::create(Window* parent_window)
|
||||
{
|
||||
resize(500, 360);
|
||||
set_title(DeprecatedString::formatted("Sample wizard"));
|
||||
set_resizable(false);
|
||||
auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WizardDialog(parent_window)));
|
||||
TRY(dialog->build());
|
||||
return dialog;
|
||||
}
|
||||
|
||||
if (parent_window)
|
||||
set_icon(parent_window->icon());
|
||||
|
||||
auto main_widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
|
||||
ErrorOr<void> WizardDialog::build()
|
||||
{
|
||||
auto main_widget = TRY(set_main_widget<Widget>());
|
||||
main_widget->set_fill_with_background_color(true);
|
||||
main_widget->set_layout<VerticalBoxLayout>(GUI::Margins {}, 0);
|
||||
TRY(main_widget->try_set_layout<VerticalBoxLayout>(Margins {}, 0));
|
||||
|
||||
m_page_container_widget = main_widget->add<Widget>();
|
||||
m_page_container_widget = TRY(main_widget->try_add<Widget>());
|
||||
m_page_container_widget->set_fixed_size(500, 315);
|
||||
m_page_container_widget->set_layout<VerticalBoxLayout>();
|
||||
TRY(m_page_container_widget->try_set_layout<VerticalBoxLayout>());
|
||||
|
||||
auto& separator = main_widget->add<SeparatorWidget>(Gfx::Orientation::Horizontal);
|
||||
separator.set_fixed_height(2);
|
||||
auto separator = TRY(main_widget->try_add<SeparatorWidget>(Gfx::Orientation::Horizontal));
|
||||
separator->set_fixed_height(2);
|
||||
|
||||
auto& nav_container_widget = main_widget->add<Widget>();
|
||||
nav_container_widget.set_layout<HorizontalBoxLayout>(GUI::Margins { 0, 10 }, 0);
|
||||
nav_container_widget.set_fixed_height(42);
|
||||
nav_container_widget.add_spacer().release_value_but_fixme_should_propagate_errors();
|
||||
auto nav_container_widget = TRY(main_widget->try_add<Widget>());
|
||||
TRY(nav_container_widget->try_set_layout<HorizontalBoxLayout>(Margins { 0, 10 }, 0));
|
||||
nav_container_widget->set_fixed_height(42);
|
||||
TRY(nav_container_widget->add_spacer());
|
||||
|
||||
m_back_button = nav_container_widget.add<DialogButton>("< Back"_short_string);
|
||||
m_back_button = TRY(nav_container_widget->try_add<DialogButton>("< Back"_short_string));
|
||||
m_back_button->on_click = [&](auto) {
|
||||
pop_page();
|
||||
};
|
||||
|
||||
m_next_button = nav_container_widget.add<DialogButton>("Next >"_short_string);
|
||||
m_next_button = TRY(nav_container_widget->try_add<DialogButton>("Next >"_short_string));
|
||||
m_next_button->on_click = [&](auto) {
|
||||
VERIFY(has_pages());
|
||||
|
||||
|
@ -62,15 +60,25 @@ WizardDialog::WizardDialog(Window* parent_window)
|
|||
push_page(*next_page);
|
||||
};
|
||||
|
||||
auto& button_spacer = nav_container_widget.add<Widget>();
|
||||
button_spacer.set_fixed_width(10);
|
||||
auto button_spacer = TRY(nav_container_widget->try_add<Widget>());
|
||||
button_spacer->set_fixed_width(10);
|
||||
|
||||
m_cancel_button = nav_container_widget.add<DialogButton>("Cancel"_short_string);
|
||||
m_cancel_button = TRY(nav_container_widget->try_add<DialogButton>("Cancel"_short_string));
|
||||
m_cancel_button->on_click = [&](auto) {
|
||||
handle_cancel();
|
||||
};
|
||||
|
||||
update_navigation();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
WizardDialog::WizardDialog(Window* parent_window)
|
||||
: Dialog(parent_window)
|
||||
, m_page_stack()
|
||||
{
|
||||
resize(500, 360);
|
||||
set_resizable(false);
|
||||
}
|
||||
|
||||
void WizardDialog::push_page(AbstractWizardPage& page)
|
||||
|
|
|
@ -13,16 +13,11 @@
|
|||
namespace GUI {
|
||||
|
||||
class WizardDialog : public Dialog {
|
||||
C_OBJECT(WizardDialog)
|
||||
C_OBJECT_ABSTRACT(WizardDialog)
|
||||
public:
|
||||
virtual ~WizardDialog() override = default;
|
||||
|
||||
static void show(AbstractWizardPage& first_page, Window* parent_window = nullptr)
|
||||
{
|
||||
auto dialog = WizardDialog::construct(parent_window);
|
||||
dialog->push_page(first_page);
|
||||
dialog->exec();
|
||||
}
|
||||
static ErrorOr<NonnullRefPtr<WizardDialog>> create(Window* parent_window);
|
||||
|
||||
Function<void()> on_cancel;
|
||||
|
||||
|
@ -36,8 +31,9 @@ public:
|
|||
inline bool has_pages() const { return !m_page_stack.is_empty(); }
|
||||
|
||||
protected:
|
||||
WizardDialog(Window* parent_window);
|
||||
explicit WizardDialog(Window* parent_window);
|
||||
|
||||
virtual ErrorOr<void> build();
|
||||
virtual void handle_cancel();
|
||||
|
||||
private:
|
||||
|
|
|
@ -14,41 +14,50 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
WizardPage::WizardPage(DeprecatedString const& title_text, DeprecatedString const& subtitle_text)
|
||||
: AbstractWizardPage()
|
||||
ErrorOr<NonnullRefPtr<WizardPage>> WizardPage::create(StringView title, StringView subtitle)
|
||||
{
|
||||
set_layout<VerticalBoxLayout>(GUI::Margins {}, 0);
|
||||
auto page = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WizardPage()));
|
||||
TRY(page->build(TRY(String::from_utf8(title)), TRY(String::from_utf8(subtitle))));
|
||||
return page;
|
||||
}
|
||||
|
||||
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);
|
||||
ErrorOr<void> WizardPage::build(String title, String subtitle)
|
||||
{
|
||||
TRY(try_set_layout<VerticalBoxLayout>(Margins {}, 0));
|
||||
|
||||
header_widget.set_layout<VerticalBoxLayout>(GUI::Margins { 15, 30, 0 });
|
||||
m_title_label = header_widget.add<Label>(String::from_deprecated_string(title_text).release_value_but_fixme_should_propagate_errors());
|
||||
auto header_widget = TRY(try_add<Widget>());
|
||||
header_widget->set_fill_with_background_color(true);
|
||||
header_widget->set_background_role(Gfx::ColorRole::Base);
|
||||
header_widget->set_fixed_height(58);
|
||||
|
||||
TRY(header_widget->try_set_layout<VerticalBoxLayout>(Margins { 15, 30, 0 }));
|
||||
m_title_label = TRY(header_widget->try_add<Label>(move(title)));
|
||||
m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant());
|
||||
m_title_label->set_fixed_height(m_title_label->font().pixel_size_rounded_up() + 2);
|
||||
m_title_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||
m_subtitle_label = header_widget.add<Label>(String::from_deprecated_string(subtitle_text).release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
m_subtitle_label = TRY(header_widget->try_add<Label>(move(subtitle)));
|
||||
m_subtitle_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
|
||||
m_subtitle_label->set_fixed_height(m_subtitle_label->font().pixel_size_rounded_up());
|
||||
header_widget.add_spacer().release_value_but_fixme_should_propagate_errors();
|
||||
TRY(header_widget->add_spacer());
|
||||
|
||||
auto& separator = add<SeparatorWidget>(Gfx::Orientation::Horizontal);
|
||||
separator.set_fixed_height(2);
|
||||
auto separator = TRY(try_add<SeparatorWidget>(Gfx::Orientation::Horizontal));
|
||||
separator->set_fixed_height(2);
|
||||
|
||||
m_body_widget = add<Widget>();
|
||||
m_body_widget->set_layout<VerticalBoxLayout>(20);
|
||||
m_body_widget = TRY(try_add<Widget>());
|
||||
TRY(m_body_widget->try_set_layout<VerticalBoxLayout>(20));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void WizardPage::set_page_title(DeprecatedString const& text)
|
||||
void WizardPage::set_page_title(String text)
|
||||
{
|
||||
m_title_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors());
|
||||
m_title_label->set_text(move(text));
|
||||
}
|
||||
|
||||
void WizardPage::set_page_subtitle(DeprecatedString const& text)
|
||||
void WizardPage::set_page_subtitle(String text)
|
||||
{
|
||||
m_subtitle_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors());
|
||||
m_subtitle_label->set_text(move(text));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,15 +14,20 @@
|
|||
namespace GUI {
|
||||
|
||||
class WizardPage : public AbstractWizardPage {
|
||||
C_OBJECT(WizardPage);
|
||||
C_OBJECT_ABSTRACT(WizardPage);
|
||||
|
||||
static ErrorOr<NonnullRefPtr<WizardPage>> create(StringView title, StringView subtitle);
|
||||
|
||||
Widget& body_widget() { return *m_body_widget; };
|
||||
|
||||
void set_page_title(DeprecatedString const& text);
|
||||
void set_page_subtitle(DeprecatedString const& text);
|
||||
void set_page_title(String);
|
||||
void set_page_subtitle(String);
|
||||
|
||||
protected:
|
||||
virtual ErrorOr<void> build(String title, String subtitle);
|
||||
|
||||
private:
|
||||
explicit WizardPage(DeprecatedString const& title_text, DeprecatedString const& subtitle_text);
|
||||
WizardPage() = default;
|
||||
|
||||
RefPtr<Widget> m_body_widget;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue