summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-03 03:06:58 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-03 03:06:58 +0100
commit663aad403650ef6509737657a8210f00a62ae14a (patch)
tree0326b8c62c61d336cfd9cab8f277861e3b006c04
parent5877feab1b69c79c4fa85211a1a60482025ad25d (diff)
downloadserenity-663aad403650ef6509737657a8210f00a62ae14a.zip
FontEditor: Add text box for editing the font name.
-rw-r--r--FontEditor/FontEditor.cpp10
-rw-r--r--FontEditor/FontEditor.h2
-rw-r--r--LibGUI/GTextBox.cpp6
-rw-r--r--LibGUI/GTextBox.h1
-rw-r--r--SharedGraphics/Font.h3
5 files changed, 21 insertions, 1 deletions
diff --git a/FontEditor/FontEditor.cpp b/FontEditor/FontEditor.cpp
index 774129dac6..8a2aa78e7d 100644
--- a/FontEditor/FontEditor.cpp
+++ b/FontEditor/FontEditor.cpp
@@ -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");
};
diff --git a/FontEditor/FontEditor.h b/FontEditor/FontEditor.h
index 7786edceb2..2274f41c34 100644
--- a/FontEditor/FontEditor.h
+++ b/FontEditor/FontEditor.h
@@ -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 {
diff --git a/LibGUI/GTextBox.cpp b/LibGUI/GTextBox.cpp
index cd04d3f156..f09c2cbe86 100644
--- a/LibGUI/GTextBox.cpp
+++ b/LibGUI/GTextBox.cpp
@@ -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;
}
diff --git a/LibGUI/GTextBox.h b/LibGUI/GTextBox.h
index 65ef7f0c9d..ad9c8dd5f8 100644
--- a/LibGUI/GTextBox.h
+++ b/LibGUI/GTextBox.h
@@ -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"; }
diff --git a/SharedGraphics/Font.h b/SharedGraphics/Font.h
index 08a7cb3ec3..b32d672b1f 100644
--- a/SharedGraphics/Font.h
+++ b/SharedGraphics/Font.h
@@ -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: