### Tutorial
« Frames | Paned Window Widgets »

## Aspect Frames

The aspect frame widget is like a frame widget, except that it also enforces the aspect ratio (that is, the ratio of the width to the height) of the child widget to have a certain value, adding extra space if necessary. This is useful, for instance, if you want to preview a larger image. The size of the preview should vary when the user resizes the window, but the aspect ratio needs to always match the original image.
To create a new aspect frame use one of the following constructors:

`AspectFrame(); AspectFrame(float xalign, float yalign, float ratio = 1.0, bool obey_child = false); AspectFrame(const String& label, float xalign, float yalign,float ratio = 1.0, bool obey_child = false);`

The xalign and yalign arguments specify the alignment as with Alignment widgets. If obey_child is true, the aspect ratio of a child widget will match the aspect ratio of the ideal size it requests. Otherwise, it is given by ratio.
The first constructor creates an AspectFrame with the default value of 0.5 for xalign and yalign, 1.0 for the ratio and true for obey_child. The second constructor creates an AspectFrame with the specified values. The last constructor lets you additionally specify a label for the aspect frame.
To change the options of an existing aspect frame, you can use:
`
`

`void set(float xalign, float yalign, float ratio, bool obey_child);`

As an example, the following program uses an AspectFrame to present a drawing area whose aspect ratio will always be 2:1, no matter how the user resizes the top-level window.
The header file for Aspect Frame is aspectframe.h:

`#include<inti/main.h> #include <inti/gtk/window.h> using namespace Inti; class AspectFrameWindow : public Gtk::Window { public: AspectFrameWindow(); virtual ~AspectFrameWindow(); };`

and the source file is aspectframe.cc:

`#include"aspectframe.h" #include <inti/gtk/aspectframe.h> #include <inti/gtk/drawingarea.h> AspectFrameWindow::AspectFrameWindow() { set_title("Aspect Frame"); set_border_width(10); // Create an aspect_frame and add it to our toplevel window Gtk::AspectFrame *aspect_frame = new Gtk::AspectFrame("2x1", 0.5, 0.5, 2); add(*aspect_frame); aspect_frame->show(); // Now add a child widget to the aspect frame Gtk::DrawingArea *drawing_area = new Gtk::DrawingArea; // We ask for a 200x200 window but get a 200x100 window since we are forcing a 2x1 aspect ratio. drawing_area->set_size_request(200, 200); aspect_frame->add(*drawing_area); drawing_area->show(); } AspectFrameWindow::~AspectFrameWindow() { } int main (int argc, char *argv[]) { using namespace Main; init(&argc, &argv); AspectFrameWindow window; window.sig_destroy().connect(slot(&Inti::Main::quit)); window.show(); run(); return 0; }`

« Frames | Index Container Widgets Top | Paned Window Widgets »