egui_alignments
Simple alignment tools for egui
Example Usage
Align a single widget
use ;
use Alignable;
new
.top;
if new
.center
.clicked
new
.bottom;
Align multiple widgets
The following buttons will be shown at the center of the screen horizontally with the tip text above and click results below.
use ;
use center_horizontal;
let mut clicked_button = None;
center_vertical
Use containers
Sometimes nested calls to alignment functions like center_horizontal, top_vertical, ...
may cause layout confusion due to interaction between inner and outer layouts.
To prevent inner layouts from disrupting the outer ones, you may use containers for inner layouts.
Containers only cares about its inner alignments and act like a simple widget in the outer layout.
The following is an example usage of containers.
use Align;
use ;
center_horizontal;
This will show an image on the left, and a column of text on the right which contains a row of three labels in the middle.
Use stretches in containers
Sometimes you may not want the elements in a container to be closely aligned.
You may use stretch to make the elements in a container stretch to fill the available space.
use Align;
use ;
center_horizontal;
This will make the text elements right to the image aligned as far as possible.
If you want the stretches in a container to have different weights, you may use stretch_with_weight instead.
use Align;
use ;
center_horizontal;
This will make the space left to the image and right to all the text elements to be twice as large as the gap between the image and the text.