GtkAspectFrame: GTK+ 4 Reference Manual

## GtkAspectFrame GtkAspectFrame — A frame that constrains its child to a particular aspect ratio |

## Functions

GtkWidget * | gtk_aspect_frame_new ()
void | gtk_aspect_frame_set ()

## Types and Values

struct | GtkAspectFrame
struct | GtkAspectFrameClass

## Includes

    #include <gtk/gtk.h>

## Description

The GtkAspectFrame is useful when you want pack a widget so that it can resize but always retains the same aspect ratio. For instance, one might be drawing a small preview of a larger image. GtkAspectFrame derives from GtkFrame, so it can draw a label and a frame around the child. The frame will be “shrink-wrapped” to the size of the child.

### CSS nodes

GtkAspectFrame uses a CSS node with name frame.

## Functions

### gtk_aspect_frame_new ()

    GtkWidget *
    gtk_aspect_frame_new (const gchar *label,
                          gfloat xalign,
                          gfloat yalign,
                          gfloat ratio,
                          gboolean obey_child);

Create a new GtkAspectFrame.

#### Parameters

label | Label text. | [allow-none]
xalign | Horizontal alignment of the child within the allocation of the GtkAspectFrame. This ranges from 0.0 (left aligned) to 1.0 (right aligned) |
yalign | Vertical alignment of the child within the allocation of the GtkAspectFrame. This ranges from 0.0 (top aligned) to 1.0 (bottom aligned) |
ratio | The desired aspect ratio. |
obey_child | If `TRUE`, `ratio` is ignored, and the aspect ratio is taken from the requistion of the child. |

#### Returns

the new GtkAspectFrame.

### gtk_aspect_frame_set ()

    void
    gtk_aspect_frame_set (GtkAspectFrame *aspect_frame,
                          gfloat xalign,
                          gfloat yalign,
                          gfloat ratio,
                          gboolean obey_child);

Set parameters for an existing GtkAspectFrame.

#### Parameters

aspect_frame | a GtkAspectFrame |
xalign | Horizontal alignment of the child within the allocation of the GtkAspectFrame. This ranges from 0.0 (left aligned) to 1.0 (right aligned) |
yalign | Vertical alignment of the child within the allocation of the GtkAspectFrame. This ranges from 0.0 (top aligned) to 1.0 (bottom aligned) |
ratio | The desired aspect ratio. |
obey_child | If `TRUE`, `ratio` is ignored, and the aspect ratio is taken from the requistion of the child. |

## Types and Values

### struct GtkAspectFrame

    struct GtkAspectFrame {
      GtkFrame frame;
    };

### struct GtkAspectFrameClass

    struct GtkAspectFrameClass {
      GtkFrameClass parent_class;
    };

#### Members