summaryrefslogtreecommitdiff
path: root/DevTools
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-27 20:43:34 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-10-27 20:44:37 +0100
commite2c74762ffcc29c5bb267eec4c61b9e09d671b43 (patch)
tree170e341691670ffd7d50d4629c0912909e9d882f /DevTools
parente2d7f585da82098872c4dda1bd58174b15f19d18 (diff)
downloadserenity-e2c74762ffcc29c5bb267eec4c61b9e09d671b43.zip
HackStudio: Draw a brownish frame around the current editor widget
Also make the editor filename label bold only for the current editor.
Diffstat (limited to 'DevTools')
-rw-r--r--DevTools/HackStudio/Editor.cpp35
-rw-r--r--DevTools/HackStudio/Editor.h9
-rw-r--r--DevTools/HackStudio/EditorWrapper.cpp6
-rw-r--r--DevTools/HackStudio/EditorWrapper.h2
4 files changed, 50 insertions, 2 deletions
diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp
index 073658fecf..fe0666d48f 100644
--- a/DevTools/HackStudio/Editor.cpp
+++ b/DevTools/HackStudio/Editor.cpp
@@ -1,9 +1,44 @@
#include "Editor.h"
#include "EditorWrapper.h"
+#include <LibGUI/GPainter.h>
+#include <LibGUI/GScrollBar.h>
+
+EditorWrapper& Editor::wrapper()
+{
+ return static_cast<EditorWrapper&>(*parent());
+}
+const EditorWrapper& Editor::wrapper() const
+{
+ return static_cast<const EditorWrapper&>(*parent());
+}
void Editor::focusin_event(CEvent& event)
{
+ wrapper().set_editor_has_focus({}, true);
if (on_focus)
on_focus();
GTextEditor::focusin_event(event);
}
+
+void Editor::focusout_event(CEvent & event)
+{
+ wrapper().set_editor_has_focus({}, false);
+ GTextEditor::focusout_event(event);
+}
+
+void Editor::paint_event(GPaintEvent& event)
+{
+ GTextEditor::paint_event(event);
+
+ if (is_focused()) {
+ GPainter painter(*this);
+ painter.add_clip_rect(event.rect());
+
+ auto rect = frame_inner_rect();
+ if (vertical_scrollbar().is_visible())
+ rect.set_width(rect.width() - vertical_scrollbar().width());
+ if (horizontal_scrollbar().is_visible())
+ rect.set_height(rect.height() - horizontal_scrollbar().height());
+ painter.draw_rect(rect, Color::from_rgb(0x955233));
+ }
+}
diff --git a/DevTools/HackStudio/Editor.h b/DevTools/HackStudio/Editor.h
index 349984eaab..92858b9e69 100644
--- a/DevTools/HackStudio/Editor.h
+++ b/DevTools/HackStudio/Editor.h
@@ -2,6 +2,8 @@
#include <LibGUI/GTextEditor.h>
+class EditorWrapper;
+
class Editor final : public GTextEditor {
C_OBJECT(Editor)
public:
@@ -9,8 +11,13 @@ public:
Function<void()> on_focus;
+ EditorWrapper& wrapper();
+ const EditorWrapper& wrapper() const;
+
private:
- virtual void focusin_event(CEvent& event) override;
+ virtual void focusin_event(CEvent&) override;
+ virtual void focusout_event(CEvent&) override;
+ virtual void paint_event(GPaintEvent&) override;
Editor(GWidget* parent)
: GTextEditor(GTextEditor::MultiLine, parent)
diff --git a/DevTools/HackStudio/EditorWrapper.cpp b/DevTools/HackStudio/EditorWrapper.cpp
index 452b16c6a6..4a45d2b65d 100644
--- a/DevTools/HackStudio/EditorWrapper.cpp
+++ b/DevTools/HackStudio/EditorWrapper.cpp
@@ -20,7 +20,6 @@ EditorWrapper::EditorWrapper(GWidget* parent)
label_wrapper->layout()->set_margins({ 2, 0, 2, 0 });
m_filename_label = GLabel::construct("(Untitled)", label_wrapper);
- m_filename_label->set_font(Font::default_bold_font());
m_filename_label->set_text_alignment(TextAlignment::CenterLeft);
m_filename_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
m_filename_label->set_preferred_size(0, 14);
@@ -61,3 +60,8 @@ EditorWrapper::EditorWrapper(GWidget* parent)
EditorWrapper::~EditorWrapper()
{
}
+
+void EditorWrapper::set_editor_has_focus(Badge<Editor>, bool focus)
+{
+ m_filename_label->set_font(focus ? Font::default_bold_font() : Font::default_font());
+}
diff --git a/DevTools/HackStudio/EditorWrapper.h b/DevTools/HackStudio/EditorWrapper.h
index b0b932525f..2180d8da73 100644
--- a/DevTools/HackStudio/EditorWrapper.h
+++ b/DevTools/HackStudio/EditorWrapper.h
@@ -15,6 +15,8 @@ public:
GLabel& filename_label() { return *m_filename_label; }
+ void set_editor_has_focus(Badge<Editor>, bool);
+
private:
explicit EditorWrapper(GWidget* parent = nullptr);