1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-26 01:35:08 +00:00

FontEditor: Simplify initialization by disabling widget callbacks

Reduces some complexity dealing with callback effects and fixes
redundant calls to update_title and erroneously set glyph widths.
This commit is contained in:
thankyouverycool 2021-09-21 17:24:09 -04:00 committed by Andreas Kling
parent 92fffc3abc
commit ca6cb6cec3
3 changed files with 22 additions and 26 deletions

View file

@ -390,9 +390,11 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
if (m_undo_glyph)
m_undo_glyph->set_code_point(glyph);
m_glyph_editor_widget->set_glyph(glyph);
auto glyph_width = m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph());
m_glyph_editor_width_spinbox->set_value(glyph_width);
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0);
auto glyph_width = m_edited_font->raw_glyph_width(glyph);
if (m_edited_font->is_fixed_width())
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0, GUI::AllowCallback::No);
else
m_glyph_editor_width_spinbox->set_value(glyph_width, GUI::AllowCallback::No);
update_statusbar();
};
@ -410,17 +412,15 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
m_edited_font->set_fixed_width(checked);
auto glyph_width = m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph());
m_glyph_editor_width_spinbox->set_visible(!checked);
m_glyph_editor_width_spinbox->set_value(glyph_width);
m_glyph_editor_width_spinbox->set_value(glyph_width, GUI::AllowCallback::No);
m_glyph_editor_present_checkbox->set_visible(checked);
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0);
m_glyph_editor_present_checkbox->set_checked(glyph_width > 0, GUI::AllowCallback::No);
m_glyph_editor_widget->update();
update_demo();
did_modify_font();
};
m_glyph_editor_width_spinbox->on_change = [this, update_demo, update_statusbar](int value) {
if (m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) == value)
return;
m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), value);
m_glyph_editor_widget->update();
m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_glyph());
@ -430,10 +430,6 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
};
m_glyph_editor_present_checkbox->on_checked = [this, update_demo, update_statusbar](bool checked) {
if (!m_edited_font->is_fixed_width()
|| m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) == checked
|| (m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) && checked))
return;
m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), checked ? m_edited_font->glyph_fixed_width() : 0);
m_glyph_editor_widget->update();
m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_glyph());
@ -503,20 +499,25 @@ void FontEditorWidget::initialize(const String& path, RefPtr<Gfx::BitmapFont>&&
m_glyph_editor_container->set_fixed_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height());
m_left_column_container->set_fixed_width(m_glyph_editor_widget->preferred_width());
m_glyph_editor_width_spinbox->set_visible(!m_edited_font->is_fixed_width());
m_glyph_editor_width_spinbox->set_max(m_edited_font->max_glyph_width());
m_glyph_editor_width_spinbox->set_max(m_edited_font->max_glyph_width(), GUI::AllowCallback::No);
m_glyph_editor_width_spinbox->set_value(m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()), GUI::AllowCallback::No);
m_glyph_editor_present_checkbox->set_visible(m_edited_font->is_fixed_width());
m_glyph_editor_present_checkbox->set_checked(m_edited_font->raw_glyph_width(m_glyph_map_widget->selected_glyph()) > 0, GUI::AllowCallback::No);
m_fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width(), GUI::AllowCallback::No);
m_name_textbox->set_text(m_edited_font->name());
m_family_textbox->set_text(m_edited_font->family());
m_name_textbox->set_text(m_edited_font->name(), GUI::AllowCallback::No);
m_family_textbox->set_text(m_edited_font->family(), GUI::AllowCallback::No);
m_presentation_spinbox->set_value(m_edited_font->presentation_size());
m_spacing_spinbox->set_value(m_edited_font->glyph_spacing());
m_presentation_spinbox->set_value(m_edited_font->presentation_size(), GUI::AllowCallback::No);
m_spacing_spinbox->set_value(m_edited_font->glyph_spacing(), GUI::AllowCallback::No);
m_mean_line_spinbox->set_range(0, max(m_edited_font->glyph_height() - 2, 0), false);
m_baseline_spinbox->set_range(0, max(m_edited_font->glyph_height() - 2, 0), false);
m_mean_line_spinbox->set_value(m_edited_font->mean_line());
m_baseline_spinbox->set_value(m_edited_font->baseline());
m_mean_line_spinbox->set_range(0, max(m_edited_font->glyph_height() - 2, 0), GUI::AllowCallback::No);
m_baseline_spinbox->set_range(0, max(m_edited_font->glyph_height() - 2, 0), GUI::AllowCallback::No);
m_mean_line_spinbox->set_value(m_edited_font->mean_line(), GUI::AllowCallback::No);
m_baseline_spinbox->set_value(m_edited_font->baseline(), GUI::AllowCallback::No);
m_font_weight_list.clear();
for (auto& it : GUI::font_weight_names)
@ -532,13 +533,9 @@ void FontEditorWidget::initialize(const String& path, RefPtr<Gfx::BitmapFont>&&
i++;
}
m_fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width());
m_glyph_map_widget->set_selected_glyph('A');
deferred_invoke([this] {
m_glyph_map_widget->set_focus(true);
m_glyph_map_widget->scroll_to_glyph(m_glyph_map_widget->selected_glyph());
window()->set_modified(false);
update_title();
});

View file

@ -24,7 +24,6 @@ void GlyphEditorWidget::initialize(Gfx::BitmapFont& mutable_font)
return;
m_font = mutable_font;
set_relative_rect({ 0, 0, preferred_width(), preferred_height() });
m_glyph = 0;
}
void GlyphEditorWidget::set_glyph(int glyph)

View file

@ -25,8 +25,8 @@ void GlyphMapWidget::initialize(Gfx::BitmapFont& mutable_font)
if (m_font == mutable_font)
return;
m_font = mutable_font;
m_selected_glyph = 0;
vertical_scrollbar().set_step(font().glyph_height() + m_vertical_spacing);
set_selected_glyph('A');
}
void GlyphMapWidget::resize_event(GUI::ResizeEvent& event)