Skip to content

Commit

Permalink
Migrate source text editor to its own class and add line numbers
Browse files Browse the repository at this point in the history
Note that currently line numbers aren't really that visible, so going
forward some better styling has to be sorted (which will probably be
done when lexers are added to the SrcEditor class)
  • Loading branch information
kosude committed Jun 6, 2024
1 parent d9f1fe2 commit d3441f4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions texedit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(TARGET_NAME "${PROJECT_NAME}")
set(DEPS_DIR "${CMAKE_CURRENT_LIST_DIR}/../deps/")

set(SRCS
"gui/editor/src_editor_component.cpp"
"gui/layout/panes/editor_pane.cpp"
"gui/layout/panes/explorer_pane.cpp"
"gui/layout/panes/output_pane.cpp"
Expand Down
23 changes: 23 additions & 0 deletions texedit/gui/editor/src_editor_component.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Jack Bennett.
* All Rights Reserved.
*
* See the LICENCE file for more information.
*/

#include "src_editor_component.hpp"

namespace te::gui::editor {
SrcEditor::SrcEditor(wxWindow *parent) : wxStyledTextCtrl(parent) {
// TODO: set colours depending on dark or light theme
// TODO: note that the theme might be system dependent, as on macOS, so properly managing themes with some sort of manager class would be best
SetMarginType(1, wxSTC_MARGIN_NUMBER);
SetMarginMask(1, 0);
SetMarginWidth(1, 20);

// TODO lexers for styling and syntax highlighting.
}

SrcEditor::~SrcEditor() {
}
}
24 changes: 24 additions & 0 deletions texedit/gui/editor/src_editor_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024 Jack Bennett.
* All Rights Reserved.
*
* See the LICENCE file for more information.
*/

#pragma once
#ifndef __devinit__src_editor_component_hpp__
#define __devinit__src_editor_component_hpp__

#include <wx/stc/stc.h>

namespace te::gui::editor {
class SrcEditor : public wxStyledTextCtrl {
public:
SrcEditor(wxWindow *parent);
~SrcEditor();

private:
};
}

#endif
5 changes: 3 additions & 2 deletions texedit/gui/layout/panes/editor_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/

#include "editor_pane.hpp"
#include "gui/editor/src_editor_component.hpp"

namespace te::gui {
EditorPane::EditorPane(wxWindow *parent) : PaneBase{parent} {
_stc = new wxStyledTextCtrl(this, wxID_ANY);
_src_editor = new editor::SrcEditor(this);

_sizer = new wxBoxSizer(wxVERTICAL);
_sizer->Add(_stc, 1, wxEXPAND);
_sizer->Add(_src_editor, 1, wxEXPAND);
SetSizer(_sizer);
}
}
4 changes: 3 additions & 1 deletion texedit/gui/layout/panes/editor_pane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <wx/wx.h>
#include <wx/stc/stc.h>
#include "pane_base.hpp"
#include "gui/editor/src_editor_component.hpp"

namespace te::gui {
class EditorPane : public PaneBase {
Expand All @@ -20,7 +21,8 @@ namespace te::gui {

private:
wxBoxSizer *_sizer;
wxStyledTextCtrl *_stc;

editor::SrcEditor *_src_editor;
};
}

Expand Down

0 comments on commit d3441f4

Please sign in to comment.