GTK gossip: gtkframe and gtkaspectframe

Source: Internet
Author: User
Tags gtk

Gtkframe is a sub-class of gtkcontainer. It can contain sub-components and contain an external frame and text:

Gtkcontainer


+ ---- Gtkbin


+ ---- Gtkframe


You can use gtk_frame_new () to create a gtkframe and specify the cursor text when creating it, or use gtk_frame_set_label later.
() Set the text. Set the text position to the upper left corner of the text. You can use gtk_frame_set_label_align () to set the text position of the text:

Gtkwidget * gtk_frame_new (const gchar * label );



Void gtk_frame_set_label (gtkframe * frame,



Const gchar * label );



Void gtk_frame_set_label_align (gtkframe * frame,



Gfloat xalign,


Gfloat
Yalign );




Gtk_frame_set_label_align () can be used to set xalign and yalign. The value ranges from 0.0 to 1.0. xalign can set horizontal comparison and yalign to set vertical comparison of text. You can also use gtk_frame_set_shadow_type () to set the external frame format:

Void gtk_frame_set_shadow_type (gtkframe * frame,


Gtkshadowtype
Type );

The following program is a simple configuration example:

  • Gtk_frame_demo.c
#include <gtk/gtk.h>

int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *frame;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkFrame");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 150);

frame = gtk_frame_new("caterpillar");
gtk_frame_set_label_align(GTK_FRAME(frame), 0.5, 0.5);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);

gtk_container_add(GTK_CONTAINER(window), frame);

g_signal_connect(GTK_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);

gtk_main();

return 0;
}

The following figure shows the result of a line:

Gtkaspectframe is a sub-class of gtkframe. It is similar to gtkframe, but it is determined by the xsize/ysize ratio. It can be used to limit the length ratio of sub-components:

Gtkwidget * gtk_aspect_frame_new (const gchar * label,



Gfloat xalign,




Gfloat yalign,




Gfloat ratio,




Gboolean obey_child );


The role of xalign and yalign is the same as that of gtkframe. ratio is the ratio setting. When obey_child is set to true, it indicates that it is indicated by the length ratio of the Child component. If it is set to false, according to the ratio of ratio.

The following example shows a simple example. The ratio of the gtkaspectframe is set to 2 (xsize/ysize). Therefore, the ratio of the parameter component is as follows:

  • Gtk_aspect_frame_demo.c
#include <gtk/gtk.h>

int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *frame;
GtkWidget *button;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "GtkAspectFrame");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);

frame = gtk_aspect_frame_new("caterpillar", 0.5, 0.5, 2, FALSE);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);

button = gtk_button_new_with_label("Press");
gtk_container_add(GTK_CONTAINER(frame), button);
gtk_container_add(GTK_CONTAINER(window), frame);

g_signal_connect(GTK_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);

gtk_widget_show_all(window);

gtk_main();

return 0;
}

The results of a line are as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.