mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
FontEditor: Convert preview window to GML and propagate its errors
This commit is contained in:
parent
7376c68652
commit
1b9dff5fb1
4 changed files with 69 additions and 48 deletions
|
@ -6,12 +6,14 @@ serenity_component(
|
|||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
compile_gml(FontEditorWindow.gml FontEditorWindowGML.h font_editor_window_gml)
|
||||
compile_gml(FontPreviewWindow.gml FontPreviewWindowGML.h font_preview_window_gml)
|
||||
compile_gml(NewFontDialogPage1.gml NewFontDialogPage1GML.h new_font_dialog_page_1_gml)
|
||||
compile_gml(NewFontDialogPage2.gml NewFontDialogPage2GML.h new_font_dialog_page_2_gml)
|
||||
|
||||
set(SOURCES
|
||||
FontEditor.cpp
|
||||
FontEditorWindowGML.h
|
||||
FontPreviewWindowGML.h
|
||||
GlyphEditorWidget.cpp
|
||||
main.cpp
|
||||
NewFontDialog.cpp
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringUtils.h>
|
||||
#include <Applications/FontEditor/FontEditorWindowGML.h>
|
||||
#include <Applications/FontEditor/FontPreviewWindowGML.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
#include <LibGUI/Action.h>
|
||||
|
@ -56,55 +57,33 @@ static constexpr Array pangrams = {
|
|||
"<fox color=\"brown\" speed=\"quick\" jumps=\"over\">lazy dog</fox>"
|
||||
};
|
||||
|
||||
static RefPtr<GUI::Window> create_font_preview_window(FontEditorWidget& editor)
|
||||
ErrorOr<RefPtr<GUI::Window>> FontEditorWidget::create_preview_window()
|
||||
{
|
||||
auto window = GUI::Window::construct(&editor);
|
||||
auto window = TRY(GUI::Window::try_create(this));
|
||||
window->set_window_type(GUI::WindowType::ToolWindow);
|
||||
window->set_title("Preview");
|
||||
window->resize(400, 150);
|
||||
window->set_minimum_size(200, 100);
|
||||
window->center_within(*editor.window());
|
||||
window->center_within(*this->window());
|
||||
|
||||
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
main_widget.layout()->set_margins(2);
|
||||
main_widget.layout()->set_spacing(4);
|
||||
auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
main_widget->load_from_gml(font_preview_window_gml);
|
||||
|
||||
auto& preview_box = main_widget.add<GUI::GroupBox>();
|
||||
preview_box.set_layout<GUI::VerticalBoxLayout>();
|
||||
preview_box.layout()->set_margins(8);
|
||||
m_preview_label = find_descendant_of_type_named<GUI::Label>("preview_label");
|
||||
m_preview_label->set_font(edited_font());
|
||||
|
||||
auto& preview_label = preview_box.add<GUI::Label>();
|
||||
preview_label.set_font(editor.edited_font());
|
||||
|
||||
editor.on_initialize = [&] {
|
||||
preview_label.set_font(editor.edited_font());
|
||||
m_preview_textbox = find_descendant_of_type_named<GUI::TextBox>("preview_textbox");
|
||||
m_preview_textbox->on_change = [&] {
|
||||
auto preview = String::formatted("{}\n{}", m_preview_textbox->text(), Unicode::to_unicode_uppercase_full(m_preview_textbox->text()));
|
||||
m_preview_label->set_text(preview);
|
||||
};
|
||||
m_preview_textbox->set_text(pangrams[0]);
|
||||
|
||||
auto& textbox_button_container = main_widget.add<GUI::Widget>();
|
||||
textbox_button_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
textbox_button_container.set_fixed_height(22);
|
||||
|
||||
auto& preview_textbox = textbox_button_container.add<GUI::TextBox>();
|
||||
preview_textbox.set_text(pangrams[0]);
|
||||
preview_textbox.set_placeholder("Preview text");
|
||||
|
||||
preview_textbox.on_change = [&] {
|
||||
auto preview = String::formatted("{}\n{}",
|
||||
preview_textbox.text(),
|
||||
Unicode::to_unicode_uppercase_full(preview_textbox.text()));
|
||||
preview_label.set_text(preview);
|
||||
};
|
||||
|
||||
auto& reload_button = textbox_button_container.add<GUI::Button>();
|
||||
reload_button.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png").release_value_but_fixme_should_propagate_errors());
|
||||
reload_button.set_fixed_width(22);
|
||||
auto& reload_button = *find_descendant_of_type_named<GUI::Button>("reload_button");
|
||||
reload_button.on_click = [&](auto) {
|
||||
static size_t i = 1;
|
||||
if (i >= pangrams.size())
|
||||
i = 0;
|
||||
preview_textbox.set_text(pangrams[i]);
|
||||
m_preview_textbox->set_text(pangrams[i]);
|
||||
i++;
|
||||
};
|
||||
|
||||
|
@ -196,13 +175,16 @@ ErrorOr<void> FontEditorWidget::create_actions()
|
|||
m_undo_selection->set_size(selection.size());
|
||||
});
|
||||
|
||||
m_open_preview_action = GUI::Action::create("&Preview Font", { Mod_Ctrl, Key_P }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
if (!m_font_preview_window)
|
||||
m_font_preview_window = create_font_preview_window(*this);
|
||||
m_font_preview_window->show();
|
||||
m_font_preview_window->move_to_front();
|
||||
m_open_preview_action = GUI::Action::create("&Preview Font", { Mod_Ctrl, Key_P }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png")), [&](auto&) {
|
||||
if (!m_font_preview_window) {
|
||||
if (auto maybe_window = create_preview_window(); maybe_window.is_error())
|
||||
warnln("Failed to create preview window: {}", maybe_window.error());
|
||||
else
|
||||
m_font_preview_window = maybe_window.release_value();
|
||||
}
|
||||
if (m_font_preview_window)
|
||||
m_font_preview_window->show();
|
||||
});
|
||||
m_open_preview_action->set_checked(false);
|
||||
m_open_preview_action->set_status_tip("Preview the current font");
|
||||
|
||||
bool show_metadata = Config::read_bool("FontEditor", "Layout", "ShowMetadata", true);
|
||||
|
@ -582,6 +564,9 @@ ErrorOr<void> FontEditorWidget::initialize(String const& path, RefPtr<Gfx::Bitma
|
|||
m_path = path;
|
||||
m_edited_font = edited_font;
|
||||
|
||||
if (m_preview_label)
|
||||
m_preview_label->set_font(*m_edited_font);
|
||||
|
||||
m_glyph_map_widget->set_font(*m_edited_font);
|
||||
m_glyph_editor_widget->initialize(*m_edited_font);
|
||||
did_resize_glyph_editor();
|
||||
|
@ -636,9 +621,6 @@ ErrorOr<void> FontEditorWidget::initialize(String const& path, RefPtr<Gfx::Bitma
|
|||
update_title();
|
||||
});
|
||||
|
||||
if (on_initialize)
|
||||
on_initialize();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,6 @@ public:
|
|||
bool is_showing_unicode_blocks() { return m_unicode_blocks; }
|
||||
void set_show_unicode_blocks(bool);
|
||||
|
||||
Function<void()> on_initialize;
|
||||
|
||||
private:
|
||||
FontEditorWidget();
|
||||
|
||||
|
@ -58,6 +56,7 @@ private:
|
|||
ErrorOr<void> create_models();
|
||||
ErrorOr<void> create_toolbars();
|
||||
ErrorOr<void> create_undo_stack();
|
||||
ErrorOr<RefPtr<GUI::Window>> create_preview_window();
|
||||
|
||||
virtual void drop_event(GUI::DropEvent&) override;
|
||||
|
||||
|
@ -124,7 +123,6 @@ private:
|
|||
RefPtr<GUI::Action> m_rotate_counterclockwise_action;
|
||||
|
||||
RefPtr<GUI::Statusbar> m_statusbar;
|
||||
RefPtr<GUI::Window> m_font_preview_window;
|
||||
RefPtr<GUI::Widget> m_left_column_container;
|
||||
RefPtr<GUI::Widget> m_glyph_editor_container;
|
||||
RefPtr<GUI::Widget> m_unicode_block_container;
|
||||
|
@ -146,6 +144,10 @@ private:
|
|||
RefPtr<GUI::FilteringProxyModel> m_filter_model;
|
||||
RefPtr<GUI::Menu> m_context_menu;
|
||||
|
||||
RefPtr<GUI::Label> m_preview_label;
|
||||
RefPtr<GUI::TextBox> m_preview_textbox;
|
||||
RefPtr<GUI::Window> m_font_preview_window;
|
||||
|
||||
String m_path;
|
||||
Vector<String> m_font_weight_list;
|
||||
Vector<String> m_font_slope_list;
|
||||
|
|
35
Userland/Applications/FontEditor/FontPreviewWindow.gml
Normal file
35
Userland/Applications/FontEditor/FontPreviewWindow.gml
Normal file
|
@ -0,0 +1,35 @@
|
|||
@GUI::Widget {
|
||||
fill_with_background_color: true
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [2]
|
||||
}
|
||||
|
||||
@GUI::Frame {
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
}
|
||||
shape: "Box"
|
||||
shadow: "Sunken"
|
||||
thickness: 2
|
||||
|
||||
@GUI::Label {
|
||||
name: "preview_label"
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::HorizontalBoxLayout {}
|
||||
fixed_height: 22
|
||||
|
||||
@GUI::TextBox {
|
||||
name: "preview_textbox"
|
||||
placeholder: "Preview text"
|
||||
}
|
||||
|
||||
@GUI::Button {
|
||||
name: "reload_button"
|
||||
icon: "/res/icons/16x16/reload.png"
|
||||
fixed_width: 22
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue