Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fastplotlib/layouts/_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(
size: tuple[int, int] = (500, 300),
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.
Expand Down Expand Up @@ -127,6 +129,11 @@ 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.

override_default_font: bool, default False
Load custom fonts before default fonts
"""

if rects is not None:
Expand Down
34 changes: 23 additions & 11 deletions fastplotlib/layouts/_imgui_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(
size: tuple[int, int] = (500, 300),
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}

Expand All @@ -62,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)
Expand All @@ -82,18 +86,26 @@ def __init__(

io = imgui.get_io()

self._default_imgui_font = io.fonts.add_font_from_file_ttf(
sans_serif_font, 14, imgui.ImFontConfig()
)

font_config = imgui.ImFontConfig()
font_config.merge_mode = True
default_fonts = [(sans_serif_font, 14), (fa_6_fonts_path, 14.0)]
custom_fonts = custom_fonts if custom_fonts is not None else []

self._default_imgui_font = io.fonts.add_font_from_file_ttf(
fa_6_fonts_path,
14,
font_config,
)
if override_default_font:
font_list = custom_fonts + default_fonts
else:
font_list = default_fonts + custom_fonts

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:
first_font = False

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)

Expand Down