Struct druid::WindowHandle
source · pub struct WindowHandle(_);
Expand description
A handle to a platform window object.
Implementations§
source§impl WindowHandle
impl WindowHandle
sourcepub fn set_window_state(&mut self, state: WindowState)
pub fn set_window_state(&mut self, state: WindowState)
Sets the state of the window.
sourcepub fn get_window_state(&self) -> WindowState
pub fn get_window_state(&self) -> WindowState
Gets the state of the window.
sourcepub fn handle_titlebar(&self, val: bool)
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.
sourcepub fn show_titlebar(&self, show_titlebar: bool)
pub fn show_titlebar(&self, show_titlebar: bool)
Set whether the window should show titlebar.
sourcepub fn set_position(&self, position: impl Into<Point>)
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.
sourcepub fn set_always_on_top(&self, always_on_top: bool)
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.
sourcepub fn set_input_region(&self, region: Option<Region>)
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.
sourcepub fn get_position(&self) -> Point
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.
sourcepub fn content_insets(&self) -> Insets
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.
sourcepub fn set_size(&self, size: impl Into<Size>)
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.
sourcepub fn get_size(&self) -> Size
pub fn get_size(&self) -> Size
Gets the window size, in display points.
sourcepub fn bring_to_front_and_focus(&self)
pub fn bring_to_front_and_focus(&self)
Bring this window to the front of the window stack and give it focus.
sourcepub fn request_anim_frame(&self)
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.
sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Request invalidation of the entire window contents.
sourcepub fn invalidate_rect(&self, rect: Rect)
pub fn invalidate_rect(&self, rect: Rect)
Request invalidation of a region of the window.
Set the top-level menu for this window.
sourcepub fn text(&self) -> CoreGraphicsText
pub fn text(&self) -> CoreGraphicsText
Get access to a type that can perform text layout.
sourcepub fn add_text_field(&self) -> TextFieldToken
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.
sourcepub fn remove_text_field(&self, token: TextFieldToken)
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
.
sourcepub fn set_focused_text_field(&self, active_field: Option<TextFieldToken>)
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.
sourcepub fn update_text_field(&self, token: TextFieldToken, update: Event)
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.
sourcepub fn request_timer(&self, deadline: Duration) -> TimerToken
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.
sourcepub fn set_cursor(&mut self, cursor: &Cursor)
pub fn set_cursor(&mut self, cursor: &Cursor)
Set the cursor icon.
pub fn make_cursor(&self, desc: &CursorDesc) -> Option<Cursor>
sourcepub fn open_file(
&mut self,
options: FileDialogOptions
) -> Option<FileDialogToken>
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.
sourcepub fn save_as(&mut self, options: FileDialogOptions) -> Option<FileDialogToken>
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.
Display a pop-up menu at the given position.
pos
is in the coordinate space of the window.
sourcepub fn get_idle_handle(&self) -> Option<IdleHandle>
pub fn get_idle_handle(&self) -> Option<IdleHandle>
Get a handle that can be used to schedule an idle task.
sourcepub fn get_scale(&self) -> Result<Scale, Error>
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
impl Clone for WindowHandle
source§fn clone(&self) -> WindowHandle
fn clone(&self) -> WindowHandle
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Default for WindowHandle
impl Default for WindowHandle
source§fn default() -> WindowHandle
fn default() -> WindowHandle
source§impl From<WindowHandle> for WindowHandle
impl From<WindowHandle> for WindowHandle
source§fn from(src: WindowHandle) -> WindowHandle
fn from(src: WindowHandle) -> WindowHandle
source§impl HasRawWindowHandle for WindowHandle
impl HasRawWindowHandle for WindowHandle
fn raw_window_handle(&self) -> RawWindowHandle
source§impl PartialEq<WindowHandle> for WindowHandle
impl PartialEq<WindowHandle> for WindowHandle
source§fn eq(&self, other: &WindowHandle) -> bool
fn eq(&self, other: &WindowHandle) -> bool
self
and other
values to be equal, and is used
by ==
.