3

Let's say the widget in question is a VBox containing a Label and two Buttons.

Furthermore, let's say the degree of rotation desired is 90°.

How does one go about rotating it? I do not think this is possible by default but I do think it is possible.

However, I have no idea how to get started. Do I write a custom widget? What do I subclass?

Fake Code Monkey Rashid
  • 13,731
  • 6
  • 37
  • 41

3 Answers3

8

You can fake it like this:

label.set_angle(90)
button1.get_child().set_angle(90) # assuming it's not a stock button
button2.get_child().set_angle(90)
vbox.set_orientation(gtk.ORIENTATION_HORIZONTAL)
ptomato
  • 56,175
  • 13
  • 112
  • 165
  • Hmm... This is pretty interesting. :) I'll try it and see if it works for my purposes. Thanks! – Fake Code Monkey Rashid Mar 02 '10 at 03:56
  • Okay, this solution is really interesting and for the example I gave, it certainly (more or less) works. I'd still like to know if true (ie: via a custom widget) rotation is possible (and if so, how to start on that venue), failing that, I'll mark this as the accepted answer (since it does answer the question I posed). Edit: Actually, can you fake the rotation of a Fixed container too? – Fake Code Monkey Rashid Mar 03 '10 at 01:59
  • 2
    You can fake the rotation of a Fixed container by resizing it, interchanging the x and y coordinates of all the child widgets, and rotating all the child widgets separately -- if they can be rotated. Widgets that can be rotated are pretty much limited to Labels and Images. – ptomato Mar 03 '10 at 10:58
  • As to the real question, try reading up on the documentation of Gdk.Drawable and Gdk.Window; maybe there's some trick with client-side windows and redirection that you can do. You might also check out Clutter (http://library.gnome.org/devel/clutter/stable/) but I know nothing about it. – ptomato Mar 03 '10 at 11:02
0

Firstly, if your widget does not have its own X window (VBox doesn't), put it inside EventBox.

Secondly, assuming that you've got X composite extension enabled in your X server, you will be able to do that by manually tweaking your widget's X window using Xlib or an equivalent one. Warning, this is a hacky solution and will not work if your user does not have compositing extensions enabled.

I don't see any way to do this without compositing extensions... well, other than drawing everything by hand. GTK uses Cairo graphics library to draw widgets, and theoretically it would be enough to set transformation matrix inside Cairo... but I see no practical possibility of doing that.

liori
  • 40,917
  • 13
  • 78
  • 105
0

I know it's been a while since this question was answered, but if you want to get started with subclassing, here's the C code to do it. This is taken from the GTK-Demo suite.

https://github.com/GNOME/gtk/blob/gtk-3-22/demos/gtk-demo/offscreen_window.c

Xliff
  • 194
  • 5