From 8b19f81e6494499c4d729a46c8ce004efcbf2d92 Mon Sep 17 00:00:00 2001 From: mokurin000 Date: Wed, 14 Jan 2026 15:17:45 +0800 Subject: [PATCH 1/4] feat: support passing custom fonts to imgui --- fastplotlib/layouts/_imgui_figure.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fastplotlib/layouts/_imgui_figure.py b/fastplotlib/layouts/_imgui_figure.py index 046c622ea..4cdcc02b6 100644 --- a/fastplotlib/layouts/_imgui_figure.py +++ b/fastplotlib/layouts/_imgui_figure.py @@ -45,6 +45,7 @@ def __init__( size: tuple[int, int] = (500, 300), names: list | np.ndarray = None, show_tooltips: bool = False, + custom_fonts: list[tuple[str, float]] = None, ): self._guis: dict[str, EdgeWindow] = {k: None for k in GUI_EDGES} @@ -95,6 +96,13 @@ def __init__( font_config, ) + for font_path, font_size in custom_fonts or []: + self._default_imgui_font = io.fonts.add_font_from_file_ttf( + font_path, + font_size, + font_config, + ) + imgui.push_font(self._default_imgui_font, self._default_imgui_font.legacy_size) self.imgui_renderer.set_gui(self._draw_imgui) From 3583140890f6921458c0bc99794e4be08cabd6e2 Mon Sep 17 00:00:00 2001 From: mokurin000 Date: Wed, 14 Jan 2026 15:43:13 +0800 Subject: [PATCH 2/4] docs: comment on custom_fonts usage --- fastplotlib/layouts/_figure.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index 8fd5dc666..79051eada 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -53,6 +53,7 @@ def __init__( size: tuple[int, int] = (500, 300), names: list | np.ndarray = None, show_tooltips: bool = False, + custom_fonts: list[tuple[str, float]] = None, ): """ Create a Figure containing Subplots. @@ -127,6 +128,8 @@ def __init__( show_tooltips: bool, default False show tooltips on graphics + custom_fonts: list[tuple[str, float]], optional + Custom font file path and pixel sizes, TrueType/OpenType are supported. """ if rects is not None: From 62fce4a0d7d6dcd30e26ab908c5a0c6e630f1895 Mon Sep 17 00:00:00 2001 From: mokurin000 Date: Wed, 14 Jan 2026 16:07:32 +0800 Subject: [PATCH 3/4] feat: allow to override default fonts --- fastplotlib/layouts/_figure.py | 4 ++++ fastplotlib/layouts/_imgui_figure.py | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index 79051eada..67c806075 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -54,6 +54,7 @@ def __init__( names: list | np.ndarray = None, show_tooltips: bool = False, custom_fonts: list[tuple[str, float]] = None, + override_default_font: bool = False, ): """ Create a Figure containing Subplots. @@ -130,6 +131,9 @@ def __init__( custom_fonts: list[tuple[str, float]], optional Custom font file path and pixel sizes, TrueType/OpenType are supported. + + override_default_font: bool, default False + Load custom fonts before default fonts """ if rects is not None: diff --git a/fastplotlib/layouts/_imgui_figure.py b/fastplotlib/layouts/_imgui_figure.py index 4cdcc02b6..dd2090f77 100644 --- a/fastplotlib/layouts/_imgui_figure.py +++ b/fastplotlib/layouts/_imgui_figure.py @@ -46,6 +46,7 @@ def __init__( names: list | np.ndarray = None, show_tooltips: bool = False, custom_fonts: list[tuple[str, float]] = None, + override_default_font: bool = False, ): self._guis: dict[str, EdgeWindow] = {k: None for k in GUI_EDGES} @@ -63,6 +64,8 @@ def __init__( size=size, names=names, show_tooltips=show_tooltips, + custom_fonts=custom_fonts, + override_default_font=override_default_font, ) self._imgui_renderer = ImguiRenderer(self.renderer.device, self.canvas) @@ -83,20 +86,21 @@ def __init__( io = imgui.get_io() - self._default_imgui_font = io.fonts.add_font_from_file_ttf( - sans_serif_font, 14, imgui.ImFontConfig() - ) + default_fonts = [(sans_serif_font, 14), (fa_6_fonts_path, 14.0)] + custom_fonts = custom_fonts if custom_fonts is not None else [] - font_config = imgui.ImFontConfig() - font_config.merge_mode = True + if override_default_font: + font_list = custom_fonts + default_fonts + else: + font_list = default_fonts + custom_fonts - self._default_imgui_font = io.fonts.add_font_from_file_ttf( - fa_6_fonts_path, - 14, - font_config, - ) + first_font = True + for font_path, font_size in font_list: + font_config = imgui.ImFontConfig() + if first_font: + font_config.merge_mode = True + first_font = False - for font_path, font_size in custom_fonts or []: self._default_imgui_font = io.fonts.add_font_from_file_ttf( font_path, font_size, From 087f1a4f5c1f5671446376042cef6f00e0c829f4 Mon Sep 17 00:00:00 2001 From: mokurin000 Date: Wed, 14 Jan 2026 16:09:56 +0800 Subject: [PATCH 4/4] fix: set font merge mode --- fastplotlib/layouts/_imgui_figure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastplotlib/layouts/_imgui_figure.py b/fastplotlib/layouts/_imgui_figure.py index dd2090f77..523c25cae 100644 --- a/fastplotlib/layouts/_imgui_figure.py +++ b/fastplotlib/layouts/_imgui_figure.py @@ -97,8 +97,8 @@ def __init__( first_font = True for font_path, font_size in font_list: font_config = imgui.ImFontConfig() + font_config.merge_mode = not first_font if first_font: - font_config.merge_mode = True first_font = False self._default_imgui_font = io.fonts.add_font_from_file_ttf(