S or /

SourceModule egui

egui: an easy-to-use GUI for Python!

Try the live web demo: https://www.egui.rs/#demo. Read more about egui at https://github.com/emilk/egui.

To create a GUI using egui create a Window and set its content function. The function receives a Ui, which is what you'll be using to add all the buttons and labels that you need.

Using egui§

To see what is possible to build with egui you can check out the online demo at https://www.egui.rs/#demo.

A simple example§

Here is a simple counter that can be incremented and decremented using two buttons:

import egui
from talon.egui import Window

count = egui.Mutable(0)

async def draw(ui: egui.Ui):
    async with ui.horizontal() as row:
        if row.button("−").clicked():
            count.set(count.get() - 1)
        row.label(str(count.get()))
        if row.button("+").clicked():
            count.set(count.get() + 1)

window = Window()
window.set_content(draw)
window.show()

In some GUI frameworks this would require defining multiple types and functions with callbacks or message handlers, but thanks to egui being immediate mode everything is one self-contained function!

Quick start§

import egui

my_string = egui.Mutable("")
my_boolean = egui.Mutable(True)
my_number = egui.Mutable(42.0)
my_choice = egui.Mutable("First")

async def draw(ui: egui.Ui):
    ui.label("This is a label")
    ui.hyperlink("https://github.com/emilk/egui")
    ui.text_edit_singleline(my_string)
    if ui.button("Click me").clicked():
        print("Clicked")
    ui.add(egui.Slider(my_number, 0.0, 100.0))
    ui.add(egui.DragValue(my_number))
    ui.checkbox(my_boolean, "Checkbox")
    async with ui.horizontal() as row:
        row.radio_value(my_choice, "First", "First")
        row.radio_value(my_choice, "Second", "Second")
        row.radio_value(my_choice, "Third", "Third")
    ui.separator()
    async with ui.collapsing("Click to see what is hidden!") as contents:
        contents.label("Not much, as it turns out")

Coordinate system§

The left-top corner of the screen is (0.0, 0.0), with X increasing to the right and Y increasing downwards.

egui uses logical points as its coordinate system. Those related to physical pixels by the pixels_per_point scale factor. For example, a high-dpi screen can have pixels_per_point = 2.0, meaning there are two physical screen pixels for each logical point.

Angles are in radians, and are measured clockwise from the X-axis, which has angle=0.

Understanding immediate mode§

egui is an immediate mode GUI library.

Immediate mode has its roots in gaming, where everything on the screen is painted at the display refresh rate, i.e. at 60+ frames per second. In immediate mode GUIs, the entire interface is laid out and painted at the same high rate. This makes immediate mode GUIs especially well suited for highly interactive applications.

It is useful to fully grok what "immediate mode" implies.

Here is an example to illustrate it:

if ui.button("click me").clicked():
    take_action()

This code is being executed each frame at maybe 60 frames per second. Each frame egui does these things:

  • lays out the letters click me in order to figure out the size of the button
  • decides where on screen to place the button
  • check if the mouse is hovering or clicking that location
  • choose button colors based on if it is being hovered or clicked
  • add a rectangle and text shapes to the list of shapes to be painted later this frame
  • return a Response with the Response.clicked member so the user can check for interactions

There is no button being created and stored somewhere. The only output of this call is some colored shapes, and a Response.

Similarly, consider this code:

ui.add(egui.Slider(value, 0.0, 100.0).text("My value"))

Here egui will read value (a Mutable containing a float) to display the slider, then look if the mouse is dragging the slider and if so change the value. Note that egui does not store the slider value for you - it only displays the current value, and changes it by how much the slider has been dragged in the previous few milliseconds. This means it is responsibility of the egui user to store the state (value) so that it persists between frames.

It can be useful to read the code for the toggle switch example widget to get a better understanding of how egui works: https://github.com/emilk/egui/blob/main/crates/egui_demo_lib/src/demo/toggle_switch.rs.

Read more about the pros and cons of immediate mode at https://github.com/emilk/egui#why-immediate-mode.

Multi-pass immediate mode§

By default, egui usually only does one pass for each rendered frame. However, egui supports multi-pass immediate mode. Another pass can be requested with Context.request_discard.

This is used by some widgets to cover up "first-frame jitters". For instance, the Grid needs to know the width of all columns before it can properly place the widgets. But it cannot know the width of widgets to come. So it stores the max widths of previous frames and uses that. This means the first time a Grid is shown it will guess the widths of the columns, and will usually guess wrong. This means the contents of the grid will be wrong for one frame, before settling to the correct places. Therefore Grid calls Context.request_discard when it is first shown, so the wrong placement is never visible to the end user.

This is an example of a form of multi-pass immediate mode, where earlier passes are used for sizing, and later passes for layout.

See Context.request_discard and Options.max_passes for more.

Misc§

Widget interaction§

Each widget has a Sense, which defines whether or not the widget is sensitive to clicking and/or drags.

For instance, a Button only has a Sense.click (by default). This means if you drag a button it will not respond with Response.dragged. Instead, the drag will continue through the button to the first widget behind it that is sensitive to dragging, which for instance could be a ScrollArea. This lets you scroll by dragging a scroll area (important on touch screens), just as long as you don't drag on a widget that is sensitive to drags (e.g. a Slider).

When widgets overlap it is the last added one that is considered to be on top and which will get input priority.

The widget interaction logic is run at the start of each frame, based on the output from the previous frame. This means that when a new widget shows up you cannot click it in the same frame (i.e. in the same fraction of a second), but unless the user is spider-man, they wouldn't be fast enough to do so anyways.

