-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
You may change the markdown options by tweaking AddOnParams before starting the app. |
Beta Was this translation helpful? Give feedback.
-
Seems I am misunderstanding something. Neither setting the initial font size nor changing the font size of the markdown text is working in the following code. from imgui_bundle import imgui, immapp, imgui_ctx, hello_imgui, imgui_md
import os
markdown = r"""
Markdown Font Test
Test Test Test Test Test Test
<u>Underline</u>
~~Strikethrough~~
"""
class Globals:
def __init__(self):
self.font1 = None
self.font2 = None
self.md_options = imgui_md.MarkdownOptions()
self.default_font_path = os.path.join("fonts/Roboto", "Roboto-Regular.ttf")
def setup_markdown(self, font_size=20):
font_opt = imgui_md.MarkdownFontOptions()
font_opt.font_base_path = self.default_font_path
font_opt.regular_size = font_size
self.md_options.font_options = font_opt
def on_change_md_fontsize(self):
self.md_options.font_options.regular_size = 30
gl = Globals()
def create_gui():
gl.setup_markdown()
with imgui_ctx.begin("Markdown Font Test"):
imgui.new_line()
with imgui_ctx.push_font(gl.font1):
imgui.text("Font 1")
imgui.new_line()
imgui.new_line()
with imgui_ctx.push_font(gl.font2):
imgui.text("Font 2")
imgui.new_line()
imgui.new_line()
imgui.separator()
imgui_md.render(markdown)
imgui.separator()
imgui.new_line()
imgui.new_line()
if imgui.button("Change_Markdown_Font_Size"):
gl.on_change_md_fontsize()
def main():
runner_params = hello_imgui.RunnerParams()
runner_params.app_window_params.window_geometry.size = (800, 600)
runner_params.app_window_params.window_title = "Font_Test"
runner_params.callbacks.show_gui = create_gui
# -----------------------------------------------------------------
addons = immapp.AddOnsParams()
addons.with_markdown = True
addons.with_markdown_options = gl.md_options
# -----------------------------------------------------------------
def load_font():
gl.font1 = hello_imgui.load_font_ttf(gl.default_font_path, 20)
gl.font2 = hello_imgui.load_font_ttf(gl.default_font_path, 30)
runner_params.callbacks.load_additional_fonts = load_font
# -----------------------------------------------------------------
immapp.run(runner_params, addons)
# ---------------------------------------------------------------------
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
-
"before starting the app" means that you cannot expect your call to setup_markdown() to have any effect in the GUI. You should gave changed the md options before this
|
Beta Was this translation helpful? Give feedback.
-
Setting up the markdown options after the initialization of from imgui_bundle import imgui, immapp, imgui_ctx, hello_imgui, imgui_md
import os
markdown = r"""
Markdown Font Test
Test Test Test Test Test Test
<u>Underline</u>
~~Strikethrough~~
"""
class Globals:
def __init__(self):
self.font1 = None
self.font2 = None
self.md_options = imgui_md.MarkdownOptions()
self.default_font_path = os.path.join("fonts/Roboto", "Roboto-Regular.ttf")
def setup_markdown(self, font_size=20):
font_opt = imgui_md.MarkdownFontOptions()
font_opt.font_base_path = self.default_font_path
font_opt.regular_size = font_size
self.md_options.font_options = font_opt
def on_change_md_fontsize(self):
self.md_options.font_options.regular_size = 30
gl = Globals()
def create_gui():
with imgui_ctx.begin("Markdown Font Test"):
imgui.new_line()
with imgui_ctx.push_font(gl.font1):
imgui.text("Font 1")
imgui.new_line()
imgui.new_line()
with imgui_ctx.push_font(gl.font2):
imgui.text("Font 2")
imgui.new_line()
imgui.new_line()
imgui.separator()
imgui_md.render(markdown)
imgui.separator()
imgui.new_line()
imgui.new_line()
if imgui.button("Change_Markdown_Font_Size"):
gl.on_change_md_fontsize()
def main():
runner_params = hello_imgui.RunnerParams()
runner_params.app_window_params.window_geometry.size = (800, 600)
runner_params.app_window_params.window_title = "Font_Test"
runner_params.callbacks.show_gui = create_gui
# -----------------------------------------------------------------
addons = immapp.AddOnsParams()
# addons.with_markdown = True
addons.with_markdown_options = gl.md_options
# -----------------------------------------------------------------
def load_font():
gl.font1 = hello_imgui.load_font_ttf(gl.default_font_path, 20)
gl.font2 = hello_imgui.load_font_ttf(gl.default_font_path, 30)
runner_params.callbacks.load_additional_fonts = load_font
# -----------------------------------------------------------------
gl.setup_markdown()
# -----------------------------------------------------------------
immapp.run(runner_params, addons)
# ---------------------------------------------------------------------
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
Please do more test before writing.
addons.with_markdown_options.font_options.regular_size = 60
before calling immapp.run does work.
The bug is in your code.