Crate egui[−][src]
egui core library
To quickly get started with egui, you can take a look at egui_template
which uses eframe
.
To create a GUI using egui you first need a CtxRef
(by convention referred to by ctx
).
Then you add a Window
or a SidePanel
to get a Ui
, which is what you'll be using to add all the buttons and labels that you need.
Integrating with egui
To write your own integration for egui you need to do this:
let mut ctx = egui::CtxRef::default(); // Game loop: loop { let raw_input: egui::RawInput = gather_input(); ctx.begin_frame(raw_input); egui::CentralPanel::default().show(&ctx, |ui| { ui.label("Hello world!"); if ui.button("Click me").clicked() { /* take some action here */ } }); let (output, shapes) = ctx.end_frame(); let clipped_meshes = ctx.tessellate(shapes); // create triangles to paint handle_output(output); paint(clipped_meshes); }
Using egui
To see what is possible to build we egui you can check out the online demo at https://emilk.github.io/egui/#demo.
Use one of SidePanel
, TopPanel
, CentralPanel
, Window
or Area
to
get access to an Ui
where you can put widgets. For example:
egui::CentralPanel::default().show(&ctx, |ui| { ui.add(egui::Label::new("Hello World!")); ui.label("A shorter and more convenient way to add a label."); if ui.button("Click me").clicked() { /* take some action here */ } });
Re-exports
pub use emath as math; |
pub use epaint as paint; |
pub use epaint::emath; |
pub use containers::*; |
pub use layers::LayerId; |
pub use layers::Order; |
pub use style::Style; |
pub use style::Visuals; |
pub use widgets::*; |
Modules
color | Color conversions and types. |
containers | Containers are pieces of the UI which wraps other pieces of UI. Examples: |
experimental | Experimental parts of egui, that may change suddenly or get removed. |
layers | Handles paint layers, i.e. how things are sometimes painted behind or in front of other things. |
menu | Menu bar functionality (very basic so far). |
mutex | Helper module that wraps some Mutex types with different implementations. |
style | egui theme (spacing, colors, etc). |
util | Miscellaneous tools used by the rest of egui. |
widgets | Widgets are pieces of GUI such as |
Macros
github_link_file | |
github_link_file_line | Create a |
Structs
Align2 | Two-dimension alignment, e.g. |
ClippedMesh | A |
Color32 | This format is used for space-efficient color representation (32 bits). |
Context | This is the first thing you need when working with egui. Create using |
CtxRef | A wrapper around |
FontDefinitions | Describes the font data and the sizes to use. |
Grid | A simple grid layout. |
Id | egui tracks widgets frame-to-frame using |
InnerResponse | Returned when we wrap some ui-code and want to return both the results of the inner function and the ui as a whole, e.g.: |
InputState | Input state that egui updates each frame. |
Layout | The layout of a |
Memory | The data that egui persists between frames. |
Modifiers | State of the modifier keys. These must be fed to egui. |
Output | What egui emits each frame. The backend should use this. |
Painter | Helper to paint shapes and text to a specific region on a specific layer. |
PointerState | Mouse or touch state. |
Pos2 | A position on screen. |
RawInput | What the integrations provides to egui at the start of each frame. |
Rect | A rectangular region of space. |
Response | The result of adding a widget to a |
Rgba | 0-1 linear space |
Sense | What sort of interaction is a widget sensitive to? |
Stroke | Describes the width and color of a line. |
Texture | An 8-bit texture containing font data. |
Ui | This is what you use to place widgets. |
Vec2 | A vector has a direction and length.
A |
Enums
Align | left/center/right or top/center/bottom alignment for e.g. anchors and layouts. |
CursorIcon | A mouse cursor icon. |
Direction | Layout direction, one of |
Event | An input event generated by the integration. |
FontFamily | Which style of font: |
Key | Keyboard keys. |
PointerButton | Mouse button (or similar for touch input) |
Shape | A paint primitive such as a circle or a piece of text. Coordinates are all screen space points (not physical pixels). |
TextStyle | One of a few categories of styles of text, e.g. body, button or heading. |
TextureId | What texture to use in a |
Constants
NUM_POINTER_BUTTONS | Number of pointer buttons supported by egui, i.e. the number of possible states of |
Traits
NumExt | Extends |
Functions
clamp | Returns |
lerp | Linear interpolation. |
pos2 |
|
remap | Linearly remap a value from one range to another,
so that when |
remap_clamp | Like |
vec2 |
|
warn_if_debug_build | Helper function that adds a label when compiling with debug assertions enabled. |