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

Change background color of child window #240

Closed
luisarandas opened this issue Aug 23, 2021 · 5 comments
Closed

Change background color of child window #240

luisarandas opened this issue Aug 23, 2021 · 5 comments

Comments

@luisarandas
Copy link

luisarandas commented Aug 23, 2021

Hello all.

I would like to know how can I approach this problem using Python. This question - how to change the background color of a newly created window - has been commented in cpp ocornut/imgui#2700 ; ocornut/imgui#1289. Example:

imgui.set_next_window_bg_alpha(1.0)
imgui.core.set_next_window_position(x,y) # hardcoded
imgui.core.set_next_window_size((loop_window_width/2)-149,315)
imgui.begin("side2", True, flags=imgui.WINDOW_NO_SCROLLBAR|imgui.WINDOW_NO_RESIZE|imgui.WINDOW_NO_TITLE_BAR)
[maybe here?]
imgui.end()

Since this is a port I think it should be able to do. Although I cannot find anything related to this in the readthedocs.

Best

@learn-more
Copy link
Collaborator

have you tried push_style_color?

@luisarandas
Copy link
Author

imgui.core.push_style_color(ImGuiCol variable, float r, float g, float b, float a=1.)

What would be the variable?

@KinoxKlark
Copy link
Member

KinoxKlark commented Aug 25, 2021

Hello,

Here, variable would be a flag of type cimgui.ImGuiCol, i.e. one of COLOR_*:

COLOR_TEXT 
COLOR_TEXT_DISABLED 
COLOR_WINDOW_BACKGROUND 
COLOR_CHILD_BACKGROUND 
COLOR_POPUP_BACKGROUND 
COLOR_BORDER 
COLOR_BORDER_SHADOW 
COLOR_FRAME_BACKGROUND 
COLOR_FRAME_BACKGROUND_HOVERED 
COLOR_FRAME_BACKGROUND_ACTIVE 
COLOR_TITLE_BACKGROUND 
COLOR_TITLE_BACKGROUND_ACTIVE 
COLOR_TITLE_BACKGROUND_COLLAPSED 
COLOR_MENUBAR_BACKGROUND 
COLOR_SCROLLBAR_BACKGROUND 
COLOR_SCROLLBAR_GRAB 
COLOR_SCROLLBAR_GRAB_HOVERED 
COLOR_SCROLLBAR_GRAB_ACTIVE 
COLOR_CHECK_MARK 
COLOR_SLIDER_GRAB 
COLOR_SLIDER_GRAB_ACTIVE 
COLOR_BUTTON 
COLOR_BUTTON_HOVERED 
COLOR_BUTTON_ACTIVE 
COLOR_HEADER 
COLOR_HEADER_HOVERED 
COLOR_HEADER_ACTIVE 
COLOR_SEPARATOR 
COLOR_SEPARATOR_HOVERED 
COLOR_SEPARATOR_ACTIVE 
COLOR_RESIZE_GRIP 
COLOR_RESIZE_GRIP_HOVERED 
COLOR_RESIZE_GRIP_ACTIVE 
COLOR_PLOT_LINES 
COLOR_PLOT_LINES_HOVERED 
COLOR_PLOT_HISTOGRAM 
COLOR_PLOT_HISTOGRAM_HOVERED 
COLOR_TEXT_SELECTED_BACKGROUND 
COLOR_DRAG_DROP_TARGET 
COLOR_NAV_HIGHLIGHT 
COLOR_NAV_WINDOWING_HIGHLIGHT 
COLOR_NAV_WINDOWING_DIM_BACKGROUND
COLOR_MODAL_WINDOW_DIM_BACKGROUND

Changing bg color would be COLOR_WINDOW_BACKGROUND:

imgui.set_next_window_bg_alpha(1.0)
imgui.core.set_next_window_position(200,200) # hardcoded
imgui.core.set_next_window_size((loop_window_width/2)-149,315)
imgui.push_style_color(imgui.COLOR_WINDOW_BACKGROUND, 200, 0, 0)
imgui.begin("side2", True, flags=imgui.WINDOW_NO_SCROLLBAR|imgui.WINDOW_NO_RESIZE|imgui.WINDOW_NO_TITLE_BAR)
imgui.end()
imgui.pop_style_color()

Note that the current release of pyimgui is based on an old version of dear imgui and that recent functionalities may not be present or work as expected. We are working on an upgrade to catch up with dear imgui.

EDIT: I said "one of", but it could be a combination of multiple flags using the pipe operator.

@luisarandas
Copy link
Author

Dear @KinoxKlark, thank you for the clarification. It works perfectly.

@learn-more
Copy link
Collaborator

This question should be fully answered.
If you feel this is not the case, feel free to re-open it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants