Struct Window

Source
pub struct Window<'open> { /* private fields */ }
Expand description

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

You can customize:

  • title
  • default, minimum, maximum and/or fixed size, collapsed/expanded
  • if the window has a scroll area (off by default)
  • if the window can be collapsed (minimized) to just the title bar (yes, by default)
  • if there should be a close button (none by default)
egui::Window::new("My Window").show(ctx, |ui| {
   ui.label("Hello World!");
});

The previous rectangle used by this window can be obtained through crate::Memory::area_rect().

Implementations§

Source§

impl<'open> Window<'open>

Source

pub fn new(title: impl Into<WidgetText>) -> Window<'open>

The window title is used as a unique Id and must be unique, and should not change. This is true even if you disable the title bar with .title_bar(false). If you need a changing title, you must call window.id(…) with a fixed id.

Source

pub fn id(self, id: Id) -> Window<'open>

Assign a unique id to the Window. Required if the title changes, or is shared with another window.

Source

pub fn open(self, open: &'open mut bool) -> Window<'open>

Call this to add a close-button to the window title bar.

  • If *open == false, the window will not be visible.
  • If *open == true, the window will have a close button.
  • If the close button is pressed, *open will be set to false.
Source

pub fn enabled(self, enabled: bool) -> Window<'open>

If false the window will be grayed out and non-interactive.

Source

pub fn interactable(self, interactable: bool) -> Window<'open>

If false the window will be non-interactive.

Source

pub fn movable(self, movable: bool) -> Window<'open>

If false the window will be immovable.

Source

pub fn mutate(self, mutate: impl Fn(&mut Window<'open>)) -> Window<'open>

Usage: Window::new(…).mutate(|w| w.resize = w.resize.auto_expand_width(true))

Source

pub fn resize(self, mutate: impl Fn(Resize) -> Resize) -> Window<'open>

Usage: Window::new(…).resize(|r| r.auto_expand_width(true))

Source

pub fn frame(self, frame: Frame) -> Window<'open>

Change the background color, margins, etc.

Source

pub fn min_width(self, min_width: f32) -> Window<'open>

Set minimum width of the window.

Source

pub fn min_height(self, min_height: f32) -> Window<'open>

Set minimum height of the window.

Source

pub fn current_pos(self, current_pos: impl Into<Pos2>) -> Window<'open>

Set current position of the window. If the window is movable it is up to you to keep track of where it moved to!

Source

pub fn default_pos(self, default_pos: impl Into<Pos2>) -> Window<'open>

Set initial position of the window.

Source

pub fn fixed_pos(self, pos: impl Into<Pos2>) -> Window<'open>

Sets the window position and prevents it from being dragged around.

Source

pub fn constrain(self, constrain: bool) -> Window<'open>

Constrains this window to the screen bounds.

To change the area to constrain to, use Self::constraint_to.

Default: true.

Source

pub fn constraint_to(self, constrain_rect: Rect) -> Window<'open>

Constraint the movement of the window to the given rectangle.

For instance: .constrain_to(ctx.screen_rect()).

Source

pub fn drag_bounds(self, constrain_rect: Rect) -> Window<'open>

👎Deprecated: Use constrain_to instead
Source

pub fn pivot(self, pivot: Align2) -> Window<'open>

Where the “root” of the window is.

For instance, if you set this to Align2::RIGHT_TOP then Self::fixed_pos will set the position of the right-top corner of the window.

Default: Align2::LEFT_TOP.

Source

pub fn anchor(self, align: Align2, offset: impl Into<Vec2>) -> Window<'open>

Set anchor and distance.

An anchor of Align2::RIGHT_TOP means “put the right-top corner of the window in the right-top corner of the screen”.

The offset is added to the position, so e.g. an offset of [-5.0, 5.0] would move the window left and down from the given anchor.

Anchoring also makes the window immovable.

It is an error to set both an anchor and a position.

Source

pub fn default_open(self, default_open: bool) -> Window<'open>

Set initial collapsed state of the window

Source

pub fn default_size(self, default_size: impl Into<Vec2>) -> Window<'open>

Set initial size of the window.

Source

pub fn default_width(self, default_width: f32) -> Window<'open>

Set initial width of the window.

Source

pub fn default_height(self, default_height: f32) -> Window<'open>

Set initial height of the window.

Source

pub fn fixed_size(self, size: impl Into<Vec2>) -> Window<'open>

Sets the window size and prevents it from being resized by dragging its edges.

Source

pub fn default_rect(self, rect: Rect) -> Window<'open>

Set initial position and size of the window.

Source

pub fn fixed_rect(self, rect: Rect) -> Window<'open>

Sets the window pos and size and prevents it from being moved and resized by dragging its edges.

Source

pub fn resizable(self, resizable: bool) -> Window<'open>

Can the user resize the window by dragging its edges?

Note that even if you set this to false the window may still auto-resize.

Default is true.

Source

pub fn collapsible(self, collapsible: bool) -> Window<'open>

Can the window be collapsed by clicking on its title?

Source

pub fn title_bar(self, title_bar: bool) -> Window<'open>

Show title bar on top of the window? If false, the window will not be collapsible nor have a close-button.

Source

pub fn auto_sized(self) -> Window<'open>

Not resizable, just takes the size of its contents. Also disabled scrolling. Text will not wrap, but will instead make your window width expand.

Source

pub fn scroll2(self, scroll: [bool; 2]) -> Window<'open>

Enable/disable horizontal/vertical scrolling. false by default.

Source

pub fn hscroll(self, hscroll: bool) -> Window<'open>

Enable/disable horizontal scrolling. false by default.

Source

pub fn vscroll(self, vscroll: bool) -> Window<'open>

Enable/disable vertical scrolling. false by default.

Source

pub fn drag_to_scroll(self, drag_to_scroll: bool) -> Window<'open>

Enable/disable scrolling on the window by dragging with the pointer. true by default.

See ScrollArea::drag_to_scroll for more.

Source§

impl<'open> Window<'open>

Source

pub fn show<R>( self, ctx: &Context, add_contents: impl FnOnce(&mut Ui) -> R, ) -> Option<InnerResponse<Option<R>>>

Returns None if the window is not open (if Window::open was called with &mut false). Returns Some(InnerResponse { inner: None }) if the window is collapsed.

Auto Trait Implementations§

§

impl<'open> Freeze for Window<'open>

§

impl<'open> RefUnwindSafe for Window<'open>

§

impl<'open> Send for Window<'open>

§

impl<'open> Sync for Window<'open>

§

impl<'open> Unpin for Window<'open>

§

impl<'open> !UnwindSafe for Window<'open>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,