Skip to content

Commit

Permalink
Merge c08ad9b into f9f45a5
Browse files Browse the repository at this point in the history
  • Loading branch information
swistakm committed Jul 21, 2020
2 parents f9f45a5 + c08ad9b commit 146e9ec
Show file tree
Hide file tree
Showing 10 changed files with 1,146 additions and 767 deletions.
2 changes: 1 addition & 1 deletion imgui-cpp
Submodule imgui-cpp updated 135 files
396 changes: 2 additions & 394 deletions imgui/__init__.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion imgui/cimgui.pxd
Expand Up @@ -107,7 +107,7 @@ cdef extern from "imgui.h":
ImVec2 DisplayVisibleMax #
bool ConfigMacOSXBehaviors #
bool ConfigInputTextCursorBlink #
bool ConfigResizeWindowsFromEdges #
bool ConfigWindowsResizeFromEdges #

# ====
# source-note: User Functions
Expand Down
396 changes: 219 additions & 177 deletions imgui/core.pyx

Large diffs are not rendered by default.

423 changes: 229 additions & 194 deletions imgui/enums.pxd

Large diffs are not rendered by default.

431 changes: 431 additions & 0 deletions imgui/flags.py

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions update-tools/core.pyx.jinja2
@@ -0,0 +1,47 @@
# ==== Condition enum redefines ====
{{ parser.fields_of("ImGuiCond_") }}

# ==== Style var enum redefines ====
{{ parser.fields_of("ImGuiStyleVar_", prefix="STYLE_") }}

# ==== Key map enum redefines ====
{{ parser.fields_of("ImGuiKey_", prefix="KEY_") }}

# ==== Window flags enum redefines ====
{{ parser.fields_of("ImGuiWindowFlags_", prefix="WINDOW_") }}

# ==== TreeNode flags enum redefines ====
{{ parser.fields_of("ImGuiTreeNodeFlags_", prefix="TREE_NODE_") }}

# ==== Selectable flags enum redefines ====
{{ parser.fields_of("ImGuiSelectableFlags_", prefix="SELECTABLE_") }}

# ==== Combo flags enum redefines ====
{{ parser.fields_of("ImGuiComboFlags_", prefix="COMBO_") }}

# === Focus flag enum redefines ====
{{ parser.fields_of("ImGuiFocusedFlags_", prefix="FOCUS_") }}

# === Hovered flag enum redefines ====
{{ parser.fields_of("ImGuiHoveredFlags_", prefix="HOVERED_") }}

# === Drag Drop flag enum redefines ====
{{ parser.fields_of("ImGuiDragDropFlags_", prefix="DRAG_DROP_") }}

# === Cardinal Direction enum redefines ====
{{ parser.fields_of("ImGuiDir_", prefix="DIRECTION_") }}

# ==== Mouse Cursors ====
{{ parser.fields_of("ImGuiMouseCursor_", prefix="MOUSE_CURSOR_") }}

# ==== Color identifiers for styling ====
{{ parser.fields_of("ImGuiCol_", prefix="COLOR_") }}

# ==== Text input flags ====
{{ parser.fields_of("ImGuiInputTextFlags_", prefix="INPUT_TEXT") }}

# ==== Config Flags ====
{{ parser.fields_of("ImGuiConfigFlags_", prefix="CONFIG_") }}

# ==== Backend Flags ====
{{ parser.fields_of("ImGuiBackendFlags_", prefix="BACKEND_") }}
57 changes: 57 additions & 0 deletions update-tools/enums.pxd.jinja2
@@ -0,0 +1,57 @@
cdef extern from "imgui.h":
ctypedef enum ImGuiKey_:
{{ parser.fields_of("ImGuiKey_") | indent(8)}}

ctypedef enum ImGuiNavInput_:
{{ parser.fields_of("ImGuiNavInput_") | indent(8)}}

ctypedef enum ImGuiConfigFlags_:
{{ parser.fields_of("ImGuiConfigFlags_") | indent(8)}}

ctypedef enum ImGuiBackendFlags_:
{{ parser.fields_of("ImGuiBackendFlags_") | indent(8)}}

ctypedef enum ImGuiCol_:
{{ parser.fields_of("ImGuiCol_") | indent(8)}}

ctypedef enum ImGuiDataType_:
{{ parser.fields_of("ImGuiDataType_") | indent(8)}}

ctypedef enum ImGuiStyleVar_:
{{ parser.fields_of("ImGuiStyleVar_") | indent(8)}}

ctypedef enum ImGuiCond_:
{{ parser.fields_of("ImGuiCond_") | indent(8)}}

ctypedef enum ImGuiWindowFlags_:
{{ parser.fields_of("ImGuiWindowFlags_") | indent(8)}}

ctypedef enum ImGuiColorEditFlags_:
{{ parser.fields_of("ImGuiColorEditFlags_") | indent(8)}}

ctypedef enum ImGuiTreeNodeFlags_:
{{ parser.fields_of("ImGuiTreeNodeFlags_") | indent(8)}}

ctypedef enum ImGuiSelectableFlags_:
{{ parser.fields_of("ImGuiSelectableFlags_") | indent(8)}}

ctypedef enum ImGuiComboFlags_:
{{ parser.fields_of("ImGuiComboFlags_") | indent(8)}}

ctypedef enum ImGuiFocusedFlags_:
{{ parser.fields_of("ImGuiFocusedFlags_") | indent(8)}}

ctypedef enum ImGuiHoveredFlags_:
{{ parser.fields_of("ImGuiHoveredFlags_") | indent(8)}}

ctypedef enum ImGuiDragDropFlags_:
{{ parser.fields_of("ImGuiDragDropFlags_") | indent(8)}}

