Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-mueller committed Nov 1, 2020
1 parent b88db2c commit 9eaa084
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
14 changes: 6 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,26 @@ extern crate serial_test;
#[doc(hidden)]
pub(crate) mod pugl;

#[macro_use]
#[doc(hidden)]
#[macro_use]
pub mod types;

#[doc(inline)]
pub use types::*;

#[doc(hidden)]
pub use types::*;

#[doc(hidden)]
#[cfg(not(feature= "testing"))]
#[cfg(not(feature="testing"))]
pub mod view;

#[doc(inline)]
#[cfg(not(feature= "testing"))]
#[cfg(not(feature="testing"))]
pub use view::*;


#[doc(hidden)]
#[cfg(feature= "testing")]
#[cfg(feature="testing")]
pub mod view_test;

#[doc(inline)]
#[cfg(feature= "testing")]
#[cfg(feature="testing")]
pub use view_test::*;
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ impl From<p::PuglStatus> for Status {
}
}

/// Used to communicate bool hints between the application and the view
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ViewHintBool {
True,
Expand Down Expand Up @@ -608,6 +609,7 @@ impl From<ViewHintBool> for p::PuglViewHintValue {
}
}

/// Used to communicate unsigned ints bettween the application and the view
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ViewHintInt {
Value(u32),
Expand Down
41 changes: 27 additions & 14 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ pub trait PuglViewTrait {
unsafe { Status::from(p::puglSetAspectRatio(self.view(), min_x, min_y, max_x, max_y)) }
}

/// Returns true iff the window is resizable
fn is_resizable(&self) -> bool {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_RESIZABLE) != 0
}
}

/// Make the view resizable.
///
/// This should be called before [[`show_window()`](#method.show_window)](#method.show_window) and [`realize()`](#method.realize).
Expand All @@ -175,14 +182,16 @@ pub trait PuglViewTrait {
}
}

fn is_resizable(&self) -> bool {
/// Returns a [`ViewHintBool`](enum.ViewHintBool.html) whether the view is ignoring
/// key repeats.
fn is_ignoring_key_repeats(&self) -> ViewHintBool {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_RESIZABLE) != 0
ViewHintBool::from(p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_IGNORE_KEY_REPEAT))
}
}

/// Gives the view the hint whether it should ignore key repeats.
fn set_ignore_key_repeats(&self, value: ViewHintBool) -> Status {
dbg!(value);
unsafe {
Status::from(p::puglSetViewHint(
self.view(),
Expand All @@ -191,60 +200,63 @@ pub trait PuglViewTrait {
}
}

fn is_ignoring_key_repeats(&self) -> ViewHintBool {
unsafe {
ViewHintBool::from(p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_IGNORE_KEY_REPEAT))
}
}

/// Returns the number of bits for the red channel of the view
fn red_bits(&self) -> u32 {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_RED_BITS) as u32
}
}

/// Returns the number of bits for the green channel of the view
fn green_bits(&self) -> u32 {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_GREEN_BITS) as u32
}
}

fn alpha_bits(&self) -> u32 {
/// Returns the number of bits for the blue channel of the view
fn blue_bits(&self) -> u32 {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_ALPHA_BITS) as u32
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_BLUE_BITS) as u32
}
}

fn blue_bits(&self) -> u32 {
/// Returns the number of bits for the alpha channel of the view
fn alpha_bits(&self) -> u32 {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_BLUE_BITS) as u32
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_ALPHA_BITS) as u32
}
}

/// Returns the number of bits for the depth buffer of the view
fn depth_bits(&self) -> u32 {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_DEPTH_BITS) as u32
}
}

/// Returns the number of bits for the stencil buffer of the view
fn stencil_bits(&self) -> u32 {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_STENCIL_BITS) as u32
}
}

/// Returns the number of samples per pixel
fn samples(&self) -> u32 {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_SAMPLES) as u32
}
}

/// Returns true iff double buffering should be used
fn double_buffer(&self) -> bool {
unsafe {
p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_DOUBLE_BUFFER) == 1
}
}

/// Sets whether double buffering should be used
fn set_double_buffer(&self, yn: bool) -> Status {
let v = if yn {
1
Expand All @@ -256,12 +268,14 @@ pub trait PuglViewTrait {
}
}

/// Returns number of frames between buffer swaps
fn swap_interval(&self) -> ViewHintInt {
unsafe {
ViewHintInt::from(p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_SWAP_INTERVAL))
}
}

/// Returns the refresh rate in Hz
fn refresh_rate(&self) -> ViewHintInt {
unsafe {
ViewHintInt::from(p::puglGetViewHint(self.view(), p::PuglViewHint_PUGL_REFRESH_RATE))
Expand Down Expand Up @@ -533,7 +547,6 @@ impl<T: PuglViewTrait> Drop for PuglView<T> {
#[cfg(test)]
mod test {
use super::*;
use crate::types::*;

struct UI {
view: PuglViewFFI
Expand Down

0 comments on commit 9eaa084

Please sign in to comment.