pub struct GpuSurface(/* private fields */);Expand description
A surface the app draws on with its own GPU API (wgpu, Vulkan, Metal,
Direct3D), at its own pace and on its own thread, as it would draw on a
window of its own: an NSView backed by a CAMetalLayer on AppKit.
It has no natural size; the layout sizes it.
on_ready gets its SurfaceHandle once the native surface exists,
and on_resize its size in pixels whenever that or its scale changes;
the handle’s size() has it too, for a render thread. The handle keeps
the native surface alive after the widget is gone, so drop it (and the
GPU surface made on it) when the app is done presenting.
The surface sits above the window’s own content, as the platform layers it. Its label is its accessible name.
With on_input it takes keys and the pointer: a click or Tab focuses
it, and it gets every key the window doesn’t take first for its menus’
shortcuts, Tab too (Control+Tab leaves it on AppKit and GTK, as it
leaves a text view). pointer_lock hides and holds the cursor and
reports its moves; keyboard_grab takes the system’s shortcuts and
the app’s own as well. The platform ends both when the window stops
being the active one (the grab also when the surface loses focus), and
sets their signals back to false: the app locks again, say, on the
next click. cursor is the cursor over it: the platform’s, none, or
the app’s own image.
GpuSurface::new()
.label("Machine")
.on_ready(move |surface| renderer.send(Message::Surface(surface)))
.on_resize(move |size| renderer.send(Message::Resize(size)))
.on_input(move |input| machine.send(Message::Input(input)))
.pointer_lock(captured)
.keyboard_grab(captured)Implementations§
Source§impl GpuSurface
impl GpuSurface
pub fn new() -> GpuSurface
Sourcepub fn label(self, label: impl IntoValue<String>) -> GpuSurface
pub fn label(self, label: impl IntoValue<String>) -> GpuSurface
Its accessible name: what the app draws there.
Sourcepub fn on_window_active(self, handler: impl Fn(bool) + 'static) -> GpuSurface
pub fn on_window_active(self, handler: impl Fn(bool) + 'static) -> GpuSurface
The window it’s in became the active one, or stopped being it. The surface keeps its focus through this: a caret it paints should stop anyway, as a text field’s does.
Sourcepub fn on_ready(self, handler: impl Fn(SurfaceHandle) + 'static) -> GpuSurface
pub fn on_ready(self, handler: impl Fn(SurfaceHandle) + 'static) -> GpuSurface
The native surface exists: make the GPU surface on it. Called once.
Sourcepub fn on_resize(self, handler: impl Fn(SurfaceSize) + 'static) -> GpuSurface
pub fn on_resize(self, handler: impl Fn(SurfaceSize) + 'static) -> GpuSurface
Its size in pixels, or its scale, changed: configure the GPU surface for it.
Sourcepub fn on_input(self, handler: impl Fn(SurfaceInput) + 'static) -> GpuSurface
pub fn on_input(self, handler: impl Fn(SurfaceInput) + 'static) -> GpuSurface
Takes keys and the pointer, and reports them: a key down or up, the pointer’s moves, buttons and scrolling over it, and while it’s locked, how far it moved. Keys down when it loses focus, or its window stops being the active one, are reported released then.
Sourcepub fn pointer_lock(self, locked: Signal<bool>) -> GpuSurface
pub fn pointer_lock(self, locked: Signal<bool>) -> GpuSurface
Hides and holds the cursor while locked is true, reporting its
moves as SurfaceInput::Motion, and before the host’s acceleration
as SurfaceInput::RawMotion. The platform ends it when the
window stops being the active one, and locked goes back to false.
Sourcepub fn cursor(self, cursor: impl IntoValue<Cursor>) -> GpuSurface
pub fn cursor(self, cursor: impl IntoValue<Cursor>) -> GpuSurface
The pointer’s cursor over it, while it isn’t locked: the platform’s own, none, or an image of the app’s (the one a machine gives its pointer, say).
Sourcepub fn text_input(self, on: impl IntoValue<bool>) -> GpuSurface
pub fn text_input(self, on: impl IntoValue<bool>) -> GpuSurface
Takes text, as a text field does, while on is true: keys report
what they type (SurfaceInput::Key’s text), and the platform’s
input methods are on while it has focus, committing as
SurfaceInput::Text. With on_input, which reports them.
Sourcepub fn input_method(self, on: impl IntoValue<bool>) -> GpuSurface
pub fn input_method(self, on: impl IntoValue<bool>) -> GpuSurface
Whether the platform’s input methods are on while it takes text,
as they are unless on is false: off, keys still report what they
type (layouts, dead keys, AltGr), but nothing composes. For a modal
editor, whose keys outside insert mode are commands.
Sourcepub fn text_cursor(self, caret: impl IntoValue<Option<Rect>>) -> GpuSurface
pub fn text_cursor(self, caret: impl IntoValue<Option<Rect>>) -> GpuSurface
Where the caret is, in points from its top left, while it takes text: the input method’s candidate window opens by it.
Sourcepub fn transparent(self, on: impl IntoValue<bool>) -> GpuSurface
pub fn transparent(self, on: impl IntoValue<bool>) -> GpuSurface
Lets the window’s backdrop show through it while on is true,
where what the app presents isn’t opaque: AppKit puts its
behind-window vibrancy under it, and WinUI’s windows have Mica
already; GTK and Kirigami have no backdrop, so the window’s own
background shows. The app presents with alpha, premultiplied as
the compositor reads it (wgpu’s PostMultiplied mode on Metal, a
composition swapchain with PreMultiplied on Direct3D 12).
Sourcepub fn keyboard_grab(self, grabbed: Signal<bool>) -> GpuSurface
pub fn keyboard_grab(self, grabbed: Signal<bool>) -> GpuSurface
Takes every key while grabbed is true, the system’s shortcuts
(as far as the platform lets an app) and the window’s own too, and
focuses the surface. The platform ends it when the surface or its
window loses focus, and grabbed goes back to false.
Trait Implementations§
Source§impl Default for GpuSurface
impl Default for GpuSurface
Source§fn default() -> GpuSurface
fn default() -> GpuSurface
Source§impl ElementBuilder for GpuSurface
impl ElementBuilder for GpuSurface
fn element(&mut self) -> &mut Element
Source§fn style(self, f: impl FnOnce(&mut Style)) -> Self
fn style(self, f: impl FnOnce(&mut Style)) -> Self
Source§fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
f re-runs whenever the
signals it reads change, and must set every field it cares about.fn width(self, value: impl IntoValue<Length>) -> Self
fn height(self, value: impl IntoValue<Length>) -> Self
fn min_width(self, value: impl IntoValue<Length>) -> Self
fn min_height(self, value: impl IntoValue<Length>) -> Self
fn max_width(self, value: impl IntoValue<Length>) -> Self
fn max_height(self, value: impl IntoValue<Length>) -> Self
fn aspect_ratio(self, value: impl IntoValue<f32>) -> Self
fn padding(self, value: impl IntoValue<Length>) -> Self
fn padding_x(self, value: impl IntoValue<Length>) -> Self
fn padding_y(self, value: impl IntoValue<Length>) -> Self
fn padding_start(self, value: impl IntoValue<Length>) -> Self
fn padding_end(self, value: impl IntoValue<Length>) -> Self
fn padding_top(self, value: impl IntoValue<Length>) -> Self
fn padding_bottom(self, value: impl IntoValue<Length>) -> Self
fn margin(self, value: impl IntoValue<Length>) -> Self
fn margin_x(self, value: impl IntoValue<Length>) -> Self
fn margin_y(self, value: impl IntoValue<Length>) -> Self
fn margin_start(self, value: impl IntoValue<Length>) -> Self
fn margin_end(self, value: impl IntoValue<Length>) -> Self
fn margin_top(self, value: impl IntoValue<Length>) -> Self
fn margin_bottom(self, value: impl IntoValue<Length>) -> Self
fn grow(self, value: impl IntoValue<f32>) -> Self
fn shrink(self, value: impl IntoValue<f32>) -> Self
fn basis(self, value: impl IntoValue<Length>) -> Self
fn align_self(self, value: impl IntoValue<Align>) -> Self
Source§fn justify_self(self, value: impl IntoValue<Align>) -> Self
fn justify_self(self, value: impl IntoValue<Align>) -> Self
Source§fn top(self, value: impl IntoValue<Length>) -> Self
fn top(self, value: impl IntoValue<Length>) -> Self
absolute()).fn bottom(self, value: impl IntoValue<Length>) -> Self
Source§fn start(self, value: impl IntoValue<Length>) -> Self
fn start(self, value: impl IntoValue<Length>) -> Self
fn end(self, value: impl IntoValue<Length>) -> Self
fn grid_column(self, value: impl IntoValue<GridPlacement>) -> Self
fn grid_row(self, value: impl IntoValue<GridPlacement>) -> Self
fn direction(self, value: impl IntoValue<TextDirection>) -> Self
display the node had.fn size( self, width: impl IntoValue<Length>, height: impl IntoValue<Length>, ) -> Self
Source§fn tooltip(self, text: impl IntoValue<String>) -> Self
fn tooltip(self, text: impl IntoValue<String>) -> Self
entries, and built again whenever what it
reads changes, as Menu::children_with builds its entries.entries each time the platform opens it,
for a menu that depends on what’s selected or under the pointer at
that moment: a table row’s menu acting on the selection. What it
reads is read then, not followed.