hoffstadt / DearPyGui

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

A table without columns breaks font/theme stack #2075

Open v-ein opened 1 year ago

v-ein commented 1 year ago

Version of Dear PyGui

Version: 1.9.0 Operating System: Windows 10

My Issue/Question

A table with no columns and a theme or font (however weird that sounds) puts the theme/font onto the stack but does not remove it, thus breaking styles everywhere else.

To Reproduce

Steps to reproduce the behavior:

  1. Run the example code
  2. Check "with columns" and show the table just to make sure everything is alright. Text in the table should be green, the word "Lorem" red, everything else white (the default color).
  3. Uncheck "With columns" and see how colors change. Now, no matter how you show or hide the table, the default white color never comes back because the stack always contains the table theme at its head.

Expected behavior

The table must not affect styling on widgets outside of it.

Screenshots/Video

image

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport(title="Test", width=500, height=400)

dpg.setup_dearpygui()
with dpg.window(pos=(100, 100), width=350, height=200, no_title_bar=False):
    # This theme makes text green
    with dpg.theme() as table_theme:
        with dpg.theme_component(dpg.mvAll):
            dpg.add_theme_color(dpg.mvThemeCol_Text, (0, 255, 0), category=dpg.mvThemeCat_Core)
    # This theme makes text red
    with dpg.theme() as another_theme:
        with dpg.theme_component(dpg.mvAll):
            dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0), category=dpg.mvThemeCat_Core)

    def manage_columns(_, checked):
        if checked:
            dpg.add_table_column(parent="test-table")
        else:
            dpg.delete_item("test-table", children_only=True, slot=0)

    dpg.add_checkbox(label="With columns", default_value=False, callback=manage_columns)
    dpg.add_checkbox(label="Show table", default_value=False, callback=lambda _, checked: dpg.configure_item("test-table", show=checked))

    with dpg.table(tag="test-table", show=False):
        dpg.bind_item_theme(dpg.last_item(), table_theme)
        with dpg.table_row():
            dpg.add_text("Cell")

    dpg.add_text("Lorem")
    dpg.bind_item_theme(dpg.last_item(), another_theme)
    dpg.add_text("ipsum")

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
v-ein commented 1 year ago

This is just to document the fix I have (which I'm going to push in future).

hoffstadt commented 1 year ago

I'll hold off on a fix then if you have it!

v-ein commented 10 months ago

A note to myself: this one is waiting for PR #2113 to be merged (to avoid conflicts).