-
Hello, using hello_imgui.ImGuiTweakedTheme() doesn't seem to change the app window background color: from imgui_bundle import imgui, immapp, hello_imgui, imgui_ctx
class Globals:
def __init__(self):
# ---
self.runner_params = hello_imgui.RunnerParams()
# ---
self.addons = immapp.AddOnsParams()
# ---
self.val_combo_layout = 0
def setup_runner_params(self):
self.runner_params = hello_imgui.RunnerParams()
self.runner_params.app_window_params.window_geometry.size = (1000, 600)
self.runner_params.callbacks.show_gui = create_gui
def on_change_layout(self):
# ---
tweaked_theme_dark = hello_imgui.ImGuiTweakedTheme()
tweaked_theme_dark.theme = hello_imgui.ImGuiTheme_.darcula
tweaked_theme_dark.tweaks.rounding = 8.0
# ---
tweaked_theme_light = hello_imgui.ImGuiTweakedTheme()
tweaked_theme_light.theme = hello_imgui.ImGuiTheme_.light_rounded
tweaked_theme_light.tweaks.rounding = 8.0
if self.val_combo_layout == 0:
hello_imgui.push_tweaked_theme(tweaked_theme_dark)
elif self.val_combo_layout == 1:
hello_imgui.push_tweaked_theme(tweaked_theme_light)
gb = Globals()
def create_gui():
table_main_flags = (
imgui.TableFlags_.resizable.value | imgui.TableFlags_.borders.value
)
# ---
gb.on_change_layout()
# ---
imgui.new_line()
with imgui_ctx.begin_table("main_frame", 1, table_main_flags) as main_frame:
if main_frame:
imgui.table_next_row()
imgui.table_next_column()
imgui.new_line()
# ---
with imgui_ctx.begin_tab_bar("tab_bar_main") as tab_bar_main:
if tab_bar_main:
with imgui_ctx.begin_tab_item("Tab") as tab_check:
if tab_check:
imgui.new_line()
imgui.new_line()
imgui.new_line()
# ---
imgui.text("Change Layout")
# ---
imgui.new_line()
# ---
items = [
"Dark",
"Light",
]
(
changed,
gb.val_combo_layout,
) = imgui.combo(
"##combo_layout",
gb.val_combo_layout,
items,
len(items),
)
# ---
hello_imgui.pop_tweaked_theme()
if __name__ == "__main__":
# ---
gb.setup_runner_params()
# ---
immapp.run(gb.runner_params, gb.addons) It is possible to change the app window background color at setup with e.g. self.runner_params.imgui_window_params.background_color = ImVec4( 0.5, 0.5, 0.5, 0.5) But how can I change the app window background color at runtime using tweaked themes? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Your current code changes the theme at each frame, even if the user did not select a change in the combo box. You can try: from imgui_bundle import imgui, immapp, hello_imgui, imgui_ctx
class Globals:
def __init__(self):
# ---
self.runner_params = hello_imgui.RunnerParams()
# ---
self.addons = immapp.AddOnsParams()
# ---
self.val_combo_layout = 0
def setup_runner_params(self):
self.runner_params = hello_imgui.RunnerParams()
self.runner_params.app_window_params.window_geometry.size = (1000, 600)
self.runner_params.callbacks.show_gui = create_gui
def on_change_layout(self):
# ---
tweaked_theme_dark = hello_imgui.ImGuiTweakedTheme()
tweaked_theme_dark.theme = hello_imgui.ImGuiTheme_.darcula
tweaked_theme_dark.tweaks.rounding = 8.0
# ---
tweaked_theme_light = hello_imgui.ImGuiTweakedTheme()
tweaked_theme_light.theme = hello_imgui.ImGuiTheme_.light_rounded
tweaked_theme_light.tweaks.rounding = 8.0
if self.val_combo_layout == 0:
hello_imgui.apply_tweaked_theme(tweaked_theme_dark) # You could call push_tweaked_theme() instead, but apply_tweaked_theme() is more convenient here
elif self.val_combo_layout == 1:
hello_imgui.apply_tweaked_theme(tweaked_theme_light)
gb = Globals()
def create_gui():
table_main_flags = (
imgui.TableFlags_.resizable.value | imgui.TableFlags_.borders.value
)
# ---
# gb.on_change_layout() # Do not call this at each frame! Only call it if the user selected a different theme
# ---
imgui.new_line()
with imgui_ctx.begin_table("main_frame", 1, table_main_flags) as main_frame:
if main_frame:
imgui.table_next_row()
imgui.table_next_column()
imgui.new_line()
# ---
with imgui_ctx.begin_tab_bar("tab_bar_main") as tab_bar_main:
if tab_bar_main:
with imgui_ctx.begin_tab_item("Tab") as tab_check:
if tab_check:
imgui.new_line()
imgui.new_line()
imgui.new_line()
# ---
imgui.text("Change Layout")
# ---
imgui.new_line()
# ---
items = [
"Dark",
"Light",
]
(
changed,
gb.val_combo_layout,
) = imgui.combo(
"##combo_layout",
gb.val_combo_layout,
items,
len(items),
)
# only call on_change_layout if the user selected a different theme
if changed:
gb.on_change_layout()
# ---
# hello_imgui.pop_tweaked_theme() # No need to call this here, as we are not calling push_tweaked_theme() at each frame anymore
if __name__ == "__main__":
# ---
gb.setup_runner_params()
# ---
immapp.run(gb.runner_params, gb.addons) |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the help. |
Beta Was this translation helpful? Give feedback.
Your current code changes the theme at each frame, even if the user did not select a change in the combo box.
I guess this is the origin of your issue.
You can try: