Struct ul_next::view::View

source ·
pub struct View { /* private fields */ }
Expand description

The View class is used to load and display web content.

View is an offscreen web-page container that can be used to display web-content in your application.

You can load content into a View via View::load_url or View::load_html and interact with it via View::fire_mouse_event and similar API.

When displaying a View, the API is different depending on whether you are using the CPU renderer or the GPU renderer:

When using the CPU renderer, you would get the underlying pixel-buffer surface for a View via View::surface.

When using the GPU renderer, you would get the underlying render target and texture information via View::render_target.

Implementations§

source§

impl View

source

pub fn url(&self) -> Result<String, CreationError>

Get the URL of the current page loaded into this View, if any.

source

pub fn title(&self) -> Result<String, CreationError>

Get the title of the current page loaded into this View, if any.

source

pub fn width(&self) -> u32

Get the width of the View, in pixels.

source

pub fn height(&self) -> u32

Get the height of the View, in pixels.

source

pub fn device_scale(&self) -> f64

Get the device scale, ie. the amount to scale page units to screen pixels.

For example, a value of 1.0 is equivalent to 100% zoom. A value of 2.0 is 200% zoom.

source

pub fn set_device_scale(&self, scale: f64)

Set the device scale.

source

pub fn is_accelerated(&self) -> bool

Whether or not the View is GPU-accelerated. If this is false, the page will be rendered via the CPU renderer.

source

pub fn is_transparent(&self) -> bool

Whether or not the View supports transparent backgrounds.

source

pub fn is_loading(&self) -> bool

Check if the main frame of the page is currently loading.

source

pub fn render_target(&self) -> Option<RenderTarget>

Get the RenderTarget for the View.

Only valid when the view is accelerated, and will return None otherwise.

source

pub fn surface(&self) -> Option<Surface>

Get the Surface for the View (native pixel buffer container).

Only valid when the view is not accelerated, and will return None otherwise.

source

pub fn load_html(&self, html: &str) -> Result<(), CreationError>

Load a raw string of HTML, the View will navigate to it as a new page.

source

pub fn load_url(&self, url: &str) -> Result<(), CreationError>

Load a URL, the View will navigate to it as a new page.

