Skip to content

Conversation

aforren1
Copy link
Contributor

This allows getting and setting colors for GuiStyle. Currently, I think GuiStyle only allows for retrieving values (not setting them). It changes the API a bit:

# getters
# master
val = style.color(imgui.COLOR_BUTTON)
# branch
val = stye.color[imgui.COLOR_BUTTON]

# setter (branch only)
style.color[imgui.COLOR_BUTTON] = (0.1, 0.6, 0.1, 1)

This is my first foray into cython, so the implementation might not be quite right...

For example, here's the pyglet example + style tweaks:

import pyglet
from pyglet import gl

import imgui
from imgui.integrations.pyglet import PygletRenderer

def main():
    window = pyglet.window.Window(width=1280, height=720, resizable=True)
    gl.glClearColor(1, 1, 1, 1)
    imgui.create_context()
    impl = PygletRenderer(window)
    # modify the current style
    style = imgui.get_style()
    print(style.color[imgui.COLOR_BORDER])
    style.color[imgui.COLOR_TITLE_BACKGROUND] = (0.9, 0.2, 0.2, 0.9)
    style.color[imgui.COLOR_WINDOW_BACKGROUND] = [0.5]*4
    style.frame_rounding = 14

    def update(dt):
        imgui.new_frame()
        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("File", True):
                clicked_quit, selected_quit = imgui.menu_item(
                    "Quit", 'Cmd+Q', False, True
                )
                if clicked_quit:
                    exit(1)

                imgui.end_menu()
            imgui.end_main_menu_bar()

        imgui.show_test_window()

        imgui.begin("Custom window", True)
        imgui.text("Bar")
        imgui.text_colored("Eggs", 0.2, 1., 0.)
        imgui.end()

    @window.event
    def on_draw():
        update(1/60.0)
        window.clear()
        imgui.render()
        impl.render(imgui.get_draw_data())

    pyglet.app.run()
    impl.shutdown()

if __name__ == "__main__":
    main()

@swistakm
Copy link
Member

Great! At first look I looks OK but I will review it in details soon.

We had failing builds in the master branch due to some unfortunate docs update (some test are based on documentation) and I missed that. Now I believe that it is fixed. Could you rebase your branch so we could rerun the tests?

If 'colors' exists, then this can co-exist and not break any
existing code (though maybe needs to be deprecated?)
Though now it fails another test, as I haven't made 'colors' directly
settable yet.
@aforren1
Copy link
Contributor Author

Now it only fails on my changes (I don't currently have a direct setter for colors).

In the meantime, I renamed color to colors, which means that

  • The pre-existing color method can continue to exist and not break existing code (though should maybe be deprecated?)
  • The API matches the C++ API a little closer

Copy link
Member

@swistakm swistakm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did detailed review. There are only two minor things that I would add/change.

Regarding the failing tests. I've checked out locally your branch and run tests. It seems that inspect module isn't able to properly distinguish data descriptors from non-data data descriptors. I thing you can simply skip that using following patch:

diff --git a/tests/test_gui_style_initialization.py b/tests/test_gui_style_initialization.py
index ed41268..054f287 100644
--- a/tests/test_gui_style_initialization.py
+++ b/tests/test_gui_style_initialization.py
@@ -18,6 +18,8 @@ def context():
 
 @pytest.fixture(params=IMGUI_DATA_DESCRIPTORS)
 def data_descriptor(request):
+    if request.param == "colors":
+        pytest.skip("'{}' isn't writable property".format(request.param))
     return request.param
 
 
-- 
2.21.0

@swistakm
Copy link
Member

I renamed color to colors

That's a good change. Definitely don't want to break backwards compatibility now.

 - Indicate that 'Colors' class is for internal use via leading underscore
 - Added suggested docstring for the 'colors' property
@aforren1
Copy link
Contributor Author

Thanks for reviewing! I've incorporated your changes.

@swistakm swistakm merged commit 1359ac9 into pyimgui:master Sep 14, 2019
@swistakm swistakm added the release pending Merged but still needs official release label Sep 14, 2019
@swistakm
Copy link
Member

This has been released in 1.1.0 and is available for download from PyPI.

@swistakm swistakm removed the release pending Merged but still needs official release label Nov 22, 2019
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

Successfully merging this pull request may close these issues.

2 participants