pub struct Window { /* private fields */ }
Expand description
Sciter window.
Implementations§
Source§impl Window
impl Window
Sourcepub fn create(rect: RECT, flags: Flags, parent: Option<HWINDOW>) -> Window
pub fn create(rect: RECT, flags: Flags, parent: Option<HWINDOW>) -> Window
Create a new window with the specified position, flags and an optional parent window.
Sourcepub fn attach(hwnd: HWINDOW) -> Window
pub fn attach(hwnd: HWINDOW) -> Window
Attach Sciter to an existing native window.
Most likely, there is no need for run_app
or run_loop
after that.
However, to get UI working, you have to route window events
to Sciter - see the blog article.
Sourcepub fn get_host(&self) -> Rc<Host>
pub fn get_host(&self) -> Rc<Host>
Obtain a reference to Host
which offers some advanced control over the Sciter engine instance.
Sourcepub fn sciter_handler<Callback: HostHandler + Sized>(
&mut self,
handler: Callback,
)
pub fn sciter_handler<Callback: HostHandler + Sized>( &mut self, handler: Callback, )
Set a callback for Sciter engine events.
Sourcepub fn event_handler<Handler: EventHandler>(&mut self, handler: Handler)
pub fn event_handler<Handler: EventHandler>(&mut self, handler: Handler)
Attach dom::EventHandler
to the Sciter window.
You should install a window event handler only once - it will survive all document reloads. Also it can be registered on an empty window before the document is loaded.
Sourcepub fn archive_handler(&mut self, resource: &[u8]) -> Result<(), ()>
pub fn archive_handler(&mut self, resource: &[u8]) -> Result<(), ()>
Register an archive produced by packfolder
tool.
The resources can be accessed via the this://app/
URL.
See documentation of the Archive
.
Sourcepub fn register_behavior<Factory>(&mut self, name: &str, factory: Factory)
pub fn register_behavior<Factory>(&mut self, name: &str, factory: Factory)
Register a native event handler for the specified behavior name.
Behavior is a named event handler which is created for a particular DOM element. In Sciter’s sense, it is a function that is called for different UI events on the DOM element. Essentially it is an analog of the WindowProc in Windows.
In HTML, there is a behavior
CSS property that defines the name of a native module
that is responsible for the initialization and event handling on the element.
For example, by defining div { behavior:button; }
you are asking all <div>
elements in your markup
to behave as buttons: generate BUTTON_CLICK
DOM events when the user clicks on that element, and be focusable.
When the engine discovers an element having behavior: xyz;
defined in its style,
it sends the SC_ATTACH_BEHAVIOR
host notification
with the name "xyz"
and an element handle to the application.
You can consume the notification and respond to it yourself,
or the default handler walks through the list of registered behavior factories
and creates an instance of the corresponding dom::EventHandler
.
§Example:
struct Button;
impl sciter::EventHandler for Button {}
let mut frame = sciter::Window::new();
// register a factory method that creates a new event handler
// for each element that has "custom-button" behavior:
frame.register_behavior("custom-button", || { Box::new(Button) });
And in HTML it can be used as:
<button style="behavior: custom-button">Rusty button</button>
Sourcepub fn load_file(&mut self, uri: &str) -> bool
pub fn load_file(&mut self, uri: &str) -> bool
Load an HTML document from file.
The specified uri
should be either an absolute file path
or a full URL to the HTML to load.
Supported URL schemes are: http://
, file://
; this://app/
(when used with archive_handler
).
ZIP archives are also supported.
Sourcepub fn load_html(&mut self, html: &[u8], uri: Option<&str>) -> bool
pub fn load_html(&mut self, html: &[u8], uri: Option<&str>) -> bool
Load an HTML document from memory.
For example, HTML can be loaded from a file in compile time
via include_bytes!
.
Sourcepub fn set_options(&self, options: Options) -> Result<(), ()>
pub fn set_options(&self, options: Options) -> Result<(), ()>
Set various Sciter engine options, see the Options
.
Sourcepub fn set_variable(&self, path: &str, value: Value) -> Result<()>
pub fn set_variable(&self, path: &str, value: Value) -> Result<()>
Set a global variable by its path to a single window.
This variable will be accessible in the current window via globalThis[path]
or just path
.
Note that the document doesn’t have to be loaded yet at this point.
See also sciter::set_variable
to assign a global to all windows.
Sourcepub fn get_variable(&self, path: &str) -> Result<Value>
pub fn get_variable(&self, path: &str) -> Result<Value>
Get a global variable by its path.
It can be a variable previously assigned by sciter::set_variable
or Window::set_variable
,
or a Sciter.JS variable,
like document
, location
, console
, etc.