hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.66k stars 669 forks source link

Binding icon font to tab button crashes application #2084

Open Evolution0 opened 1 year ago

Evolution0 commented 1 year ago

Version of Dear PyGui

Version: 1.9.0 Operating System: Windows 10 Pro 22H2

My Issue/Question

Attempting to bind an icon font to a tab button causes the application to crash.

It is possibly to correctly display this font other ways just fine, for example as a basic line of text. (see L29, run with L32 commented)

To Reproduce

Minimal example that reproduces the issue:

import dearpygui.dearpygui as dpg

dpg.create_context()

def add_font(file, size: int | float, parent=0, **kwargs) -> int:
    if not isinstance(size, (int, float)):
        raise ValueError(f'font size must be an integer or float. Not {type(size)}')

    chars = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
    for i, char in enumerate(chars):
        chars[i] = ord(char)

    with dpg.font(file, size, parent=parent, **kwargs) as font:
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Default, parent=font)
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Cyrillic, parent=font)
        dpg.add_font_chars(chars, parent=font)
    return font

with dpg.font_registry():
    box_icons = add_font("boxicons.ttf", 30, tag="_box_icons")

dpg.create_viewport(title='Private Use Area Unicode Block Test', width=720, height=520, resizable=False)

with dpg.window(label="Font Test", tag="_font_test"):
    with dpg.tab_bar(tag="_font_test_bar") as tb:
        with dpg.tab(label="Compression", tag="_font_test_tab"):
            icons = dpg.add_text("              ")
            dpg.bind_item_font(icons, box_icons)
        dpg.add_tab_button(label="", leading=True, tag="_toggle")
        dpg.bind_item_font("_toggle", box_icons)

dpg.setup_dearpygui()
dpg.set_primary_window("_font_test", True)
dpg.show_viewport()

while dpg.is_dearpygui_running():
    dpg.render_dearpygui_frame()
dpg.destroy_context()

Expected behavior

The label of the tab_button should show the icon font. As a side note this works perfectly fine on tabs themselves, just not tab_buttons. boxicons.zip

Evolution0 commented 1 year ago

After some experimentation I'm guessing that not only did I misunderstand how binding fonts to a specific widget worked but it might not be possible to do what I want to do. Binding a font to a tab itself means everything in that tab gets the same font, problem is many icon fonts are made with the rest of the blocks entirely empty and just icons in the Private Use Area, this means any regular text inside the tab will be blank.

I've attempted to set a base font with a font registry and parent to it when loading the icon font but that does not seem to help.

I could be and am probably missing something, I'm pretty new to using imgui in general, everything has been smooth sailing and easy to understand so far other than this.