mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 19:31:30 +11:00
Improvement in doc and doc tests (#86)
* Fixed a few mistakes in docs * Convert `ignore` examples to `no_run` examples, so `cargo test` will make sure they compiles.
This commit is contained in:
parent
b8d4ad098f
commit
c56ea6dae9
110
src/lib.rs
110
src/lib.rs
|
@ -159,7 +159,8 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// Open up a window with default settings
|
/// Open up a window with default settings
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
/// let mut window = match Window::new("Test", 640, 400, WindowOptions::default()) {
|
/// let mut window = match Window::new("Test", 640, 400, WindowOptions::default()) {
|
||||||
/// Ok(win) => win,
|
/// Ok(win) => win,
|
||||||
/// Err(err) => {
|
/// Err(err) => {
|
||||||
|
@ -171,7 +172,8 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// Open up a window that is resizeable
|
/// Open up a window that is resizeable
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
/// let mut window = match Window::new("Test", 640, 400,
|
/// let mut window = match Window::new("Test", 640, 400,
|
||||||
/// WindowOptions {
|
/// WindowOptions {
|
||||||
/// resize: true,
|
/// resize: true,
|
||||||
|
@ -193,8 +195,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
/// let mut window = match Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
/// # use minifb::*;
|
||||||
|
/// let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
///
|
///
|
||||||
/// window.set_title("My New Title!");
|
/// window.set_title("My New Title!");
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -207,7 +210,7 @@ impl Window {
|
||||||
/// Returns the native handle for a window which is an opaque pointer/handle which
|
/// Returns the native handle for a window which is an opaque pointer/handle which
|
||||||
/// dependens on the current operating system:
|
/// dependens on the current operating system:
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```text
|
||||||
/// Windows HWND
|
/// Windows HWND
|
||||||
/// MacOS NSWindow
|
/// MacOS NSWindow
|
||||||
/// X11 XWindow
|
/// X11 XWindow
|
||||||
|
@ -224,10 +227,11 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
/// let mut buffer: Vec<u32> = vec![0; 640 * 400];
|
/// let mut buffer: Vec<u32> = vec![0; 640 * 400];
|
||||||
///
|
///
|
||||||
/// let mut window = match Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
/// let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
///
|
///
|
||||||
/// window.update_with_buffer(&buffer).unwrap();
|
/// window.update_with_buffer(&buffer).unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -241,10 +245,11 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
/// let mut buffer: Vec<u32> = vec![0; 640 * 400];
|
/// let mut buffer: Vec<u32> = vec![0; 640 * 400];
|
||||||
///
|
///
|
||||||
/// let mut window = match Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
/// let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
///
|
///
|
||||||
/// window.update();
|
/// window.update();
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -260,9 +265,11 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// while window.is_open() {
|
/// while window.is_open() {
|
||||||
/// window.update(...)
|
/// // Update window
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -276,7 +283,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// // Moves the window to pixel position 20, 20 on the screen
|
/// // Moves the window to pixel position 20, 20 on the screen
|
||||||
/// window.set_position(20, 20);
|
/// window.set_position(20, 20);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -291,7 +300,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// let size = window.get_size();
|
/// let size = window.get_size();
|
||||||
/// println!("width {} height {}", size.0, size.1);
|
/// println!("width {} height {}", size.0, size.1);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -307,7 +318,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_mouse_pos(MouseMode::Clamp).map(|mouse| {
|
/// window.get_mouse_pos(MouseMode::Clamp).map(|mouse| {
|
||||||
/// println!("x {} y {}", mouse.0, mouse.1);
|
/// println!("x {} y {}", mouse.0, mouse.1);
|
||||||
/// });
|
/// });
|
||||||
|
@ -325,7 +338,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_unscaled_mouse_pos(MouseMode::Clamp).map(|mouse| {
|
/// window.get_unscaled_mouse_pos(MouseMode::Clamp).map(|mouse| {
|
||||||
/// println!("x {} y {}", mouse.0, mouse.1);
|
/// println!("x {} y {}", mouse.0, mouse.1);
|
||||||
/// });
|
/// });
|
||||||
|
@ -341,7 +356,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// let left_down = window.get_mouse_down(MouseButton::Left);
|
/// let left_down = window.get_mouse_down(MouseButton::Left);
|
||||||
/// println!("is left down? {}", left_down)
|
/// println!("is left down? {}", left_down)
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -360,7 +377,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_scroll_wheel().map(|scroll| {
|
/// window.get_scroll_wheel().map(|scroll| {
|
||||||
/// println!("scrolling - x {} y {}", scroll.0, scroll.1);
|
/// println!("scrolling - x {} y {}", scroll.0, scroll.1);
|
||||||
/// });
|
/// });
|
||||||
|
@ -378,7 +397,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.set_cursor_style(CursorStyle::ResizeLeftRight);
|
/// window.set_cursor_style(CursorStyle::ResizeLeftRight);
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -391,7 +412,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_keys().map(|keys| {
|
/// window.get_keys().map(|keys| {
|
||||||
/// for t in keys {
|
/// for t in keys {
|
||||||
/// match t {
|
/// match t {
|
||||||
|
@ -413,7 +436,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.get_keys_pressed(KeyRepeat::No).map(|keys| {
|
/// window.get_keys_pressed(KeyRepeat::No).map(|keys| {
|
||||||
/// for t in keys {
|
/// for t in keys {
|
||||||
/// match t {
|
/// match t {
|
||||||
|
@ -434,7 +459,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// if window.is_key_down(Key::A) {
|
/// if window.is_key_down(Key::A) {
|
||||||
/// println!("Key A is down");
|
/// println!("Key A is down");
|
||||||
/// }
|
/// }
|
||||||
|
@ -451,8 +478,10 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
/// if window.is_key_pressed(KeyRepeat::No) {
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
|
/// if window.is_key_pressed(Key::A, KeyRepeat::No) {
|
||||||
/// println!("Key A is down");
|
/// println!("Key A is down");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -476,7 +505,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.set_key_repeat_delay(0.5) // 0.5 sec before repeat starts
|
/// window.set_key_repeat_delay(0.5) // 0.5 sec before repeat starts
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -491,7 +522,9 @@ impl Window {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut window = Window::new("Test", 640, 400, WindowOptions::default()).unwrap();
|
||||||
/// window.set_key_repeat_rate(0.01) // 0.01 sec between keys
|
/// window.set_key_repeat_rate(0.01) // 0.01 sec between keys
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -520,7 +553,7 @@ impl Window {
|
||||||
/// This allows adding menus to your windows. As menus behaves a bit diffrently depending on
|
/// This allows adding menus to your windows. As menus behaves a bit diffrently depending on
|
||||||
/// Operating system here is how it works.
|
/// Operating system here is how it works.
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```text
|
||||||
/// Windows:
|
/// Windows:
|
||||||
/// Each window has their own menu and shortcuts are active depending on active window.
|
/// Each window has their own menu and shortcuts are active depending on active window.
|
||||||
/// Mac:
|
/// Mac:
|
||||||
|
@ -680,8 +713,11 @@ impl Menu {
|
||||||
/// Adds an item to the menu. Notice that you need to call "build" to finish the add
|
/// Adds an item to the menu. Notice that you need to call "build" to finish the add
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut menu = Menu::new("test").unwrap();
|
||||||
/// menu.add_item("test", 1).shortcut(Key::A, 0).build()
|
/// menu.add_item("test", 1).shortcut(Key::A, 0).build()
|
||||||
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn add_item(&mut self, name: &str, id: usize) -> MenuItem {
|
pub fn add_item(&mut self, name: &str, id: usize) -> MenuItem {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
@ -753,8 +789,11 @@ impl<'a> MenuItem<'a> {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut menu = Menu::new("test").unwrap();
|
||||||
/// menu.add_item("test", 1).shortcut(Key::A, 0).build()
|
/// menu.add_item("test", 1).shortcut(Key::A, 0).build()
|
||||||
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn shortcut(self, key: Key, modifier: usize) -> Self {
|
pub fn shortcut(self, key: Key, modifier: usize) -> Self {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
@ -768,8 +807,11 @@ impl<'a> MenuItem<'a> {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut menu = Menu::new("test").unwrap();
|
||||||
/// menu.add_item("", 0).separator().build()
|
/// menu.add_item("", 0).separator().build()
|
||||||
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
/// Notice that it's usually easier to just call ```menu.add_separator()``` directly
|
/// Notice that it's usually easier to just call ```menu.add_separator()``` directly
|
||||||
pub fn separator(self) -> Self {
|
pub fn separator(self) -> Self {
|
||||||
|
@ -783,8 +825,11 @@ impl<'a> MenuItem<'a> {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut menu = Menu::new("test").unwrap();
|
||||||
/// menu.add_item("test", 1).enabled(false).build()
|
/// menu.add_item("test", 1).enabled(false).build()
|
||||||
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn enabled(self, enabled: bool) -> Self {
|
pub fn enabled(self, enabled: bool) -> Self {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
|
@ -797,8 +842,11 @@ impl<'a> MenuItem<'a> {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
|
/// # use minifb::*;
|
||||||
|
/// # let mut menu = Menu::new("test").unwrap();
|
||||||
/// menu.add_item("test", 1).enabled(false).build()
|
/// menu.add_item("test", 1).enabled(false).build()
|
||||||
|
/// # ;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn build(&mut self) -> MenuItemHandle {
|
pub fn build(&mut self) -> MenuItemHandle {
|
||||||
let t = self.clone();
|
let t = self.clone();
|
||||||
|
|
Loading…
Reference in a new issue