You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Trac3r-rust/doc/winit/index.html

103 lines
16 KiB

5 years ago
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `winit` crate."><meta name="keywords" content="rust, rustlang, rust-lang, winit"><title>winit - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../winit/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Crate winit</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all winit's items</p></a><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#types">Type Definitions</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'winit', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/winit/lib.rs.html#1-542' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>winit</a></span></h1><div class='docblock'><p>Winit allows you to build a window on as many platforms as possible.</p>
<h1 id="building-a-window" class="section-header"><a href="#building-a-window">Building a window</a></h1>
<p>Before you can build a window, you first need to build an <code>EventsLoop</code>. This is done with the
<code>EventsLoop::new()</code> function. Example:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">winit</span>::<span class="ident">EventsLoop</span>;
<span class="kw">let</span> <span class="ident">events_loop</span> <span class="op">=</span> <span class="ident">EventsLoop</span>::<span class="ident">new</span>();</pre></div>
<p>Once this is done there are two ways to create a window:</p>
<ul>
<li>Calling <code>Window::new(&amp;events_loop)</code>.</li>
<li>Calling <code>let builder = WindowBuilder::new()</code> then <code>builder.build(&amp;events_loop)</code>.</li>
</ul>
<p>The first way is the simplest way and will give you default values for everything.</p>
<p>The second way allows you to customize the way your window will look and behave by modifying
the fields of the <code>WindowBuilder</code> object before you create the window.</p>
<h1 id="events-handling" class="section-header"><a href="#events-handling">Events handling</a></h1>
<p>Once a window has been created, it will <em>generate events</em>. For example whenever the user moves
the window, resizes the window, moves the mouse, etc. an event is generated.</p>
<p>The events generated by a window can be retrieved from the <code>EventsLoop</code> the window was created
with.</p>
<p>There are two ways to do so. The first is to call <code>events_loop.poll_events(...)</code>, which will
retrieve all the events pending on the windows and immediately return after no new event is
available. You usually want to use this method in application that render continuously on the
screen, such as video games.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">winit</span>::{<span class="ident">Event</span>, <span class="ident">WindowEvent</span>};
<span class="kw">use</span> <span class="ident">winit</span>::<span class="ident">dpi</span>::<span class="ident">LogicalSize</span>;
<span class="kw">loop</span> {
<span class="ident">events_loop</span>.<span class="ident">poll_events</span>(<span class="op">|</span><span class="ident">event</span><span class="op">|</span> {
<span class="kw">match</span> <span class="ident">event</span> {
<span class="ident">Event</span>::<span class="ident">WindowEvent</span> {
<span class="ident">event</span>: <span class="ident">WindowEvent</span>::<span class="ident">Resized</span>(<span class="ident">LogicalSize</span> { <span class="ident">width</span>, <span class="ident">height</span> }),
..
} <span class="op">=</span><span class="op">&gt;</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;The window was resized to {}x{}&quot;</span>, <span class="ident">width</span>, <span class="ident">height</span>);
},
<span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> ()
}
});
}</pre></div>
<p>The second way is to call <code>events_loop.run_forever(...)</code>. As its name tells, it will run
forever unless it is stopped by returning <code>ControlFlow::Break</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">winit</span>::{<span class="ident">ControlFlow</span>, <span class="ident">Event</span>, <span class="ident">WindowEvent</span>};
<span class="ident">events_loop</span>.<span class="ident">run_forever</span>(<span class="op">|</span><span class="ident">event</span><span class="op">|</span> {
<span class="kw">match</span> <span class="ident">event</span> {
<span class="ident">Event</span>::<span class="ident">WindowEvent</span> { <span class="ident">event</span>: <span class="ident">WindowEvent</span>::<span class="ident">CloseRequested</span>, .. } <span class="op">=</span><span class="op">&gt;</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;The close button was pressed; stopping&quot;</span>);
<span class="ident">ControlFlow</span>::<span class="ident">Break</span>
},
<span class="kw">_</span> <span class="op">=</span><span class="op">&gt;</span> <span class="ident">ControlFlow</span>::<span class="ident">Continue</span>,
}
});</pre></div>
<p>If you use multiple windows, the <code>WindowEvent</code> event has a member named <code>window_id</code>. You can
compare it with the value returned by the <code>id()</code> method of <code>Window</code> in order to know which
window has received the event.</p>
<h1 id="drawing-on-the-window" class="section-header"><a href="#drawing-on-the-window">Drawing on the window</a></h1>
<p>Winit doesn't provide any function that allows drawing on a window. However it allows you to
retrieve the raw handle of the window (see the <code>os</code> module for that), which in turn allows you
to create an OpenGL/Vulkan/DirectX/Metal/etc. context that will draw on the window.</p>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table><tr class='module-item'><td><a class="mod" href="dpi/index.html" title='winit::dpi mod'>dpi</a></td><td class='docblock-short'><p>DPI is important, so read the docs for this module if you don't want to be confused.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="os/index.html" title='winit::os mod'>os</a></td><td class='docblock-short'><p>Contains traits with platform-specific methods in them.</p>
</td></tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.AvailableMonitorsIter.html" title='winit::AvailableMonitorsIter struct'>AvailableMonitorsIter</a></td><td class='docblock-short'><p>An iterator for the list of available monitors.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.DeviceId.html" title='winit::DeviceId struct'>DeviceId</a></td><td class='docblock-short'><p>Identifier of an input device.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.EventsLoop.html" title='winit::EventsLoop struct'>EventsLoop</a></td><td class='docblock-short'><p>Provides a way to retrieve events from the system and from the windows that were registered to
the events loop.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.EventsLoopClosed.html" title='winit::EventsLoopClosed struct'>EventsLoopClosed</a></td><td class='docblock-short'><p>The error that is returned when an <code>EventsLoopProxy</code> attempts to wake up an <code>EventsLoop</code> that
no longer exists.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.EventsLoopProxy.html" title='winit::EventsLoopProxy struct'>EventsLoopProxy</a></td><td class='docblock-short'><p>Used to wake up the <code>EventsLoop</code> from another thread.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Icon.html" title='winit::Icon struct'>Icon</a></td><td class='docblock-short'><p>An icon used for the window titlebar, taskbar, etc.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.KeyboardInput.html" title='winit::KeyboardInput struct'>KeyboardInput</a></td><td class='docblock-short'><p>Describes a keyboard input event.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.ModifiersState.html" title='winit::ModifiersState struct'>ModifiersState</a></td><td class='docblock-short'><p>Represents the current state of the keyboard modifiers</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.MonitorId.html" title='winit::MonitorId struct'>MonitorId</a></td><td class='docblock-short'><p>Identifier for a monitor.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Touch.html" title='winit::Touch struct'>Touch</a></td><td class='docblock-short'><p>Represents touch event</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Window.html" title='winit::Window struct'>Window</a></td><td class='docblock-short'><p>Represents a window.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.WindowAttributes.html" title='winit::WindowAttributes struct'>WindowAttributes</a></td><td class='docblock-short'><p>Attributes to use when creating a window.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.WindowBuilder.html" title='winit::WindowBuilder struct'>WindowBuilder</a></td><td class='docblock-short'><p>Object that allows you to build windows.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.WindowId.html" title='winit::WindowId struct'>WindowId</a></td><td class='docblock-short'><p>Identifier of a window. Unique for each window.</p>
</td></tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table><tr class='module-item'><td><a class="enum" href="enum.BadIcon.html" title='winit::BadIcon enum'>BadIcon</a></td><td class='docblock-short'><p>An error produced when using <code>Icon::from_rgba</code> with invalid arguments.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.ControlFlow.html" title='winit::ControlFlow enum'>ControlFlow</a></td><td class='docblock-short'><p>Returned by the user callback given to the <code>EventsLoop::run_forever</code> method.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.CreationError.html" title='winit::CreationError enum'>CreationError</a></td><td class='docblock-short'><p>Error that can happen while creating a window or a headless renderer.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.DeviceEvent.html" title='winit::DeviceEvent enum'>DeviceEvent</a></td><td class='docblock-short'><p>Represents raw hardware events that are not associated with any particular window.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.ElementState.html" title='winit::ElementState enum'>ElementState</a></td><td class='docblock-short'><p>Describes the input state of a key.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.Event.html" title='winit::Event enum'>Event</a></td><td class='docblock-short'><p>Describes a generic event.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.MouseButton.html" title='winit::MouseButton enum'>MouseButton</a></td><td class='docblock-short'><p>Describes a button of a mouse controller.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.MouseCursor.html" title='winit::MouseCursor enum'>MouseCursor</a></td><td class='docblock-short'><p>Describes the appearance of the mouse cursor.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.MouseScrollDelta.html" title='winit::MouseScrollDelta enum'>MouseScrollDelta</a></td><td class='docblock-short'><p>Describes a difference in the mouse scroll wheel state.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.TouchPhase.html" title='winit::TouchPhase enum'>TouchPhase</a></td><td class='docblock-short'><p>Describes touch-screen input state.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.VirtualKeyCode.html" title='winit::VirtualKeyCode enum'>VirtualKeyCode</a></td><td class='docblock-short'><p>Symbolic name for a keyboard key.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.WindowEvent.html" title='winit::WindowEvent enum'>WindowEvent</a></td><td class='docblock-short'><p>Describes an event from a <code>Window</code>.</p>
</td></tr></table><h2 id='types' class='section-header'><a href="#types">Type Definitions</a></h2>
<table><tr class='module-item'><td><a class="type" href="type.AxisId.html" title='winit::AxisId type'>AxisId</a></td><td class='docblock-short'><p>Identifier for a specific analog axis on some device.</p>
</td></tr><tr class='module-item'><td><a class="type" href="type.ButtonId.html" title='winit::ButtonId type'>ButtonId</a></td><td class='docblock-short'><p>Identifier for a specific button on some device.</p>
</td></tr><tr class='module-item'><td><a class="type" href="type.ScanCode.html" title='winit::ScanCode type'>ScanCode</a></td><td class='docblock-short'><p>Hardware-dependent keyboard scan code.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "winit";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>