fix(md_renderer_py): remove push_font for headings (API mismatch)
The imgui_bundle imgui.push_font() signature is: push_font(font: ImFont | None, font_size_base_unscaled: float) -> None We were calling it with one arg (the font). This crashed imgui at runtime, leaving imscope in a broken state and cascading to subsequent scope errors (Missing EndGroup, PopID too many times, Size > 0). Since we don't have a separate heading font configured, just skip the font push for headings. Headings render at the default font size and use a separator (for h1/h2) to look distinct. User can subclass MarkdownRenderer and override _handle_heading_open to add a custom font later. REMOVED: _get_heading_font method (no longer needed)
This commit is contained in:
@@ -203,11 +203,9 @@ class MarkdownRenderer:
|
||||
level = int(tok.tag[1])
|
||||
self._hlevel = level
|
||||
imgui.new_line()
|
||||
imgui.push_font(self._get_heading_font(level))
|
||||
return i + 1
|
||||
|
||||
def _handle_heading_close(self, tok, tokens, i):
|
||||
imgui.pop_font()
|
||||
self._hlevel = 0
|
||||
imgui.new_line()
|
||||
if self._hlevel <= 2:
|
||||
@@ -626,9 +624,3 @@ class MarkdownRenderer:
|
||||
def _pop_bold(self) -> None:
|
||||
imgui.pop_style_color()
|
||||
imgui.pop_style_color()
|
||||
|
||||
def _get_heading_font(self, level: int):
|
||||
try:
|
||||
return imgui.get_io().fonts.fonts[0]
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
@@ -61,9 +61,7 @@ def test_renderer_renders_h1_with_separator():
|
||||
with patch("src.md_renderer_py.imgui") as mock_imgui:
|
||||
_mock_imgui(mock_imgui)
|
||||
r.render("# Heading 1")
|
||||
assert mock_imgui.push_font.called
|
||||
assert mock_imgui.pop_font.called
|
||||
assert mock_imgui.separator.called
|
||||
assert mock_imgui.separator.called, "h1/h2 should render a separator after the heading"
|
||||
|
||||
def test_renderer_renders_bullet_list_with_bullets():
|
||||
r = MarkdownRenderer()
|
||||
|
||||
Reference in New Issue
Block a user