Skip to content

Commit 0a6a5aa

Browse files
committed
[Bundle] mark binding exclusions with IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
1 parent f4a85ad commit 0a6a5aa

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@
1111
![Maintained](https://img.shields.io/maintenance/yes/2026?style=for-the-badge)
1212
![Version](https://img.shields.io/badge/version-0.9-blue?style=for-the-badge)
1313

14-
# Colorizing Text Editor and Text Diff for Dear ImGui
15-
1614
</div>
1715

16+
---
17+
18+
# About this fork
19+
20+
The imgui_bundle branch of this fork is used in [Dear ImGui Bundle](https://github.com/pthom/imgui_bundle).
21+
22+
It is based on the most maintained fork of the original ImGuiColorTextEdit repository which is available at
23+
https://github.com/goossens/ImGuiColorTextEdit.
24+
25+
Very small adaptations are made to make it work with Python bindings (preprocessor guards for unbindable APIs, and a few convenience structs like `CursorPosition`/`CursorSelection`).
26+
27+
Many thanks to @goossens for providing a well-designed rewrite of ImGuiColorTextEdit!
28+
29+
---
30+
31+
# Colorizing Text Editor and Text Diff for Dear ImGui
32+
1833
TextEdit is a syntax highlighting text editor for
1934
[Dear ImGui](https://github.com/ocornut/imgui) and it was originally developed by
2035
[Balázs Jákó](https://github.com/BalazsJako/ImGuiColorTextEdit). Unfortunately, he no

TextEditor.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include "imgui.h"
2828

29+
// [Bundle] IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API is always defined,
30+
// but is used as a marker to exclude certain sections from the python bindings generation.
31+
#define IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
2932

3033
//
3134
// TextEditor
@@ -141,14 +144,18 @@ class TextEditor {
141144
inline bool CurrentCursorHasSelection() const { return cursors.currentCursorHasSelection(); }
142145
inline void ClearCursors() { cursors.clearAll(); }
143146

144-
// get cursor positions (the meaning of main and current is explained in README.md)
145147
inline size_t GetNumberOfCursors() const { return cursors.size(); }
148+
149+
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
150+
// get cursor positions (the meaning of main and current is explained in README.md)
146151
inline void GetCursor(int& line, int& column, size_t cursor) const { return getCursor(line, column, cursor); }
147152
inline void GetCursor(int& startLine, int& startColumn, int& endLine, int& endColumn, size_t cursor) const { return getCursor(startLine, startColumn, endLine, endColumn, cursor); }
148153
inline void GetMainCursor(int& line, int& column) const { return getCursor(line, column, cursors.getMainIndex()); }
149154
inline void GetCurrentCursor(int& line, int& column) const { return getCursor(line, column, cursors.getCurrentIndex()); }
155+
#endif // #ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
150156

151157
// Alternative API for cursor and selection position using lightweight out struct (line and column are zero-based)
158+
// (the meaning of main and current is explained in README.md)
152159
struct CursorPosition { int line = 0; int column = 0; };
153160
struct CursorSelection { CursorPosition start; CursorPosition end; };
154161
inline CursorPosition GetMainCursorPosition() const { CursorPosition p; getCursor(p.line, p.column, cursors.getMainIndex()); return p; }
@@ -248,6 +255,7 @@ class TextEditor {
248255
// passing nullptr deactivates the callback
249256
inline void SetTransactionCallback(std::function<void(std::vector<Change>&)> callback) { transactionCallback = callback; }
250257

258+
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
251259
// line-based callbacks (line numbers are zero-based)
252260
// insertor callback is called when for each line inserted and the result is used as the new line specific user data
253261
// deletor callback is called for each line deleted (line specific user data is passed to callback)
@@ -265,6 +273,7 @@ class TextEditor {
265273
inline void SetUserData(int line, void* data) { document.setUserData(line, data); }
266274
inline void* GetUserData(int line) const { return document.getUserData(line); }
267275
inline void IterateUserData(std::function<void(int line, void* data)> callback) const { document.iterateUserData(callback); }
276+
#endif // IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
268277

269278
// line-based decoration
270279
struct Decorator {
@@ -401,6 +410,7 @@ class TextEditor {
401410
// name of the language
402411
std::string name;
403412

413+
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
404414
// flag to describe if keywords and identifiers are case sensitive (which is the default)
405415
bool caseSensitive = true;
406416

@@ -451,6 +461,7 @@ class TextEditor {
451461
// function to implement custom tokenizer
452462
// if a token is found, function should return an iterator to the character after the token and set the color
453463
std::function<Iterator(Iterator start, Iterator end, Color& color)> customTokenizer;
464+
#endif // #ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
454465

455466
// predefined language definitions
456467
static const Language* C();
@@ -474,6 +485,7 @@ class TextEditor {
474485
// iterate through identifiers detected by the colorizer (based on current language)
475486
inline void IterateIdentifiers(std::function<void(const std::string& identifier)> callback) const { document.iterateIdentifiers(callback); }
476487

488+
#ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
477489
// autocomplete state (acts as API between editor and outer application)
478490
class AutoCompleteState {
479491
public:
@@ -727,6 +739,7 @@ class TextEditor {
727739
int line = 0;
728740
int column = 0;
729741
};
742+
#endif // #ifdef IMGUI_BUNDLE_PYTHON_UNSUPPORTED_API
730743

731744
// a single cursor
732745
class Cursor {

0 commit comments

Comments
 (0)