mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 23:48:11 +00:00
HackStudio: Draw a brownish frame around the current editor widget
Also make the editor filename label bold only for the current editor.
This commit is contained in:
parent
e2d7f585da
commit
e2c74762ff
4 changed files with 50 additions and 2 deletions
|
@ -1,9 +1,44 @@
|
||||||
#include "Editor.h"
|
#include "Editor.h"
|
||||||
#include "EditorWrapper.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)
|
void Editor::focusin_event(CEvent& event)
|
||||||
{
|
{
|
||||||
|
wrapper().set_editor_has_focus({}, true);
|
||||||
if (on_focus)
|
if (on_focus)
|
||||||
on_focus();
|
on_focus();
|
||||||
GTextEditor::focusin_event(event);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <LibGUI/GTextEditor.h>
|
#include <LibGUI/GTextEditor.h>
|
||||||
|
|
||||||
|
class EditorWrapper;
|
||||||
|
|
||||||
class Editor final : public GTextEditor {
|
class Editor final : public GTextEditor {
|
||||||
C_OBJECT(Editor)
|
C_OBJECT(Editor)
|
||||||
public:
|
public:
|
||||||
|
@ -9,8 +11,13 @@ public:
|
||||||
|
|
||||||
Function<void()> on_focus;
|
Function<void()> on_focus;
|
||||||
|
|
||||||
|
EditorWrapper& wrapper();
|
||||||
|
const EditorWrapper& wrapper() const;
|
||||||
|
|
||||||
private:
|
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)
|
Editor(GWidget* parent)
|
||||||
: GTextEditor(GTextEditor::MultiLine, parent)
|
: GTextEditor(GTextEditor::MultiLine, parent)
|
||||||
|
|
|
@ -20,7 +20,6 @@ EditorWrapper::EditorWrapper(GWidget* parent)
|
||||||
label_wrapper->layout()->set_margins({ 2, 0, 2, 0 });
|
label_wrapper->layout()->set_margins({ 2, 0, 2, 0 });
|
||||||
|
|
||||||
m_filename_label = GLabel::construct("(Untitled)", label_wrapper);
|
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_text_alignment(TextAlignment::CenterLeft);
|
||||||
m_filename_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
m_filename_label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
m_filename_label->set_preferred_size(0, 14);
|
m_filename_label->set_preferred_size(0, 14);
|
||||||
|
@ -61,3 +60,8 @@ EditorWrapper::EditorWrapper(GWidget* parent)
|
||||||
EditorWrapper::~EditorWrapper()
|
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());
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ public:
|
||||||
|
|
||||||
GLabel& filename_label() { return *m_filename_label; }
|
GLabel& filename_label() { return *m_filename_label; }
|
||||||
|
|
||||||
|
void set_editor_has_focus(Badge<Editor>, bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit EditorWrapper(GWidget* parent = nullptr);
|
explicit EditorWrapper(GWidget* parent = nullptr);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue