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

position a gui element in corner of windows - track resizes? #243

Open
pootle opened this issue Dec 18, 2019 · 2 comments
Open

position a gui element in corner of windows - track resizes? #243

pootle opened this issue Dec 18, 2019 · 2 comments

Comments

@pootle
Copy link

pootle commented Dec 18, 2019

I want to position a couple of buttons in the window corners, and reposition them if the user resizes the window, but I can't see how to find the window's size, or detect when it is resized.

@paddywwoof
Copy link
Collaborator

paddywwoof commented Dec 18, 2019

Good point. I see there's a TODO in DisplayOpenGL on that subject. It's probably rather difficult to do in your code as it needs an additional event mask setting up in DisplayOpenGL and the event checking in Display needs to catch resizes. i.e. DisplayOpenGL

      xlib.XSelectInput(self.d, self.window, KeyPressMask | KeyReleaseMask | ResizeRedirectMask)

and Display

      n = xlib.XEventsQueued(self.opengl.d, xlib.QueuedAfterFlush)
      for _ in range(n):
          xlib.XNextEvent(self.opengl.d, self.ev)
          if self.ev.type == KeyPress or self.ev.type == KeyRelease:
              self.event_list.append(self.ev)
          elif self.ev.type == ClientMessage:
            if (self.ev.xclient.data.l[0] == self.opengl.WM_DELETE_WINDOW.value):
              self.destroy()
          elif self.ev.type == ResizeRequest:
            (self.width, self.height) = (self.ev.xresizerequest.width,
                                         self.ev.xresizerequest.height)
            opengles.glViewport(0, 0, self.width, self.height)
            self.was_resized = True

then in programs

    if DISPLAY.was_resized:
        # move shapes and fix camera

However the the normal Camera.reset() with different lens settings doesn't work properly and creating new Cameras and setting Shape._camera = new_cam also has issues. I will let you know when I've figured out what to do, and will post the revisions to pi3d develop branch. Hopefully something quick to do.

Paddy

PS to answer the first part of your question. You can get the Display size using its width and height properties. So if your button is bwxbh it will be in the bottom right corner:

...
button.positionX((display.width - bw) * 0.5)
button.positionY((diplay.height - bh) * 0.5)

@pootle
Copy link
Author

pootle commented Dec 18, 2019

Many thanks, that'll keep me going

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

2 participants