You can use File URLs (eg, file:///page.html) as well.

source

pub fn resize(&self, width: u32, height: u32)

Resize View to a certain size.

§Arguments
  • width - The new width in pixels.
  • height - The new height in pixels.
source

pub fn evaluate_script( &self, script: &str ) -> Result<Result<String, String>, CreationError>

Helper function to evaluate a raw string of JavaScript and return the result as a String.

You can pass the raw Javascript string in script, if an exception occurs it will be returned in Err, otherwise a string result in Ok will be returned.

source

pub fn can_go_back(&self) -> bool

Whether or not we can navigate backwards in history

source

pub fn can_go_forward(&self) -> bool

Whether or not we can navigate forwards in history

source

pub fn go_back(&self)

Navigate backwards in history

source

pub fn go_forward(&self)

Navigate forwards in history

source

pub fn go_to_history_offset(&self, offset: i32)

Navigate to an arbitrary offset in history

source

pub fn reload(&self)

Reload current page

source

pub fn stop(&self)

Stop all page loads

source

pub fn focus(&self)

Give focus to the View.

You should call this to give visual indication that the View has input focus (changes active text selection colors, for example).

source

pub fn unfocus(&self)

Remove focus from the View and unfocus any focused input elements.

You should call this to give visual indication that the View has lost input focus.

source

pub fn has_focus(&self) -> bool

Whether or not the View has focus.

source

pub fn has_input_focus(&self) -> bool

Whether or not the View has an input element with visible keyboard focus (indicated by a blinking caret).

You can use this to decide whether or not the View should consume keyboard input events (useful in games with mixed UI and key handling).

source

pub fn fire_key_event(&self, key_event: KeyEvent)

Fire a keyboard event

Note that only KeyEventType::Char events actually generate text in input fields.

source

pub fn fire_mouse_event(&self, mouse_event: MouseEvent)

Fire a mouse event

source

pub fn fire_scroll_event(&self, scroll_event: ScrollEvent)

Fire a scroll event

source

pub fn set_change_title_callback<F>(&self, callback: F)
where F: FnMut(&View, String) + 'static,

Called when the page title changes

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • title: String - The new title
source

pub fn set_change_url_callback<F>(&self, callback: F)
where F: FnMut(&View, String) + 'static,

Called when the page URL changes

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • url: String - The new url
source

pub fn set_change_tooltip_callback<F>(&self, callback: F)
where F: FnMut(&View, String) + 'static,

Called when the tooltip changes (usually as result of a mouse hover)

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • tooltip: String - The tooltip string
source

pub fn set_change_cursor_callback<F>(&self, callback: F)
where F: FnMut(&View, Cursor) + 'static,

Called when the mouse cursor changes

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • cursor: Cursor - The cursor type
source

pub fn set_add_console_message_callback<F>(&self, callback: F)

Called when a message is added to the console (useful for errors / debug)

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • message_source: ConsoleMessageSource - The source of the message
  • message_level: ConsoleMessageLevel - The level of the message
  • message: String - The message
  • line_number: i32 - The line number of the message
  • column_number: i32 - The column number of the message
  • source_id: String - The source id of the message
source

pub fn set_create_child_view_callback<F>(&self, callback: F)
where F: FnMut(&View, String, String, bool, Rect<i32>) -> Option<View> + 'static,

Set callback for when the page wants to create a new View.

This is usually the result of a user clicking a link with target=“_blank” or by JavaScript calling window.open(url).

To allow creation of these new Views, you should create a new View in this callback (eg. Renderer::create_view), resize it to your container, and return it. You are responsible for displaying the returned View.

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • opener_url: String - The url of the page that initiated this request
  • target_url: String - The url the new View will navigate to
  • is_popup: bool - Whether or not this was triggered by window.open()
  • popup_rect: Rect<i32> - Popups can optionally request certain dimensions and coordinates via window.open(). You can choose to respect these or not by resizing/moving the View to this rect.

You should return None if you want to block the action.

source

pub fn set_begin_loading_callback<F>(&self, callback: F)
where F: FnMut(&View, u64, bool, String) + 'static,

Called when the page begins loading a new URL into a frame.

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • frame_id: u64 - A unique ID for the frame
  • is_main_frame: bool - Whether or not this is the main frame
  • url: String - The url that is being loaded
source

pub fn set_finish_loading_callback<F>(&self, callback: F)
where F: FnMut(&View, u64, bool, String) + 'static,

Called when the page finishes loading a URL into a frame.

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • frame_id: u64 - A unique ID for the frame
  • is_main_frame: bool - Whether or not this is the main frame
  • url: String - The url that is being loaded
source

pub fn set_fail_loading_callback<F>(&self, callback: F)
where F: FnMut(&View, u64, bool, String, String, String, i32) + 'static,

Called when an error occurs while loading a URL into a frame.

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • frame_id: u64 - A unique ID for the frame
  • is_main_frame: bool - Whether or not this is the main frame
  • url: String - The url that is being loaded
  • description: String - A human-readable description of the error.
  • error_domain: String - The name of the module that triggered the error.
  • error_code: u32 - Internal error code generated by the module
source

pub fn set_window_object_ready_callback<F>(&self, callback: F)
where F: FnMut(&View, u64, bool, String) + 'static,

Set callback for when the JavaScript window object is reset for a new page load.

This is called before any scripts are executed on the page and is the earliest time to setup any initial JavaScript state or bindings.

The document is not guaranteed to be loaded/parsed at this point. If you need to make any JavaScript calls that are dependent on DOM elements or scripts on the page, use DOMReady instead.

The window object is lazily initialized (this will not be called on pages with no scripts).

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • frame_id: u64 - A unique ID for the frame
  • is_main_frame: bool - Whether or not this is the main frame
  • url: String - The url that is being loaded
source

pub fn set_dom_ready_callback<F>(&self, callback: F)
where F: FnMut(&View, u64, bool, String) + 'static,

Called when all JavaScript has been parsed and the document is ready.

This is the best time to make any JavaScript calls that are dependent on DOM elements or scripts on the page.

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
  • frame_id: u64 - A unique ID for the frame
  • is_main_frame: bool - Whether or not this is the main frame
  • url: String - The url that is being loaded
source

pub fn set_update_history_callback<F>(&self, callback: F)
where F: FnMut(&View) + 'static,

Called when the session history (back/forward state) is modified.

§Callback Arguments
  • view: &View - The view that fired the event (eg. self)
source

pub fn set_needs_paint(&self, needs_paint: bool)

Set whether or not this View should be repainted during the next call to Renderer::render.

This flag is automatically set whenever the page content changes but you can set it directly in case you need to force a repaint.

source

pub fn needs_paint(&self) -> bool

Whether or not this View should be repainted during the next call to Renderer::render.

Trait Implementations§

source§

impl Drop for View

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for View

§

impl !Send for View

§

impl !Sync for View

§

impl Unpin for View

§

impl UnwindSafe for View

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<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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.