user12211554
user12211554

Reputation:

In GTK, how can I space widgets and size text according to window size, rather than pixels?

In GTK, for example, in a VBox, or a GtkGrid, the overall size of widgets is according the the size of the screen. If there are two buttons in a homogenous VBox, they will be half the height of the window.

My question is, for text size or spacing between widgets or padding, how can I make it proportional to the window size so if the window is resized, the spacing and text size will change to reflect this?

In a drawing area, I can use gtk_widget_get_allocated_height() or gtk_widget_get_allocated_width(), but what's the equivalent outside a drawing area?

Upvotes: 0

Views: 746

Answers (1)

Paul Childs
Paul Childs

Reputation: 231

It's not just a matter of screens. In Gtk the user should often be able to resize a window and widgets change according to the display manager. For Gtk2 you can get the number of pixels in your drawing area with widget->allocation.width and widget->allocation.height. Gtk3 is a bit different. Then multiply by the fraction as Gehardh mentioned.

Upvotes: 2

Related Questions