pub struct WebView { /* private fields */ }Expand description
A WebKit-rendered view that can be embedded into an LTK widget tree
via WebView::element.
Implementations§
Source§impl WebView
impl WebView
Sourcepub fn new(width: f32, height: f32, url: &str) -> Result<Self, String>
pub fn new(width: f32, height: f32, url: &str) -> Result<Self, String>
Create a new WebView, connect it to the user’s Wayland session,
and start loading url. The view does not render until tick
is pumped from the host application’s event loop.
Sourcepub fn resize(&self, width: f32, height: f32)
pub fn resize(&self, width: f32, height: f32)
Resize the embedded view. Updates both the reserved space the
LTK [External] widget claims and the WPEView buffer
dimensions, so click coordinates keep mapping 1:1 and WebKit
re-renders to the new size.
Sourcepub fn tick(&self)
pub fn tick(&self)
Drive WPE’s GMainLoop forward by one non-blocking iteration. Call
this from the host application’s per-frame poll (LTK’s
App::poll_external is the obvious place).
Sourcepub fn pointer_press(&self, x: f64, y: f64)
pub fn pointer_press(&self, x: f64, y: f64)
Forward a left-button press to the embedded view at WPEView
pixel coordinates (x, y). Pair with Self::pointer_release
for a click; intermediate Self::pointer_move calls between
the two construct a drag (which WebKit interprets as text
selection over selectable content).
Sourcepub fn pointer_release(&self, x: f64, y: f64)
pub fn pointer_release(&self, x: f64, y: f64)
Forward a left-button release to the embedded view.
Sourcepub fn click_at(&self, x: f64, y: f64)
pub fn click_at(&self, x: f64, y: f64)
Convenience: synthesise a complete press + release click at
(x, y). Useful for tests / scripted interactions; real user
clicks should go through Self::pointer_press /
Self::pointer_release so drags work.
Sourcepub fn touch_down(&self, id: u32, x: f64, y: f64)
pub fn touch_down(&self, id: u32, x: f64, y: f64)
Forward a touchscreen finger-down to the embedded view. The
touch stream (touch_down / touch_move / touch_up per
finger id) feeds WebKit’s own gesture recognition: tap becomes
click, drag becomes kinetic scroll, two fingers pinch-zoom —
none of which the mouse-event path can express.
Sourcepub fn touch_move(&self, id: u32, x: f64, y: f64)
pub fn touch_move(&self, id: u32, x: f64, y: f64)
See Self::touch_down.
Sourcepub fn scroll(&self, x: f64, y: f64, dx: f64, dy: f64)
pub fn scroll(&self, x: f64, y: f64, dx: f64, dy: f64)
Forward a wheel / touchpad scroll event to the embedded view.
x, y are in WPEView pixel coordinates (same as the host
pointer), dx/dy are scroll deltas in pixels (positive =
down/right, matching WPE convention).
Sourcepub fn pointer_move(&self, x: f64, y: f64)
pub fn pointer_move(&self, x: f64, y: f64)
Forward a pointer-move event to the embedded view at WPEView
pixel coordinates (x, y). WebKit needs this to update hover
state, fire mouseenter / mouseleave, and decide which
cursor it wants — without it the cursor query through
Self::cursor_shape stays at Default.
Sourcepub fn send_key(
&self,
keysym: u32,
keycode: u32,
pressed: bool,
ctrl: bool,
shift: bool,
)
pub fn send_key( &self, keysym: u32, keycode: u32, pressed: bool, ctrl: bool, shift: bool, )
Forward a keyboard event to the embedded view. keysym is the
xkbcommon keysym (the symbol the user effectively pressed,
after xkb layout translation); keycode is the raw hardware
scancode the compositor delivered. pressed selects DOWN vs
UP; ctrl and shift populate the WPEModifiers bitfield.
Sourcepub fn take_redraw_request(&self) -> bool
pub fn take_redraw_request(&self) -> bool
Returns true once for every new buffer WebKit has produced
since the previous call. The host’s invalidate_after should
return InvalidationScope::All whenever this is true so LTK
redraws and the new frame becomes visible — keeping the
surface from getting stuck on a stale (sometimes black) frame
when the compositor’s frame-callback chain pauses during a
resize. Idle ticks return false, so static pages cost zero
redraws.
Sourcepub fn cursor_shape(&self) -> CursorShape
pub fn cursor_shape(&self) -> CursorShape
The cursor shape WebKit currently wants for the embedded view.
Mirrors the most recent mouse-target-changed signal payload.
The host application surfaces this through
[ltk::App::cursor_override].
Sourcepub fn element<Msg: Clone + 'static>(&self) -> Element<Msg>
pub fn element<Msg: Clone + 'static>(&self) -> Element<Msg>
Build an LTK [Element] that composites this WebView’s pixels
into the parent widget tree. Uses the dimensions most recently
passed to Self::resize (or the constructor) as the
preferred size; the actual laid-out rect is captured by the
draw closure on every frame and used to drive auto-resize +
input coordinate translation.
Auto Trait Implementations§
impl Freeze for WebView
impl RefUnwindSafe for WebView
impl Send for WebView
impl Sync for WebView
impl Unpin for WebView
impl UnwindSafe for WebView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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