By running the interaction code early, egui can actually tell you if a widget is being interacted with before you add it, as long as you know its Id before-hand (e.g. using Ui.next_auto_id), by calling Context.read_response. This can be useful in some circumstances in order to style a widget, or to respond to interactions before adding the widget (perhaps on top of other widgets).

Installing additional fonts§

The default egui fonts only support latin and cryllic characters, and some emojis. To use egui with e.g. asian characters you need to install your own font (.ttf or .otf) using Context.set_fonts.

Modules§

classClasses
commonmarkRenderHtmlFn, RenderMathFn, Alert, AlertBundle, CommonMarkCache
containers

Containers are pieces of the UI which wraps other pieces of UI. Examples: Window, ScrollArea, Resize, Panel, etc.

debug_text

This is an example of how to create a plugin for egui.

ecolor

Color conversions and types.

egui_extras

This is a crate that adds some features on top top of egui.

emath

Opinionated 2D math library for building GUIs.

epaint

A simple 2D graphics library for turning simple 2D shapes and text into textured triangles.

gui_zoom

Helpers for zooming the whole GUI of an app (changing Context.pixels_per_point).

input

The input needed by egui.

introspection

Showing UI:s for egui/epaint types.

layers

Handles paint layers, i.e. how things are sometimes painted behind or in front of other things.

load

Image loading

osOperatingSystem
output

All the data egui returns to the backend at the end of each frame.

responseResponse
style

egui theme (spacing, colors, etc).

syntax_highlightingTextLayouter, layouter
talonWindow
text_selection

Helpers regarding text selection for labels and text edit.

util

Miscellaneous tools used by the rest of egui.

viewport

egui supports multiple viewports, corresponding to multiple native windows.

widget_styleButtonStyle, CheckboxStyle, SeparatorStyle, TextVisuals, WidgetState
widget_textRichText, WidgetText
widgets

Widgets are pieces of GUI such as Label, Button, Slider etc.

Classes§

Alert
AlertBundle
Align Enum

left/center/right or top/center/bottom alignment for e.g. anchors and layouts.

Align2

Two-dimension alignment, e.g. Align2.LEFT_TOP.

Alpha Enum

What options to show for alpha

Area

An area on the screen that can be moved by dragging.

AreaState

State of an Area that is persisted between frames.

Atom

A low-level ui building block.

AtomKind Enum

The different kinds of egui.Atoms.

AtomLayout

AtomLayout was split into WidgetAtom (id, sense, allocation) and ContainerAtom (layout & painting). WidgetAtom is the direct replacement.

AtomLayoutResponse

Renamed to WidgetAtomResponse.

Atoms

A list of Atoms.

Brush

Controls texturing of a egui.RectShape.

Button

Clickable button with text.

ButtonStyle

Dedicated button style

Bytes Enum

Represents a byte buffer.

BytesLoader
BytesPoll Enum

Represents bytes which are currently being loaded.

CCursor

Character cursor.

CCursorRange

A selected text range (could be a range of length zero).

CentralPanel

A panel that covers the remainder of the screen, i.e. whatever area is left after adding other panels.

Checkbox

Boolean on/off control with text label.

CheckboxStyle

Dedicated checkbox style

CircleShape

How to paint a circle.

Classes

Classes is a collection of ClassNames that can be added to widgets or containers.

ClippedPrimitive

A Mesh or PaintCallback within a clip rectangle.

ClippedShape

A Shape within a clip rectangle.

ClosableTag

A tag to mark a container as closable.

CodeTheme
CollapsingHeader

A header which can be collapsed/expanded, revealing a contained Ui region.

CollapsingResponse

The response from showing a CollapsingHeader.

CollapsingState

This is a a building block for building collapsing regions.

Color32

This format is used for space-efficient color representation (32 bits).

ColorImage

A 2D RGBA color image in RAM.

Column

Specifies the properties of a column, like its width range.

ComboBox

A drop-down selection menu with a descriptive label.

ComboBoxResponse
CommonMarkCache
CommonMarkViewer
Context

Your handle to egui.

CornerRadius

How rounded the corners of things should be.

CubicBezierShape

A cubic Bézier Curve.

CursorGrab Enum
CursorIcon Enum

A mouse cursor icon.

CustomCursorImage

A bitmap cursor pushed to the integration via PlatformOutput.cursor_image.

DatePickerButton

Shows a date, and will open a date picker popup when clicked.

DefaultBytesLoader

Maps URI:s to Bytes, e.g. found with include_bytes!.

DefaultTextureLoader
Direction Enum

A cardinal direction, one of LeftToRight, RightToLeft, TopDown, BottomUp.

DragAndDrop

Plugin for tracking drag-and-drop payload.

DragPanButtons

Specifies which pointer buttons can be used to pan the scene by dragging.

DragScroll Enum

When ScrollArea should let the user scroll by dragging the content.

DragValue

A numeric value that you can change by dragging the number. More compact than a egui.Slider.

DroppedFile
EllipseShape

How to paint an ellipse.

Event Enum

An input event generated by the integration.

EventFilter

Controls which events that a focused widget will have exclusive access to.

FileLoader
FocusDirection Enum

A direction in which to move the keyboard focus.

FontColorTransferFunction Enum

How to convert font coverage values into alpha and color values.

FontData

A .ttf or .otf file and a font face index.

FontDefinitions

Describes a set of pre-configured fonts.

FontFamily Enum

Font of unknown size.

FontId