ctypedef enum ImGuiDir_:
{{ parser.fields_of("ImGuiDir_") | indent(8)}}

ctypedef enum ImGuiMouseCursor_:
{{ parser.fields_of("ImGuiMouseCursor_") | indent(8)}}

ctypedef enum ImGuiInputTextFlags_:
{{ parser.fields_of("ImGuiInputTextFlags_") | indent(8)}}
110 changes: 110 additions & 0 deletions update-tools/enums.py
@@ -0,0 +1,110 @@
import os
import re

import click
import inflection

import jinja2

loader = jinja2.FileSystemLoader(searchpath="./")
env = jinja2.Environment(loader=loader)
base_dir = os.path.dirname(__file__)


def extract_comment(line):
parts = line.split("//")
if len(parts) > 1:
return "//".join(map(str.strip, parts[1:]))
else:
return ""


def pxd_format(field, comment, max_len):
if comment:
return field + " " * (max_len - len(field) + 2) + "# " + comment
else:
return field


def pyx_format(field, comment, max_len, prefix=""):
key = inflection.underscore(field.split("_", 1)[-1]).upper()

return "{prefix}{key} = enums.{field}{comment}".format(
prefix=prefix, key=key, field=field,
comment=" # " + comment if comment else ""
)


def py_format(field, comment, max_len, prefix=""):
key = inflection.underscore(field.split("_", 1)[-1]).upper()

return "{comment}{prefix}{key} = core.{prefix}{key}".format(
prefix=prefix, key=key,
comment="#: " + comment + "\n" if comment else ""
)


class EnumParser:
FIELD_RE_TEMPLATE = r"\s+({name}_?\w+)[,\s=]?"

def __init__(self, header_file, formatter):
self.formatter = formatter

with open(header_file) as f:
self.contents = f.readlines()

def fields_of(self, name, **format_kwargs):
fields = []
started = False
regexp = re.compile(self.FIELD_RE_TEMPLATE.format(name=name))

for line in self.contents:
if not started and line.startswith("enum {}".format(name)):
started = True
continue
elif started and "}" in line:
break
elif started:
match = regexp.match(line)
if match:
comment = extract_comment(line)
field = match.groups()[0]
fields.append((field, comment))

max_len = max(map(lambda x: len(x[0]), fields))
out_lines = []

for field, comment in fields:
out_lines.append(self.formatter(field, comment, max_len, **format_kwargs))

return "\n".join(out_lines)


@click.group()
def cli():
pass


@cli.command()
def pxd():
template = env.get_template(os.path.join(base_dir, "enums.pxd.jinja2"))
parser = EnumParser(os.path.join(base_dir, "..", "imgui-cpp", "imgui.h"), pxd_format)
click.echo(template.render(parser=parser))


@cli.command()
def py():
template = env.get_template(os.path.join(base_dir, "flags.py.jinja2"))
parser = EnumParser(os.path.join(base_dir, "..", "imgui-cpp", "imgui.h"), py_format)
click.echo(template.render(parser=parser))


@cli.command()
def pyx():
template = env.get_template(os.path.join(base_dir, "core.pyx.jinja2"))
parser = EnumParser(os.path.join(base_dir, "..", "imgui-cpp", "imgui.h"), pyx_format)
click.echo(template.render(parser=parser))


if __name__ == "__main__":
cli()
49 changes: 49 additions & 0 deletions update-tools/flags.py.jinja2
@@ -0,0 +1,49 @@
from imgui import core

# ==== Condition enum redefines ====
{{ parser.fields_of("ImGuiCond_") }}

# ==== Style var enum redefines ====
{{ parser.fields_of("ImGuiStyleVar_", prefix="STYLE_") }}

# ==== Key map enum redefines ====
{{ parser.fields_of("ImGuiKey_", prefix="KEY_") }}

# ==== Window flags enum redefines ====
{{ parser.fields_of("ImGuiWindowFlags_", prefix="WINDOW_") }}

# ==== TreeNode flags enum redefines ====
{{ parser.fields_of("ImGuiTreeNodeFlags_", prefix="TREE_NODE_") }}

# ==== Selectable flags enum redefines ====
{{ parser.fields_of("ImGuiSelectableFlags_", prefix="SELECTABLE_") }}

# ==== Combo flags enum redefines ====
{{ parser.fields_of("ImGuiComboFlags_", prefix="COMBO_") }}

# === Focus flag enum redefines ====
{{ parser.fields_of("ImGuiFocusedFlags_", prefix="FOCUS_") }}

# === Hovered flag enum redefines ====
{{ parser.fields_of("ImGuiHoveredFlags_", prefix="HOVERED_") }}

# === Drag Drop flag enum redefines ====
{{ parser.fields_of("ImGuiDragDropFlags_", prefix="DRAG_DROP_") }}

# === Cardinal Direction enum redefines ====
{{ parser.fields_of("ImGuiDir_", prefix="DIRECTION_") }}

# ==== Mouse Cursors ====
{{ parser.fields_of("ImGuiMouseCursor_", prefix="MOUSE_CURSOR_") }}

# ==== Color identifiers for styling ====
{{ parser.fields_of("ImGuiCol_", prefix="COLOR_") }}

# ==== Text input flags ====
{{ parser.fields_of("ImGuiInputTextFlags_", prefix="INPUT_TEXT") }}

# ==== Config Flags ====
{{ parser.fields_of("ImGuiConfigFlags_", prefix="CONFIG_") }}

# ==== Backend Flags ====
{{ parser.fields_of("ImGuiBackendFlags_", prefix="BACKEND_") }}

0 comments on commit 146e9ec

Please sign in to comment.