feat(markdown): implement table rendering with imgui.begin_table
This commit is contained in:
@@ -1,8 +1,28 @@
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from imgui_bundle import imgui
|
||||
|
||||
_TABLE_SEPARATOR = re.compile(r"^\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)+\|?\s*$")
|
||||
|
||||
def render_table(block: "TableBlock") -> None:
|
||||
"""Render a GFM table block via imgui.begin_table.
|
||||
[C: src/markdown_helper.py:MarkdownRenderer.render]
|
||||
"""
|
||||
n_cols = len(block.headers)
|
||||
if n_cols == 0: return
|
||||
flags = imgui.TableFlags_.borders | imgui.TableFlags_.row_bg | imgui.TableFlags_.resizable
|
||||
if not imgui.begin_table("md_table", n_cols, flags): return
|
||||
imgui.table_headers_row()
|
||||
for h in block.headers:
|
||||
imgui.table_next_column()
|
||||
imgui.text(h)
|
||||
for row in block.rows:
|
||||
imgui.table_next_row()
|
||||
for c in row:
|
||||
imgui.table_next_column()
|
||||
imgui.text(c)
|
||||
imgui.end_table()
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TableBlock:
|
||||
"""Frozen GFM table block.
|
||||
|
||||
Reference in New Issue
Block a user