FontEditor: Add text box for editing the font name.

This commit is contained in:
Andreas Kling 2019-02-03 03:06:58 +01:00
parent 5877feab1b
commit 663aad4036
Notes: sideshowbarker 2024-07-19 15:53:26 +09:00
5 changed files with 21 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#include <SharedGraphics/Painter.h>
#include <LibGUI/GButton.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GTextBox.h>
FontEditorWidget::FontEditorWidget(GWidget* parent)
: GWidget(parent)
@ -16,9 +17,16 @@ FontEditorWidget::FontEditorWidget(GWidget* parent)
m_glyph_editor_widget = new GlyphEditorWidget(*m_edited_font, this);
m_glyph_editor_widget->move_to({ 5, 5 });
m_name_textbox = new GTextBox(this);
m_name_textbox->set_relative_rect({ 5, 135, 140, 20 });
m_name_textbox->set_text(m_edited_font->name());
m_name_textbox->on_change = [this] (GTextBox&) {
m_edited_font->set_name(m_name_textbox->text());
};
auto* save_button = new GButton(this);
save_button->set_caption("Save");
save_button->set_relative_rect({ 5, 135, 140, 20 });
save_button->set_relative_rect({ 5, 170, 140, 20 });
save_button->on_click = [this] (GButton&) {
m_edited_font->write_to_file("/saved.font");
};

View file

@ -5,6 +5,7 @@
class GlyphEditorWidget;
class GlyphMapWidget;
class GTextBox;
class FontEditorWidget final : public GWidget {
public:
@ -16,6 +17,7 @@ private:
GlyphMapWidget* m_glyph_map_widget { nullptr };
GlyphEditorWidget* m_glyph_editor_widget { nullptr };
GTextBox* m_name_textbox { nullptr };
};
class GlyphMapWidget final : public GWidget {

View file

@ -68,6 +68,8 @@ void GTextBox::handle_backspace()
if (m_text.length() == 1) {
m_text = String::empty();
m_cursor_position = 0;
if (on_change)
on_change(*this);
update();
return;
}
@ -80,6 +82,8 @@ void GTextBox::handle_backspace()
m_text = move(new_text);
--m_cursor_position;
if (on_change)
on_change(*this);
update();
}
@ -118,6 +122,8 @@ void GTextBox::keydown_event(GKeyEvent& event)
m_text = move(new_text);
++m_cursor_position;
if (on_change)
on_change(*this);
update();
return;
}

View file

@ -12,6 +12,7 @@ public:
void set_text(String&&);
Function<void(GTextBox&)> on_return_pressed;
Function<void(GTextBox&)> on_change;
private:
virtual const char* class_name() const override { return "GTextBox"; }

View file

@ -26,6 +26,9 @@ public:
byte glyph_width() const { return m_glyph_width; }
byte glyph_height() const { return m_glyph_height; }
String name() const { return m_name; }
void set_name(const String& name) { m_name = name; }
static void initialize();
private: