The horizontal, vertical, and table layout containers we learned earlier, the controls are automatically adapted to changes in the size of the container, while the controls in the fixed layout container do not change (or are fixed).
To create a fixed layout:
Gtkwidget *gtk_fixed_new (void);
Return value: Fixed layout container pointer
To add a control to a fixed layout container:
void Gtk_fixed_put (
Gtkfixed *fixed,
Gtkwidget *widget,
Gint x,
Gint y);
Fixed: container to hold controls
Widgets: Controls to add
X, Y: The starting coordinates of the position where the control is placed, such as:
Set the size (width and height) of the control:
void Gtk_widget_set_size_request (
Gtkwidget *widget,
Gint width,
Gint height);
Widgets: Controls that need to be set
Width: Wide
Height: High
To move a control's position in a fixed layout:
void Gtk_fixed_move (
Gtkfixed *fixed,
Gtkwidget *widget,
Gint x,
Gint y);
Fixed: Stationary layout container
Widgets: Controls that need to be moved
X, y: Moving position
The complete code is as follows:
#include <gtk/gtk.h> int main (int argc, char *argv[]) {gtk_init (&ARGC, &ARGV);//Initialize Gtkwidget *windo W = gtk_window_new (gtk_window_toplevel); Create window Gtkwidget *fixed = gtk_fixed_new (); Create a fixed container gtk_container_add (gtk_container (window), fixed); Fixed put into window gtkwidget *button1 = Gtk_button_new_with_label ("^_^"); Create button Gtk_fixed_put (gtk_fixed (fixed), button1, 0, 0); The button is added to the fixed layout gtkwidget *button2 = Gtk_button_new_with_label ("@[email protected]"); Create button Gtk_fixed_put (gtk_fixed (fixed), button2, 0, 0); The button is added to the fixed layout gtk_fixed_move (gtk_fixed (fixed), button2, 150, 150); The position of the mobile control gtk_widget_set_size_request (button2, 100, 50); Sets the size of the control gtk_widget_show_all (window); Show all Controls Gtk_main (); Enter event loop
The program runs as follows:
Source code download please click here.
Fixed layout of layout containers