Struct druid::WindowHandle

source ·
pub struct WindowHandle(_);
Expand description

A handle to a platform window object.

Implementations§

source§

impl WindowHandle

source

pub fn show(&self)

Make this window visible.

source

pub fn close(&self)

Close the window.

source

pub fn hide(&self)

Hide the window

source

pub fn resizable(&self, resizable: bool)

Set whether the window should be resizable

source

pub fn set_window_state(&mut self, state: WindowState)

Sets the state of the window.

source

pub fn get_window_state(&self) -> WindowState

Gets the state of the window.

source

pub fn handle_titlebar(&self, val: bool)

Informs the system that the current location of the mouse should be treated as part of the window’s titlebar. This can be used to implement a custom titlebar widget. Note that because this refers to the current location of the mouse, you should probably call this function in response to every relevant WinHandler::mouse_move.

This is currently only implemented on Windows and GTK.

source

pub fn show_titlebar(&self, show_titlebar: bool)

Set whether the window should show titlebar.

source

pub fn set_position(&self, position: impl Into<Point>)

Sets the position of the window.

The position is given in display points, measured relative to the parent window if there is one, or the origin of the virtual screen if there is no parent.

source

pub fn set_always_on_top(&self, always_on_top: bool)

Sets whether the window is always on top of other windows.

How and if this works is system dependent, by either setting a flag, or setting the level. On Wayland systems, the user needs to manually set this in the titlebar.

source

pub fn set_input_region(&self, region: Option<Region>)

Sets where in the window the user can interact with the program.

This enables irregularly shaped windows. For example, you can make it simply not rectangular or you can make a sub-window which can be moved even on Wayland.

The contents of region are added together, and are specified in display points, so you do not need to deal with scale yourself.

On GTK and Wayland, this is specified as where the user can interact with the program. On Windows, this is specified as both where you can interact, and where the window is visible. So on Windows it will hide all regions not specified. On macOS, this does nothing, but you can make the window transparent for the same effect. On Web, this does nothing.

source

pub fn get_position(&self) -> Point

Returns the position of the top left corner of the window.

The position is returned in display points, measured relative to the parent window if there is one, of the origin of the virtual screen if there is no parent.

source

pub fn content_insets(&self) -> Insets

Returns the insets of the window content from its position and size in display points.

This is to account for any window system provided chrome, e.g. title bars. For example, if you want your window to have room for contents of size contents, then you should call WindowHandle::get_size with an argument of (contents.to_rect() + insets).size(), where insets is the return value of this function.

The details of this function are somewhat platform-dependent. For example, on Windows both the insets and the window size include the space taken up by the title bar and window decorations; on GTK neither the insets nor the window size include the title bar or window decorations.

source

pub fn set_size(&self, size: impl Into<Size>)

Set the window’s size in display points.

The actual window size in pixels will depend on the platform DPI settings.

This should be considered a request to the platform to set the size of the window. The platform might choose a different size depending on its DPI or other platform-dependent configuration. To know the actual size of the window you should handle the WinHandler::size method.

source

pub fn get_size(&self) -> Size

Gets the window size, in display points.

source

pub fn bring_to_front_and_focus(&self)

Bring this window to the front of the window stack and give it focus.

source

pub fn request_anim_frame(&self)

Request that prepare_paint and paint be called next time there’s the opportunity to render another frame. This differs from invalidate and invalidate_rect in that it doesn’t invalidate any part of the window.

source

pub fn invalidate(&self)

Request invalidation of the entire window contents.

source

pub fn invalidate_rect(&self, rect: Rect)

Request invalidation of a region of the window.

source

pub fn set_title(&self, title: &str)

Set the title for this menu.

source

pub fn set_menu(&self, menu: Menu)

Set the top-level menu for this window.

source

pub fn text(&self) -> D2DText

Get access to a type that can perform text layout.

source

pub fn add_text_field(&self) -> TextFieldToken

Register a new text input receiver for this window.

This method should be called any time a new editable text field is created inside a window. Any text field with a TextFieldToken that has not yet been destroyed with remove_text_field must be ready to accept input from the platform via WinHandler::text_input at any time, even if it is not currently focused.

Returns the TextFieldToken associated with this new text input.

source

pub fn remove_text_field(&self, token: TextFieldToken)

Unregister a previously registered text input receiver.

If token is the text field currently focused, the platform automatically sets the focused field to None.

source

pub fn set_focused_text_field(&self, active_field: Option<TextFieldToken>)

Notify the platform that the focused text input receiver has changed.

This must be called any time focus changes to a different text input, or when focus switches away from a text input.

source

pub fn update_text_field(&self, token: TextFieldToken, update: Event)

Notify the platform that some text input state has changed, such as the selection, contents, etc.

This method should never be called in response to edits from a InputHandler; only in response to changes from the application: scrolling, remote edits, etc.

source

pub fn request_timer(&self, deadline: Duration) -> TimerToken

Schedule a timer.

This causes a WinHandler::timer call at the deadline. The return value is a token that can be used to associate the request with the handler call.

Note that this is not a precise timer. On Windows, the typical resolution is around 10ms. Therefore, it’s best used for things like blinking a cursor or triggering tooltips, not for anything requiring precision.

source

pub fn set_cursor(&mut self, cursor: &Cursor)

Set the cursor icon.

source

pub fn make_cursor(&self, desc: &CursorDesc) -> Option<Cursor>

source

pub fn open_file( &mut self, options: FileDialogOptions ) -> Option<FileDialogToken>

Prompt the user to choose a file to open.

This won’t block immediately; the file dialog will be shown whenever control returns to druid-shell, and the WinHandler::open_file method will be called when the dialog is closed.

source

pub fn save_as(&mut self, options: FileDialogOptions) -> Option<FileDialogToken>

Prompt the user to choose a path for saving.

This won’t block immediately; the file dialog will be shown whenever control returns to druid-shell, and the WinHandler::save_as method will be called when the dialog is closed.

source

pub fn show_context_menu(&self, menu: Menu, pos: Point)

Display a pop-up menu at the given position.

pos is in the coordinate space of the window.

source

pub fn get_idle_handle(&self) -> Option<IdleHandle>

Get a handle that can be used to schedule an idle task.

source

pub fn get_scale(&self) -> Result<Scale, Error>

Get the DPI scale of the window.

The returned Scale is a copy and thus its information will be stale after the platform DPI changes. This means you should not stash it and rely on it later; it is only guaranteed to be valid for the current pass of the runloop.

Trait Implementations§

source§

impl Clone for WindowHandle

source§

fn clone(&self) -> WindowHandle

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for WindowHandle

source§

fn default() -> WindowHandle

Returns the “default value” for a type. Read more
source§

impl From<WindowHandle> for WindowHandle

source§

fn from(src: WindowHandle) -> WindowHandle

Converts to this type from the input type.
source§

impl HasRawWindowHandle for WindowHandle

source§

impl PartialEq<WindowHandle> for WindowHandle

source§

fn eq(&self, other: &WindowHandle) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for WindowHandle

source§

impl StructuralEq for WindowHandle

source§

impl StructuralPartialEq for WindowHandle

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AnyEq for Twhere T: Any + PartialEq<T>,

source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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.

§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more