Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to bind theme to modal windows #2463

Open
grybouilli opened this issue Jan 21, 2025 · 1 comment
Open

Unable to bind theme to modal windows #2463

grybouilli opened this issue Jan 21, 2025 · 1 comment
Labels
state: pending not addressed yet type: bug bug

Comments

@grybouilli
Copy link

Version of Dear PyGui

Version: 2.0.0
Operating System: Windows 10

My Issue/Question

Binding theme to modal window doesn't seem to work.

To Reproduce

This minimal code :

import dearpygui.dearpygui as dpg
from time import sleep
from random import randint

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
global_theme = None
with dpg.theme() as g_theme:
    global_theme = g_theme
    with dpg.theme_component(dpg.mvAll, enabled_state=True):
        dpg.add_theme_color(dpg.mvThemeCol_TitleBgActive, (200,200,200), category=dpg.mvThemeCat_Core)
        dpg.add_theme_color(dpg.mvThemeCol_WindowBg, (225,225,225), category=dpg.mvThemeCat_Core)
        dpg.add_theme_color(dpg.mvThemeCol_Text, (100, 100, 100), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 6, category=dpg.mvThemeCat_Core)
        dpg.add_theme_color(dpg.mvThemeCol_Button, (200,200,200), category=dpg.mvThemeCat_Core)
        dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, (200, 200, 200), category=dpg.mvThemeCat_Core)
        dpg.add_theme_color(dpg.mvThemeCol_ButtonActive, (200, 200, 200), category=dpg.mvThemeCat_Core)

def rand_me():
    dpg.set_value("number_text", str(randint(0,100)))
    
def button_callback():
    dpg.show_item("windowblocker")
    sleep(2)
    dpg.hide_item("windowblocker")

dpg.bind_theme(global_theme)
with dpg.window(label="Example Window", tag="mainwindow"):
    dpg.add_button(label="Open modal", callback=button_callback)
    dpg.add_button(label="Gen nb", callback=rand_me)
    with dpg.group(horizontal=True):
        dpg.add_text("Number : ")
        dpg.add_text(label="", tag="number_text")

with dpg.window(modal=True, no_close=True, no_title_bar=True, show=False, tag="windowblocker"): # One can try removing modal=True and see the theme binding will work
    dpg.add_text("The theme isn't bound here !!")
dpg.bind_item_theme("windowblocker", global_theme) # <---- BINDING HERE !!!

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

Expected behavior

The modal window theme should be the one used with dpg.bind_item_theme.

Screenshots/Video

Expected theme (regular window)

Image

Theme in modal window

Image

@grybouilli grybouilli added state: pending not addressed yet type: bug bug labels Jan 21, 2025
@SamuMazzi
Copy link
Contributor

Hi, this is not a bug, indeed you need to set mvThemeCol_PopupBg instead of mvThemeCol_WindowBg, because (if I got it right) modals in ImGui are treated as a "subtype" of popups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: pending not addressed yet type: bug bug
Projects
None yet
Development

No branches or pull requests

2 participants