How to select a sized font.

FontInsert

A font to add to FontDefinitions, and which families to add it to.

FontPriority Enum

Whether an inserted font (or egui.text.GlyphRasterizer) goes before or after the existing fonts of a family.

Fonts

The collection of fonts used by epaint.

FontSelection Enum

A way to select FontId, either by picking one directly or by using a TextStyle.

FontTweak

Extra scale and vertical tweak to apply to all text of a certain font.

FontVariationAxis

A single variation axis of a variable font, e.g. weight (wght) or width (wdth).

Frame

A frame around some content, including margin, colors, etc.

FrameDurations

Stores the durations between each frame of an animated image

FullOutput

What egui emits each frame from egui.Context.run_ui.

Galley

Text that has been laid out, ready for painting.

Grid

A simple grid layout.

HandleShape Enum

Shape of the handle for sliders and similar widgets.

HexColor Enum

A wrapper around Color32 that converts to and from a hex-color string

HintingTarget Enum

How to hint glyph outlines, i.e. how aggressively to nudge them onto the pixel grid before rasterizing. Mirrors skrifa.outline.Target.

HoveredFile

A file about to be dropped into egui.

Hsva

Hue, saturation, value, alpha. All in the range [0, 1]. No premultiplied alpha.

HsvaGamma

Like Hsva but with the v value (brightness) being gamma corrected so that it is somewhat perceptually even.

Hyperlink

A clickable hyperlink, e.g. to "https://github.com/emilk/egui".

Id
IdSalt

A "locally unique" identifier, e.g. to identify a child widget within a parent widget.

IdSource Enum

Is this Ui a root or a child of another Ui?

IdTypeMap
Image

A widget which displays an image.

ImageButton
ImageData Enum

An image stored in RAM.

ImageDelta

A change to an image.

ImageFit Enum

This type determines how the image should try to fit within the UI.

ImageLoader
ImageOptions
ImagePoll Enum

Represents an image which is currently being loaded.

ImageSize

This type determines the constraints on how the size of an image should be calculated.

ImageSource Enum

This type tells the Ui how to load an image.

ImeComposition

Visual style for IME composition.

ImeEvent Enum

IME event.

IMEOutput

Information about text being edited.

IMEPurpose Enum
InputOptions

Options for input state handling.

InputState

Input state that egui updates each frame.

InsertFontFamily

Where in the fallback chain of a FontFamily a FontInsert goes.

Interaction

How and when interaction happens.

InteractionSnapshot

Calculated at the start of each frame based on: * Widget rects from precious frame * Mouse/touch input * Current InteractionState.

InteractOptions

How to handle multiple calls to egui.Response.interact and egui.Ui.interact_opt.

Key Enum
KeyboardShortcut

A keyboard shortcut, e.g. Ctrl+Alt+W.

Label

Static text.

LabelSelectionState

Handles text selection in labels (NOT in egui.TextEdit)s.

LabelStyle
LayerId

An identifier for a paint layer. Also acts as an identifier for egui.Area:s.

Layout
LayoutJob

Describes the task of laying out text.

LayoutSection

A contiguous range of LayoutJob.text that shares the same TextFormat.

Link

Clickable text, that looks like a hyperlink.

LoadError Enum

Represents a failed attempt at loading an image.

Loaders

The loaders of bytes, images, and textures.

Margin

A value for all four sides of a rectangle, often used to express padding or spacing.

MarginF32

A value for all four sides of a rectangle, often used to express padding or spacing.

Memory

The data that egui persists between frames.

MenuBar

Horizontal menu bar where you can add MenuButtons.

MenuButton

A thin wrapper around a Button that shows a Popup.menu when clicked.

MenuConfig

Configuration and style for menus.

MenuResponse
MenuState

Holds the state of the menu.

Mesh

Textured triangles in two dimensions.

Mesh16

A version of Mesh that uses 16-bit indices.

MeshVertex
Modal

A modal dialog.

ModalResponse

The response of a modal dialog.

ModifierNames

Names of different modifier keys.

Modifiers

State of the modifier keys. These must be fed to egui.

MouseWheelUnit Enum

The unit associated with the numeric value of a mouse wheel event

MultiTouchInfo

All you probably need to know about a multi-touch gesture.

Mutable
NumberFormatter

How to format numbers in e.g. a egui.DragValue.

NumericColorSpace Enum

How to display numeric color values.

OpenUrl

What URL to open, and how.

OperatingSystem Enum

An enum of common operating systems.

Options

Some global options that you can read and write.

Order Enum

Different layer categories

OutputCommand Enum

Commands that the egui integration should execute at the end of a frame.

OutputEvent Enum

Things that happened during this frame that the integration may be interested in.

Painter

Helper to paint shapes and text to a specific region on a specific layer.

Panel

A panel that covers an entire side (left, right, top or bottom) of a Ui or screen.

PanelState

State regarding panels.

ParseHexColorError Enum
PathShape

A path which can be stroked and/or filled (if closed).

PathStroke

Describes the width and color of paths. The color can either be solid or provided by a callback. For more information, see ColorMode

PlatformOutput

The non-rendering part of what egui emits each frame.

PointerButton Enum

Mouse button (or similar for touch input)

PointerState

Mouse or touch state.

Popup

A popup container.

PopupAnchor Enum

What should we anchor the popup to?

PopupCloseBehavior Enum

Determines popup's close behavior

PopupKind Enum

Is the popup a popup, tooltip or menu?

PopupResponse
Pos2

A position on screen.

ProgressBar

A simple progress bar.

QuadraticBezierShape

A quadratic Bézier Curve.

RadioButton

One out of several alternatives, either selected or not.

Rangef

Inclusive range of floats, i.e. min..=max, but more ergonomic than RangeInclusive.

RawInput

What the integrations provides to egui at the start of each frame.

Rect

A rectangular region of space.

RectAlign
RectShape

How to paint a rectangle.

RectTransform

Linearly transforms positions from one Rect to another.

RepaintCause

What called Context.request_repaint or Context.request_discard?

RequestRepaintInfo

Information given to the backend about when it is time to repaint the ui.

Resize

A region that can be resized by dragging the bottom right corner.

ResizeDirection Enum
Response

The result of adding a widget to a Ui.

ResponseFlags
Rgba

0-1 linear space RGBA color with premultiplied alpha.

RichText

Text and optional style choices for it.

RowVertexIndices
Runtime
SafeAreaInsets

The 'safe area' insets of the screen

Scene

A container that allows you to zoom and pan.

ScrollAnimation

Scroll animation configuration, used when programmatically scrolling somewhere (e.g. with [egui.Ui.scroll_to_cursor](egui.Ui.html#scroll_to_cursor-5999)).

ScrollArea

Add vertical and/or horizontal scrolling to a contained Ui.

ScrollAreaOutput
ScrollAreaRowsUi
ScrollAreaState
ScrollAreaViewportUi
ScrollBarVisibility Enum

Indicate whether the horizontal and vertical scroll bars must be always visible, hidden or visible when needed.

ScrollFadeStyle

Controls if and how to fade out the sides of a egui.ScrollArea to indicate there is more there if you scroll.

ScrollSource

What is the source of scrolling for a ScrollArea.

ScrollStyle

Controls the spacing and visuals of a egui.ScrollArea.

SelectableLabel
Selection

Selected text, selected elements etc

Sense
Separator

A visual separator. A horizontal or vertical line (depending on egui.Layout).

SeparatorStyle

Dedicated separator style

SetOpenCommand Enum
Shadow

The color and fuzziness of a fuzzy shape.

Shape Enum

A paint primitive such as a circle or a piece of text. Coordinates are all screen space points (not physical pixels).

ShownSides
SidePanel
Sides

Put some widgets on the left and right sides of a ui.

Size Enum

Size hint for table column/strip cell.

SizedAtom

A egui.Atom which has been sized.

SizedAtomKind Enum

A sized egui.AtomKind.

SizedAtomLayout

SizedAtomLayout was split into SizedWidgetAtom (id, sense) and SizedContainerAtom (the measured contents). SizedWidgetAtom is the direct replacement.

SizedTexture

A texture with a known size.

SizeHint Enum

Given as a hint for image loading requests.

Slider

Control a number with a slider.

SliderClamping Enum

Specifies how values in a Slider are clamped.

SliderOrientation Enum

Specifies the orientation of a Slider.

SmoothHinting

Tuning for HintingTarget.Smooth, mirroring skrifa's Target.Smooth.

Spacing

Controls the sizes and distances between widgets.

Spinner

A spinner widget used to indicate loading.

Strip

A Strip of cells which go in one direction. Each cell has a fixed size. In contrast to normal egui behavior, strip cells do not grow with its children!

StripBuilder

Builder for creating a new Strip.

Stroke

Describes the width and color of a line.

StrokeKind Enum

Describes how the stroke of a shape should be painted.

Style

Specifies the look and feel of egui.

StyleModifier

Utility to modify a Style in some way. Constructed via StyleModifier.from from a Fn(Style) or a Style.

SubMenu

Show a submenu in a menu.

SubMenuButton

A submenu button that shows a SubMenu if a Button is hovered.

SurrenderFocusOn Enum
SvgLoader
SystemTheme Enum
Table

Table struct which can construct a TableBody.

TableBody

The body of a table.

TableBuilder

Builder for a Table with (optional) fixed header and scrolling body.

TableHeader
TableRow

The row of a table. Is created by TableRow for each created TableBody.row or each visible row in rows created by calling TableBody.rows.

TableRows
TessellationOptions

Tessellation quality options

Tessellator

Converts Shapes into triangles (Mesh).

TextBuffer
TextCursorState

The state of a text cursor selection.

TextCursorStyle

Look and feel of the text cursor.

TextEdit

A text region that the user can edit the contents of.

TextEditOutput

The output from a TextEdit.

TextEditState

The text edit state stored between frames.

TextEditUndoer
TextFormat

Formatting option for a section of text.

TextLayouter
TextOptions

Controls how we render text

TextShape

How to paint some text on screen.

TextStyle Enum

Alias for a FontId (font of a certain size).

TextStyles
TextureFilter Enum

How the texture texels are filtered.

TextureHandle

Used to paint images.

TextureId Enum

What texture to use in a Mesh mesh.

TextureLoader
TextureOptions

How the texture texels are filtered.

TexturePoll Enum

Represents a texture is currently being loaded.

TexturesDelta

What has been allocated and freed during the last period.

TextureWrapMode Enum

Defines how textures are wrapped around objects when texture coordinates fall outside the [0, 1] range.

TextVisuals

General text style

TextWrapMode Enum

How to wrap and elide text.

TextWrapping

Controls the text wrapping and elision of a LayoutJob.

Theme Enum

Dark or Light theme.

ThemePreference Enum

The user's theme preference.

Tooltip
TopBottomPanel
TouchDeviceId

this is a int as values of this kind can always be obtained by hashing

TouchId

Unique identification of a touch occurrence (finger or pen or …). A Touch ID is valid until the finger is lifted. A new ID is used for the next touch.

TouchPhase Enum

In what phase a touch event is in.

TSTransform

Linearly transforms positions via a translation, then a scaling.

Ui

This is what you use to place widgets.

UiBuilder

The properties specified when creating a top-level or child Ui.

UiKind Enum

What kind is this egui.Ui?

UiStack

Information about a egui.Ui and its parents.

UiStackInfo

Information about a egui.Ui to be included in the corresponding UiStack.

Undoer

Automatic undo system.

UndoSettings
UserAttentionType Enum

Types of attention to request from a user when a native window is not in focus.

UserData
Vec2

A vector has a direction and length. A Vec2 is often used to represent a size.

Vec2b

Two bools, one for each axis (X and Y).

ViewportBuilder

Control the building of a new egui viewport (i.e. native window).

ViewportClass Enum

The different types of viewports supported by egui.

ViewportCommand Enum

An output viewport-command from egui to the backend, e.g. to change the window title or size.

ViewportEvent Enum

An input event from the backend into egui, about a specific viewport.

ViewportId

A unique identifier of a viewport.

ViewportIdPair

A pair of ViewportId, used to identify a viewport and its parent.

ViewportInfo

Information about the current viewport, given as input each frame.

ViewportOutput

Describes a viewport, i.e. a native window.

ViewportUi
Visuals

Controls the visual style (colors etc) of egui.

WidgetInfo

Describes a widget such as a egui.Button or a egui.TextEdit.

WidgetRect

Used to store each widget's Id, Rect and Sense each frame.

WidgetRects

Stores the WidgetRects of all widgets generated during a single egui update/frame.

Widgets

The visuals of widgets for different states of interaction.

WidgetState Enum

The different state of a widget can be

WidgetStyle
WidgetText Enum

This is how you specify text for a widget.

WidgetType Enum

The different types of built-in widgets in egui

WidgetVisuals

bg = background, fg = foreground.

Window

Builder for a floating window which can be dragged, closed, collapsed, resized and scrolled (off by default).

Window
WindowDrag Enum

Where the user can drag to move a Window.

WindowLevel Enum

For winit platform compatibility, see winit.WindowLevel documentation

X11WindowType Enum

Functions§

accesskit_root_id
at_least
at_most
bar
byte_index_from_char_index
capture

Capture a callstack, skipping the frames that are not interesting.

capture_callstack
ccursor_next_word
ccursor_previous_word
char_index_from_byte_index
code_view_ui

View some code with syntax highlighting and selection.

color_edit_button_hsva
color_edit_button_rgb

Shows a button with the given color. If the user clicks the button, a full color picker is shown.

color_edit_button_rgba

Shows a button with the given color. If the user clicks the button, a full color picker is shown.

color_edit_button_srgb

Shows a button with the given color. If the user clicks the button, a full color picker is shown. The given color is in sRGB space.

color_edit_button_srgba

Shows a button with the given color. If the user clicks the button, a full color picker is shown.

color_picker_color32

Shows a color picker where the user can change the given Color32 color.

color_picker_hsva_2d

Shows a color picker where the user can change the given Hsva color.

context_menu
context_menu_opened
cursor_rect

The thin rectangle of one end of the selection, e.g. the primary cursor, in local galley coordinates.

debug_print
debug_print_str
decode_animated_image_uri

Extracts uri and frame index

Errors

Will return Err if uri does not match pattern {uri}-{frame_index}

default_text_styles

The default text styles of the default egui theme.

find_line_start

Accepts and returns character offset (NOT byte offset!).

find_menu_root

Find the root UiStack of the menu.

font_family_ui
font_id_ui
global_dark_light_mode_buttons
global_dark_light_mode_switch
global_theme_preference_buttons

Show a row of buttons for changing the theme of the whole app.

global_theme_preference_switch

Show a small button to switch to/from dark/light mode (globally).

has_gif_magic_header

Checks if bytes are gifs

has_webp_header

Checks if bytes are webp

highlight

Add syntax highlighting to a code string.

install_image_loaders

Installs a set of image loaders.

is_in_menu

Is this Ui part of a menu?

is_word_char
layouter
lerp

Linear interpolation.

load_svg_bytes

Load an SVG and rasterize it into an egui image.

load_svg_bytes_with_size

Load an SVG and rasterize it into an egui image with a scaling parameter.

loaders_ui
menu_button
menu_custom_button
menu_image_button
menu_style

Apply a menu style to the Style.

paint_cursor_end

Paint one end of the selection, e.g. the primary cursor.

paint_default_icon

Paint the arrow icon that indicated if the region is open or not

paint_resize_corner
paint_resize_corner_with_style
paint_text_cursor

Paint one end of the selection, e.g. the primary cursor, with blinking (if enabled).

paint_text_selection

Adds text selection rectangles to the galley.

paint_texture_at
paint_texture_load_result
pos2

pos2(x, y) == Pos2.new(x, y)

print

Print this text next to the cursor at the end of the pass.

remap

Linearly remap a value from one range to another, so that when x == from.start() returns to.start() and when x == from.end() returns to.end().

remap_clamp

Like remap, but also clamps the value so that the returned value is always in the to range.

render
reset_button

Show a button to reset a value to its default. The button is only enabled if the value does not already have its original value.

reset_button_with

Show a button to reset a value to its default. The button is only enabled if the value does not already have its original value.

show_color

Show a color with background checkers to demonstrate transparency (if any).

show_color_at

Show a color with background checkers to demonstrate transparency (if any).

show_tooltip_text
slice_char_range
stroke_ui
submenu_button
texture_load_result_response

Attach tooltips like "Loading…" or "Failed loading: …".

vec2

vec2(x, y) == Vec2.new(x, y)

warn_if_debug_build

Helper function that adds a label when compiling with debug assertions enabled.

was_tooltip_open_last_frame
zoom_in

Make everything larger by increasing Context.zoom_factor.

zoom_menu_buttons

Show buttons for zooming the ui.

zoom_out

Make everything smaller by decreasing Context.zoom_factor.

SourceFunction accesskit_root_id§

from egui import accesskit_root_id
def accesskit_root_id() -> Id

Function at_least§

from egui import at_least
def at_least(value: float, lower_limit: float) -> float

Function at_most§

from egui import at_most
def at_most(value: float, upper_limit: float) -> float

Function bar§

from egui import bar
def bar() -> Any

SourceFunction byte_index_from_char_index§

from egui import byte_index_from_char_index
def byte_index_from_char_index(s: str, char_index: int) -> int

SourceFunction capture§

from egui import capture
def capture() -> str

Capture a callstack, skipping the frames that are not interesting.

In particular: slips everything before egui.Context.run, and skipping all frames in the egui. namespace.

Function capture_callstack§

from egui import capture_callstack
def capture_callstack() -> str

SourceFunction ccursor_next_word§

from egui import ccursor_next_word
def ccursor_next_word(text: str, ccursor: CCursor) -> CCursor

SourceFunction ccursor_previous_word§

from egui import ccursor_previous_word
def ccursor_previous_word(text: str, ccursor: CCursor) -> CCursor

SourceFunction char_index_from_byte_index§

from egui import char_index_from_byte_index
def char_index_from_byte_index(input: str, byte_index: int) -> int

SourceFunction code_view_ui§

from egui.syntax_highlighting import code_view_ui
def code_view_ui(ui: Ui, theme: CodeTheme, code: str, language: str) -> Response

View some code with syntax highlighting and selection.

SourceFunction color_edit_button_hsva§

from egui import color_edit_button_hsva
def color_edit_button_hsva(ui: Ui, hsva: Hsva, alpha: Alpha) -> Response

SourceFunction color_edit_button_rgb§

from egui import color_edit_button_rgb
def color_edit_button_rgb(ui: Ui, rgb: Mutable) -> Response

Shows a button with the given color. If the user clicks the button, a full color picker is shown.

SourceFunction color_edit_button_rgba§

from egui import color_edit_button_rgba
def color_edit_button_rgba(ui: Ui, rgba: Rgba, alpha: Alpha) -> Response

Shows a button with the given color. If the user clicks the button, a full color picker is shown.

SourceFunction color_edit_button_srgb§

from egui import color_edit_button_srgb
def color_edit_button_srgb(ui: Ui, srgb: Mutable) -> Response

Shows a button with the given color. If the user clicks the button, a full color picker is shown. The given color is in sRGB space.

SourceFunction color_edit_button_srgba§

from egui import color_edit_button_srgba
def color_edit_button_srgba(ui: Ui, srgba: Color32, alpha: Alpha) -> Response

Shows a button with the given color. If the user clicks the button, a full color picker is shown.

SourceFunction color_picker_color32§

from egui import color_picker_color32
def color_picker_color32(ui: Ui, srgba: Color32, alpha: Alpha) -> bool

Shows a color picker where the user can change the given Color32 color.

Returns True on change.

SourceFunction color_picker_hsva_2d§

from egui import color_picker_hsva_2d
def color_picker_hsva_2d(ui: Ui, hsva: Hsva, alpha: Alpha) -> bool

Shows a color picker where the user can change the given Hsva color.

Returns True on change.

Function context_menu§

from egui import context_menu
def context_menu(response: Response) -> Any

Function context_menu_opened§

from egui import context_menu_opened
def context_menu_opened(response: Response) -> bool

SourceFunction cursor_rect§

from egui import cursor_rect
def cursor_rect(galley: Galley, cursor: CCursor, row_height: float) -> Rect

The thin rectangle of one end of the selection, e.g. the primary cursor, in local galley coordinates.

Function debug_print§

from egui import debug_print
def debug_print(ctx: Context, text: WidgetText) -> None

Function debug_print_str§

from egui import debug_print_str
def debug_print_str(ctx: Context, text: str) -> None

SourceFunction decode_animated_image_uri§

from egui import decode_animated_image_uri
def decode_animated_image_uri(uri: str) -> tuple[str, int]

Extracts uri and frame index

Errors

Will return Err if uri does not match pattern {uri}-{frame_index}

SourceFunction default_text_styles§

from egui import default_text_styles
def default_text_styles() -> TextStyles

The default text styles of the default egui theme.

SourceFunction find_line_start§

from egui import find_line_start
def find_line_start(text: str, current_index: CCursor) -> CCursor

Accepts and returns character offset (NOT byte offset!).

SourceFunction find_menu_root§

from egui import find_menu_root
def find_menu_root(ui: Ui) -> UiStack

Find the root UiStack of the menu.

SourceFunction font_family_ui§

from egui import font_family_ui
def font_family_ui(ui: Ui, font_family: FontFamily) -> None

SourceFunction font_id_ui§

from egui import font_id_ui
def font_id_ui(ui: Ui, font_id: FontId) -> None

Function global_dark_light_mode_buttons§

from egui import global_dark_light_mode_buttons
def global_dark_light_mode_buttons(ui: Ui) -> None

Function global_dark_light_mode_switch§

from egui import global_dark_light_mode_switch
def global_dark_light_mode_switch(ui: Ui) -> None

SourceFunction global_theme_preference_buttons§

from egui import global_theme_preference_buttons
def global_theme_preference_buttons(ui: Ui) -> None

Show a row of buttons for changing the theme of the whole app.

There is one button for each egui.ThemePreference: dark mode, light mode, and following the system theme. The button of the current preference is highlighted.

Each button is a small icon, so this fits in a top bar.

SourceFunction global_theme_preference_switch§

from egui import global_theme_preference_switch
def global_theme_preference_switch(ui: Ui) -> None

Show a small button to switch to/from dark/light mode (globally).

This does not allow switching back to following the system theme, which is why global_theme_preference_buttons is preferred.

SourceFunction has_gif_magic_header§

from egui import has_gif_magic_header
def has_gif_magic_header(bytes: Any) -> bool

Checks if bytes are gifs

SourceFunction has_webp_header§

from egui import has_webp_header
def has_webp_header(bytes: Any) -> bool

Checks if bytes are webp

SourceFunction highlight§

from egui.syntax_highlighting import highlight
def highlight(ctx: Context, style: Style, theme: CodeTheme, code: str, language: str) -> LayoutJob

Add syntax highlighting to a code string.

The results are memoized, so you can call this every frame without performance penalty.

SourceFunction install_image_loaders§

from egui import install_image_loaders
def install_image_loaders(ctx: Context) -> None

Installs a set of image loaders.

Calling this enables the use of egui.Image and egui.Ui.image.

⚠ This will do nothing and you won't see any images unless you also enable some feature flags on egui_extras:

  • file feature: file:// loader on non-Wasm targets
  • http feature: http(s):// loader
  • image feature: Loader of png, jpeg etc using the image crate
  • svg feature: .svg loader

Calling this multiple times on the same egui.Context is safe. It will never install duplicate loaders.

  • If you just want to be able to load file:// and http:// URIs, enable the all_loaders feature.
  • The supported set of image formats is configured by adding the image crate as your direct dependency, and enabling features on it:

⚠ You have to configure both the supported loaders in egui_extras and the supported image formats in image to get any output!

Loader-specific information

⚠ The exact way bytes, images, and textures are loaded is subject to change, but the supported protocols and file extensions are not.

The file loader is a BytesLoaderegui.load.BytesLoader. It will attempt to load file:// URIs, and infer the content type from the extension. The path will be passed to std.fs.read after trimming the file:// prefix, and is resolved the same way as with std.fs.read(path): - Relative paths are relative to the current working directory - Absolute paths are left as is.

The http loader is a BytesLoaderegui.load.BytesLoader. It will attempt to load http:// and https:// URIs, and infer the content type from the Content-Type header.

The image loader is an ImageLoaderegui.load.ImageLoader. It will attempt to load any URI with any extension other than svg. It will also try to load any URI without an extension. The content type specified by BytesPoll.Ready.mimeegui.load.BytesPoll.Ready.mime always takes precedence. This means that even if the URI has a png extension, and the png image format is enabled, if the content type is not one of the supported and enabled image formats, the loader will return LoadError.NotSupportedegui.load.LoadError.NotSupported, allowing a different loader to attempt to load the image.

The svg loader is an ImageLoaderegui.load.ImageLoader. It will attempt to load any URI with an svg extension. It will not attempt to load a URI without an extension. The content type specified by BytesPoll.Ready.mimeegui.load.BytesPoll.Ready.mime always takes precedence, and must include svg for it to be considered supported. For example, image/svg+xml would be loaded by the svg loader.

See egui.load for more information about how loaders work.

SourceFunction is_in_menu§

from egui import is_in_menu
def is_in_menu(ui: Ui) -> bool

Is this Ui part of a menu?

Returns False if this is a menu bar. Should be used to determine if we should show a menu button or submenu button.

SourceFunction is_word_char§

from egui import is_word_char
def is_word_char(c: str) -> bool

Function layouter§

from egui.syntax_highlighting import layouter
def layouter(theme: CodeTheme, language: str) -> TextLayouter

SourceFunction lerp§

from egui import lerp
def lerp(min: float, max: float, t: float) -> float

Linear interpolation.

SourceFunction load_svg_bytes§

from egui import load_svg_bytes
def load_svg_bytes(svg_bytes: Sequence[int]) -> ColorImage

Load an SVG and rasterize it into an egui image.

Requires the "svg" feature.

Errors

On invalid image

SourceFunction load_svg_bytes_with_size§

from egui import load_svg_bytes_with_size
def load_svg_bytes_with_size(svg_bytes: Sequence[int], size_hint: SizeHint) -> ColorImage

Load an SVG and rasterize it into an egui image with a scaling parameter.

Requires the "svg" feature.

Errors

On invalid image

Function loaders_ui§

from egui import loaders_ui
def loaders_ui(ctx: Context, ui: Ui) -> None

Function menu_button§

from egui import menu_button
def menu_button(title: Any) -> Any

Function menu_custom_button§

from egui import menu_custom_button
def menu_custom_button(button: Button) -> Any

Function menu_image_button§

from egui import menu_image_button
def menu_image_button(image_uri: str, title: str) -> Any

SourceFunction menu_style§

from egui import menu_style
def menu_style(style: Style) -> None

Apply a menu style to the Style.

Mainly removes the background stroke and the inactive background fill.

SourceFunction paint_cursor_end§

from egui import paint_cursor_end
def paint_cursor_end(painter: Painter, visuals: Visuals, cursor_rect: Rect) -> None

Paint one end of the selection, e.g. the primary cursor.

This will never blink.

SourceFunction paint_default_icon§

from egui import paint_default_icon
def paint_default_icon(ui: Ui, openness: float, response: Response) -> None

Paint the arrow icon that indicated if the region is open or not

SourceFunction paint_resize_corner§

from egui import paint_resize_corner
def paint_resize_corner(ui: Ui, response: Response) -> None

SourceFunction paint_resize_corner_with_style§

from egui import paint_resize_corner_with_style
def paint_resize_corner_with_style(ui: Ui, rect: Rect, color: Color32, corner: Align2) -> None

SourceFunction paint_text_cursor§

from egui import paint_text_cursor
def paint_text_cursor(ui: Ui, painter: Painter, primary_cursor_rect: Rect, time_since_last_interaction: float) -> None

Paint one end of the selection, e.g. the primary cursor, with blinking (if enabled).

SourceFunction paint_text_selection§

from egui import paint_text_selection
def paint_text_selection(galley: Galley, visuals: Visuals, cursor_range: CCursorRange, collect_new_vertex_indices: bool = False) -> list[RowVertexIndices] |None

Adds text selection rectangles to the galley.

SourceFunction paint_texture_at§

from egui import paint_texture_at
def paint_texture_at(painter: Painter, rect: Rect, options: ImageOptions, texture: SizedTexture) -> None

SourceFunction paint_texture_load_result§

from egui import paint_texture_load_result
def paint_texture_load_result(ui: Ui, rect: Rect, options: ImageOptions, texture_poll: TexturePoll |None = None, error: LoadError |None = None, show_loading_spinner: bool |None = None, alt_text: str |None = None) -> None

SourceFunction pos2§

from egui import pos2
def pos2(x: float, y: float) -> Pos2

pos2(x, y) == Pos2.new(x, y)

SourceFunction print§

from egui import print
def print(ctx: Context, text: Any) -> None

Print this text next to the cursor at the end of the pass.

If you call this multiple times, the text will be appended.

This only works if compiled with debug_assertions.

SourceFunction remap§

from egui import remap
def remap(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float

Linearly remap a value from one range to another, so that when x == from.start() returns to.start() and when x == from.end() returns to.end().

SourceFunction remap_clamp§

from egui import remap_clamp
def remap_clamp(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float

Like remap, but also clamps the value so that the returned value is always in the to range.

Function render§

from egui import render
def render(callback: Any, ui: Ui) -> None

SourceFunction reset_button§

from egui import reset_button
def reset_button(ui: Ui, value: Mutable, text: str) -> None

Show a button to reset a value to its default. The button is only enabled if the value does not already have its original value.

The text could be something like "Reset foo".

SourceFunction reset_button_with§

from egui import reset_button_with
def reset_button_with(ui: Ui, value: Mutable, text: str, reset_value: Any) -> None

Show a button to reset a value to its default. The button is only enabled if the value does not already have its original value.

The text could be something like "Reset foo".

SourceFunction show_color§

from egui import show_color
def show_color(ui: Ui, color: Color32, desired_size: Vec2) -> Response

Show a color with background checkers to demonstrate transparency (if any).

SourceFunction show_color_at§

from egui import show_color_at
def show_color_at(painter: Painter, color: Color32, rect: Rect) -> None

Show a color with background checkers to demonstrate transparency (if any).

Function show_tooltip_text§

from egui import show_tooltip_text
def show_tooltip_text(ctx: Context, parent_layer: LayerId, widget_id: Id, text: WidgetText) -> bool

SourceFunction slice_char_range§

from egui import slice_char_range
def slice_char_range(s: str, start: int, end: int) -> str

Function stroke_ui§

from egui import stroke_ui
def stroke_ui(ui: Ui, stroke: Stroke, text: str) -> None

Function submenu_button§

from egui import submenu_button
def submenu_button(title: Any) -> Any

SourceFunction texture_load_result_response§

from egui import texture_load_result_response
def texture_load_result_response(source: ImageSource, response: Response, texture_poll: TexturePoll |None = None, error: LoadError |None = None) -> Response

Attach tooltips like "Loading…" or "Failed loading: …".

SourceFunction vec2§

from egui import vec2
def vec2(x: float, y: float) -> Vec2

vec2(x, y) == Vec2.new(x, y)

SourceFunction warn_if_debug_build§

from egui import warn_if_debug_build
def warn_if_debug_build(ui: Ui) -> None

Helper function that adds a label when compiling with debug assertions enabled.

Function was_tooltip_open_last_frame§

from egui import was_tooltip_open_last_frame
def was_tooltip_open_last_frame(ctx: Context, widget_id: Id) -> bool

SourceFunction zoom_in§

from egui import zoom_in
def zoom_in(ctx: Context) -> None

Make everything larger by increasing Context.zoom_factor.

SourceFunction zoom_menu_buttons§

from egui import zoom_menu_buttons
def zoom_menu_buttons(ui: Ui) -> None

Show buttons for zooming the ui.

This is meant to be called from within a menu (See Ui.menu_button).

SourceFunction zoom_out§

from egui import zoom_out
def zoom_out(ctx: Context) -> None

Make everything smaller by decreasing Context.zoom_factor.

Constants§

RenderHtmlFn
RenderMathFn
SkipUiBlock

Re-exports§