Skip to content

Commit 5cdaae1

Browse files
committed
Added rustdoc to all public items
1 parent 8286c2b commit 5cdaae1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ mod win32;
55

66
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
77

8+
/// An instance of this struct contains the platform-specific data that must be managed in order to
9+
/// write to a window on that platform. This struct owns the window that this data corresponds to
10+
/// to ensure safety, as that data must be destroyed before the window itself is destroyed. You may
11+
/// access the underlying window via [`window`](Self::window) and [`window_mut`](Self::window_mut).
812
pub struct GraphicsContext<W: HasRawWindowHandle>{
913
window: W,
1014
graphics_context_impl: Box<dyn GraphicsContextImpl>
1115
}
1216

1317
impl<W: HasRawWindowHandle> GraphicsContext<W> {
1418

19+
/// Creates a new instance of this struct, consuming the given window.
20+
///
21+
/// # Safety
22+
///
23+
/// - Ensure that the passed object is valid to draw a 2D buffer to
1524
pub unsafe fn new(window: W) -> Self{
1625
let raw_handle = window.raw_window_handle();
1726
let imple = match raw_handle{
@@ -28,16 +37,41 @@ impl<W: HasRawWindowHandle> GraphicsContext<W> {
2837
}
2938
}
3039

40+
/// Gets shared access to the underlying window
3141
#[inline]
3242
pub fn window(&self) -> &W{
3343
&self.window
3444
}
3545

46+
/// Gets mut/exclusive access to the underlying window
3647
#[inline]
3748
pub fn window_mut(&mut self) -> &mut W{
3849
&mut self.window
3950
}
4051

52+
/// Shows the given buffer with the given width and height on the window corresponding to this
53+
/// graphics context. Panics if buffer.len() ≠ width*height. If the size of the buffer does
54+
/// not match the size of the window, the buffer is drawn in the upper-left corner of the window.
55+
/// It is recommended in most production use cases to have the buffer fill the entire window.
56+
/// Use your windowing library to find the size of the window.
57+
///
58+
/// The format of the buffer is as follows. There is one u32 in the buffer for each pixel in
59+
/// the area to draw. The first entry is the upper-left most pixel. The second is one to the right
60+
/// etc. (Row-major top to bottom left to right one u32 per pixel). Within each u32 the highest
61+
/// order 8 bits are to be set to 0. The next highest order 8 bits are the red channel, then the
62+
/// green channel, and then the blue channel in the lowest-order 8 bits. See the examples for
63+
/// one way to build this format using bitwise operations.
64+
///
65+
/// --------
66+
///
67+
/// Pixel format (u32):
68+
///
69+
/// 00000000RRRRRRRRGGGGGGGGBBBBBBBB
70+
///
71+
/// 0: Bit is 0
72+
/// R: Red channel
73+
/// G: Green channel
74+
/// B: Blue channel
4175
#[inline]
4276
pub fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16){
4377
if (width as usize)*(height as usize) != buffer.len(){

0 commit comments

Comments
 (0)