mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
Welcome: Load banner font in a fallible manner
And simplify painting logic by using the banner widget's relative rect and tray_text() ColorRole.
This commit is contained in:
parent
08456be9dc
commit
883abffa25
2 changed files with 13 additions and 5 deletions
|
@ -18,7 +18,6 @@
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/Process.h>
|
#include <LibGUI/Process.h>
|
||||||
#include <LibGfx/Font/BitmapFont.h>
|
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<WelcomeWidget>> WelcomeWidget::try_create()
|
ErrorOr<NonnullRefPtr<WelcomeWidget>> WelcomeWidget::try_create()
|
||||||
|
@ -33,6 +32,9 @@ ErrorOr<void> WelcomeWidget::create_widgets()
|
||||||
{
|
{
|
||||||
TRY(load_from_gml(welcome_window_gml));
|
TRY(load_from_gml(welcome_window_gml));
|
||||||
|
|
||||||
|
m_banner_widget = find_descendant_of_type_named<GUI::Widget>("welcome_banner");
|
||||||
|
m_banner_font = TRY(Gfx::BitmapFont::try_load_from_file("/res/fonts/MarietaRegular24.font"sv));
|
||||||
|
|
||||||
m_web_view = find_descendant_of_type_named<WebView::OutOfProcessWebView>("web_view");
|
m_web_view = find_descendant_of_type_named<WebView::OutOfProcessWebView>("web_view");
|
||||||
auto path = TRY(String::formatted("{}/README.md", Core::StandardPaths::home_directory()));
|
auto path = TRY(String::formatted("{}/README.md", Core::StandardPaths::home_directory()));
|
||||||
m_web_view->load(URL::create_with_file_scheme(path.to_deprecated_string()));
|
m_web_view->load(URL::create_with_file_scheme(path.to_deprecated_string()));
|
||||||
|
@ -121,8 +123,10 @@ void WelcomeWidget::paint_event(GUI::PaintEvent& event)
|
||||||
GUI::Painter painter(*this);
|
GUI::Painter painter(*this);
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
|
|
||||||
static auto font = Gfx::BitmapFont::load_from_file("/res/fonts/MarietaRegular24.font"sv);
|
auto rect = m_banner_widget->relative_rect();
|
||||||
painter.draw_text(Gfx::IntRect { 12, 4, 1, 30 }, "Welcome to "sv, *font, Gfx::TextAlignment::CenterLeft, palette().base_text());
|
painter.draw_text(rect, "Welcome to "sv, *m_banner_font, Gfx::TextAlignment::CenterLeft, palette().base_text());
|
||||||
painter.draw_text(Gfx::IntRect { 12 + static_cast<int>(ceilf(font->width("Welcome to "sv))), 4, 1, 30 }, "Serenity"sv, font->bold_variant(), Gfx::TextAlignment::CenterLeft, palette().base_text());
|
rect.set_x(rect.x() + static_cast<int>(ceilf(m_banner_font->width("Welcome to "sv))));
|
||||||
painter.draw_text(Gfx::IntRect { 12 + static_cast<int>(ceilf(font->width("Welcome to "sv))) + static_cast<int>(ceilf(font->bold_variant().width("Serenity"sv))), 4, 1, 30 }, "OS"sv, font->bold_variant(), Gfx::TextAlignment::CenterLeft, palette().base() == palette().window() ? palette().base_text() : palette().base());
|
painter.draw_text(rect, "Serenity"sv, m_banner_font->bold_variant(), Gfx::TextAlignment::CenterLeft, palette().base_text());
|
||||||
|
rect.set_x(rect.x() + static_cast<int>(ceilf(m_banner_font->bold_variant().width("Serenity"sv))));
|
||||||
|
painter.draw_text(rect, "OS"sv, m_banner_font->bold_variant(), Gfx::TextAlignment::CenterLeft, palette().tray_text());
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
|
#include <LibGfx/Font/BitmapFont.h>
|
||||||
#include <LibWebView/OutOfProcessWebView.h>
|
#include <LibWebView/OutOfProcessWebView.h>
|
||||||
|
|
||||||
class WelcomeWidget final : public GUI::Widget {
|
class WelcomeWidget final : public GUI::Widget {
|
||||||
|
@ -25,6 +26,9 @@ private:
|
||||||
void set_random_tip();
|
void set_random_tip();
|
||||||
ErrorOr<void> open_and_parse_tips_file();
|
ErrorOr<void> open_and_parse_tips_file();
|
||||||
|
|
||||||
|
RefPtr<Gfx::BitmapFont> m_banner_font;
|
||||||
|
RefPtr<GUI::Widget> m_banner_widget;
|
||||||
|
|
||||||
RefPtr<GUI::Button> m_close_button;
|
RefPtr<GUI::Button> m_close_button;
|
||||||
RefPtr<GUI::Button> m_next_button;
|
RefPtr<GUI::Button> m_next_button;
|
||||||
RefPtr<GUI::Button> m_help_button;
|
RefPtr<GUI::Button> m_help_button;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue