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 mein 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
Responsewith theResponse.clickedmember 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§
| class | Classes |
| commonmark | RenderHtmlFn, RenderMathFn, Alert, AlertBundle, CommonMarkCache |
| containers | Containers are pieces of the UI which wraps other pieces of UI. Examples: |
| 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 |
| 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 |
| 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 |
| os | OperatingSystem |
| output | All the data egui returns to the backend at the end of each frame. |
| response | Response |
| style | egui theme (spacing, colors, etc). |
| syntax_highlighting | TextLayouter, layouter |
| talon | Window |
| 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_style | ButtonStyle, CheckboxStyle, SeparatorStyle, TextVisuals, WidgetState |
| widget_text | RichText, WidgetText |
| widgets | Widgets are pieces of GUI such as |
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. |
| Alpha Enum | What options to show for alpha |
| Area | An area on the screen that can be moved by dragging. |
| AreaState | State of an |
| Atom | A low-level ui building block. |
| AtomKind Enum | The different kinds of |
| AtomLayout |
|
| AtomLayoutResponse | Renamed to |
| Atoms | A list of |
| Brush | Controls texturing of a |
| 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 |
|
| ClippedPrimitive | A |
| ClippedShape | A |
| ClosableTag | A tag to mark a container as closable. |
| CodeTheme | |
| CollapsingHeader | A header which can be collapsed/expanded, revealing a contained |
| CollapsingResponse | The response from showing a |
| 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 |
| DatePickerButton | Shows a date, and will open a date picker popup when clicked. |
| DefaultBytesLoader | Maps URI:s to |
| DefaultTextureLoader | |
| Direction Enum | A cardinal direction, one of |
| 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 |
| DragValue | A numeric value that you can change by dragging the number. More compact than a |
| 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 |
| 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 |
| FontPriority Enum | Whether an inserted font (or |
| Fonts | The collection of fonts used by |
| FontSelection Enum | A way to select |
| 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 ( |
| 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 |
| 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 |
| 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 |
| Hyperlink | A clickable hyperlink, e.g. to |
| Id | |
| IdSalt | A "locally unique" identifier, e.g. to identify a child widget within a parent widget. |
| IdSource Enum | |
| 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 |
| 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 |
| 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 |
| InteractOptions | How to handle multiple calls to |
| Key Enum | |
| KeyboardShortcut | A keyboard shortcut, e.g. |
| Label | Static text. |
| LabelSelectionState | Handles text selection in labels (NOT in |
| LabelStyle | |
| LayerId | An identifier for a paint layer.
Also acts as an identifier for |
| Layout | |
| LayoutJob | Describes the task of laying out text. |
| LayoutSection | A contiguous range of |
| 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 |
| MenuButton | A thin wrapper around a |
| MenuConfig | Configuration and style for menus. |
| MenuResponse | |
| MenuState | Holds the state of the menu. |
| Mesh | Textured triangles in two dimensions. |
| Mesh16 | A version of |
| 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 |
| NumericColorSpace Enum | How to display numeric color values. |
| OpenUrl | What URL to open, and how. |
| OperatingSystem Enum | An |
| 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
( |
| 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 |
| 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. |
| 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 |
| RepaintCause | What called |
| 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 |
| ResponseFlags | |
| Rgba | 0-1 linear space |
| 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 |
| ScrollArea | Add vertical and/or horizontal scrolling to a contained |
| 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 |
| ScrollSource | What is the source of scrolling for a |
| ScrollStyle | Controls the spacing and visuals of a |
| SelectableLabel | |
| Selection | Selected text, selected elements etc |
| Sense | |
| Separator | A visual separator. A horizontal or vertical line (depending on |
| 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 |
| SizedAtomKind Enum | A sized |
| SizedAtomLayout |
|
| 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 |
| SliderOrientation Enum | Specifies the orientation of a |
| SmoothHinting | Tuning for |
| 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 |
| 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 |
| SubMenu | Show a submenu in a menu. |
| SubMenuButton | A submenu button that shows a |
| SurrenderFocusOn Enum | |
| SvgLoader | |
| SystemTheme Enum | |
| Table | Table struct which can construct a |
| TableBody | The body of a table. |
| TableBuilder | Builder for a |
| TableHeader | |
| TableRow | The row of a table.
Is created by |
| TableRows | |
| TessellationOptions | Tessellation quality options |
| Tessellator | |
| 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 |
| 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 |
| TextStyles | |
| TextureFilter Enum | How the texture texels are filtered. |
| TextureHandle | Used to paint images. |
| TextureId Enum | What texture to use in a |
| 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 |
| Theme Enum | Dark or Light theme. |
| ThemePreference Enum | The user's theme preference. |
| Tooltip | |
| TopBottomPanel | |
| TouchDeviceId | this is a |
| 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 |
| UiKind Enum | What kind is this |
| UiStack | Information about a |
| UiStackInfo | Information about a |
| 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 |
| 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 |
| 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 |
| WidgetRect | |
| WidgetRects | Stores the |
| 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 |
| WindowLevel Enum | For winit platform compatibility, see |
| 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 |
| 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 |
| color_picker_hsva_2d | Shows a color picker where the user can change the given |
| 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 ErrorsWill return |
| 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 |
| 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 |
| 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 |
|
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 |
| remap_clamp | Like |
| 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 |
|
| 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 |
| zoom_menu_buttons | Show buttons for zooming the ui. |
| zoom_out | Make everything smaller by decreasing |
SourceFunction accesskit_root_id§
from egui import accesskit_root_iddef accesskit_root_id() -> IdFunction at_least§
from egui import at_leastdef at_least(value: float, lower_limit: float) -> floatFunction at_most§
from egui import at_mostdef at_most(value: float, upper_limit: float) -> floatFunction bar§
from egui import bardef bar() -> AnySourceFunction byte_index_from_char_index§
from egui import byte_index_from_char_indexdef byte_index_from_char_index(s: str, char_index: int) -> intSourceFunction capture§
from egui import capturedef capture() -> strCapture 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_callstackdef capture_callstack() -> strSourceFunction ccursor_next_word§
from egui import ccursor_next_worddef ccursor_next_word(text: str, ccursor: CCursor) -> CCursorSourceFunction ccursor_previous_word§
from egui import ccursor_previous_worddef ccursor_previous_word(text: str, ccursor: CCursor) -> CCursorSourceFunction char_index_from_byte_index§
from egui import char_index_from_byte_indexdef char_index_from_byte_index(input: str, byte_index: int) -> intSourceFunction code_view_ui§
from egui.syntax_highlighting import code_view_uidef code_view_ui(ui: Ui, theme: CodeTheme, code: str, language: str) -> ResponseView some code with syntax highlighting and selection.
SourceFunction color_edit_button_hsva§
from egui import color_edit_button_hsvadef color_edit_button_hsva(ui: Ui, hsva: Hsva, alpha: Alpha) -> ResponseSourceFunction color_edit_button_rgb§
from egui import color_edit_button_rgbdef color_edit_button_rgb(ui: Ui, rgb: Mutable) -> ResponseShows 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_rgbadef color_edit_button_rgba(ui: Ui, rgba: Rgba, alpha: Alpha) -> ResponseShows 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_srgbdef color_edit_button_srgb(ui: Ui, srgb: Mutable) -> ResponseShows 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_srgbadef color_edit_button_srgba(ui: Ui, srgba: Color32, alpha: Alpha) -> ResponseShows 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_color32def color_picker_color32(ui: Ui, srgba: Color32, alpha: Alpha) -> boolShows 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_2ddef color_picker_hsva_2d(ui: Ui, hsva: Hsva, alpha: Alpha) -> boolShows a color picker where the user can change the given Hsva color.
Returns True on change.
SourceFunction cursor_rect§
from egui import cursor_rectdef cursor_rect(galley: Galley, cursor: CCursor, row_height: float) -> RectThe thin rectangle of one end of the selection, e.g. the primary cursor, in local galley coordinates.
Function debug_print§
from egui import debug_printdef debug_print(ctx: Context, text: WidgetText) -> NoneFunction debug_print_str§
from egui import debug_print_strdef debug_print_str(ctx: Context, text: str) -> NoneSourceFunction decode_animated_image_uri§
from egui import decode_animated_image_uridef 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_stylesdef default_text_styles() -> TextStylesThe default text styles of the default egui theme.
SourceFunction find_line_start§
from egui import find_line_startdef find_line_start(text: str, current_index: CCursor) -> CCursorAccepts and returns character offset (NOT byte offset!).
SourceFunction font_family_ui§
from egui import font_family_uidef font_family_ui(ui: Ui, font_family: FontFamily) -> NoneSourceFunction font_id_ui§
from egui import font_id_uidef font_id_ui(ui: Ui, font_id: FontId) -> NoneFunction global_dark_light_mode_buttons§
from egui import global_dark_light_mode_buttonsdef global_dark_light_mode_buttons(ui: Ui) -> NoneFunction global_dark_light_mode_switch§
from egui import global_dark_light_mode_switchdef global_dark_light_mode_switch(ui: Ui) -> NoneSourceFunction global_theme_preference_buttons§
from egui import global_theme_preference_buttonsdef global_theme_preference_buttons(ui: Ui) -> NoneShow 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_switchdef global_theme_preference_switch(ui: Ui) -> NoneShow 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_headerdef has_gif_magic_header(bytes: Any) -> boolChecks if bytes are gifs
SourceFunction has_webp_header§
from egui import has_webp_headerdef has_webp_header(bytes: Any) -> boolChecks if bytes are webp
SourceFunction highlight§
from egui.syntax_highlighting import highlightdef highlight(ctx: Context, style: Style, theme: CodeTheme, code: str, language: str) -> LayoutJobAdd 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_loadersdef install_image_loaders(ctx: Context) -> NoneInstalls 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:
filefeature:file://loader on non-Wasm targetshttpfeature:http(s)://loaderimagefeature: Loader of png, jpeg etc using theimagecratesvgfeature:.svgloader
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://andhttp://URIs, enable theall_loadersfeature. - The supported set of image formats is configured by adding the
imagecrate 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_word_char§
from egui import is_word_chardef is_word_char(c: str) -> boolFunction layouter§
from egui.syntax_highlighting import layouterdef layouter(theme: CodeTheme, language: str) -> TextLayouterSourceFunction lerp§
from egui import lerpdef lerp(min: float, max: float, t: float) -> floatLinear interpolation.
SourceFunction load_svg_bytes§
from egui import load_svg_bytesdef load_svg_bytes(svg_bytes: Sequence[int]) -> ColorImageLoad 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_sizedef load_svg_bytes_with_size(svg_bytes: Sequence[int], size_hint: SizeHint) -> ColorImageLoad 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_uidef loaders_ui(ctx: Context, ui: Ui) -> NoneSourceFunction paint_cursor_end§
from egui import paint_cursor_enddef paint_cursor_end(painter: Painter, visuals: Visuals, cursor_rect: Rect) -> NonePaint one end of the selection, e.g. the primary cursor.
This will never blink.
SourceFunction paint_default_icon§
from egui import paint_default_icondef paint_default_icon(ui: Ui, openness: float, response: Response) -> NonePaint the arrow icon that indicated if the region is open or not
SourceFunction paint_resize_corner§
from egui import paint_resize_cornerdef paint_resize_corner(ui: Ui, response: Response) -> NoneSourceFunction paint_resize_corner_with_style§
from egui import paint_resize_corner_with_styledef paint_resize_corner_with_style(ui: Ui, rect: Rect, color: Color32, corner: Align2) -> NoneSourceFunction paint_text_cursor§
from egui import paint_text_cursordef paint_text_cursor(ui: Ui, painter: Painter, primary_cursor_rect: Rect, time_since_last_interaction: float) -> NonePaint one end of the selection, e.g. the primary cursor, with blinking (if enabled).
SourceFunction paint_text_selection§
from egui import paint_text_selectiondef paint_text_selection(galley: Galley, visuals: Visuals, cursor_range: CCursorRange, collect_new_vertex_indices: bool = False) -> list[RowVertexIndices] |NoneAdds text selection rectangles to the galley.
SourceFunction paint_texture_at§
from egui import paint_texture_atdef paint_texture_at(painter: Painter, rect: Rect, options: ImageOptions, texture: SizedTexture) -> NoneSourceFunction paint_texture_load_result§
from egui import paint_texture_load_resultdef 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) -> NoneSourceFunction pos2§
from egui import pos2def pos2(x: float, y: float) -> Pos2pos2(x, y) == Pos2.new(x, y)
SourceFunction print§
from egui import printdef print(ctx: Context, text: Any) -> NonePrint 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 remapdef remap(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> floatLinearly 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_clampdef remap_clamp(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> floatLike remap, but also clamps the value so that the returned value is always in the to range.
Function render§
from egui import renderdef render(callback: Any, ui: Ui) -> NoneSourceFunction reset_button§
from egui import reset_buttondef reset_button(ui: Ui, value: Mutable, text: str) -> NoneShow 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_withdef reset_button_with(ui: Ui, value: Mutable, text: str, reset_value: Any) -> NoneShow 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_colordef show_color(ui: Ui, color: Color32, desired_size: Vec2) -> ResponseShow a color with background checkers to demonstrate transparency (if any).
SourceFunction show_color_at§
from egui import show_color_atdef show_color_at(painter: Painter, color: Color32, rect: Rect) -> NoneShow a color with background checkers to demonstrate transparency (if any).
Function show_tooltip_text§
from egui import show_tooltip_textdef show_tooltip_text(ctx: Context, parent_layer: LayerId, widget_id: Id, text: WidgetText) -> boolSourceFunction slice_char_range§
from egui import slice_char_rangedef slice_char_range(s: str, start: int, end: int) -> strFunction stroke_ui§
from egui import stroke_uidef stroke_ui(ui: Ui, stroke: Stroke, text: str) -> NoneSourceFunction texture_load_result_response§
from egui import texture_load_result_responsedef texture_load_result_response(source: ImageSource, response: Response, texture_poll: TexturePoll |None = None, error: LoadError |None = None) -> ResponseAttach tooltips like "Loading…" or "Failed loading: …".
SourceFunction vec2§
from egui import vec2def vec2(x: float, y: float) -> Vec2vec2(x, y) == Vec2.new(x, y)
SourceFunction warn_if_debug_build§
from egui import warn_if_debug_builddef warn_if_debug_build(ui: Ui) -> NoneHelper function that adds a label when compiling with debug assertions enabled.
Function was_tooltip_open_last_frame§
from egui import was_tooltip_open_last_framedef was_tooltip_open_last_frame(ctx: Context, widget_id: Id) -> boolSourceFunction zoom_in§
from egui import zoom_indef zoom_in(ctx: Context) -> NoneMake everything larger by increasing Context.zoom_factor.
SourceFunction zoom_out§
from egui import zoom_outdef zoom_out(ctx: Context) -> NoneMake everything smaller by decreasing Context.zoom_factor.
Constants§
| RenderHtmlFn | |
| RenderMathFn | |
| SkipUiBlock |