Skip to content

Commit 7ed5adb

Browse files
authored
Fix inconsistencies in documentation/attributes/function inclusion (#177)
* Apply documentation to audio methods * Make getter methods const * Apply documentation to automation methods * Apply documentation to `camera.rs` * Apply documentation to `color.rs` * Add color palette impls * Fix documentation comment * Apply documentation to `drawing.rs * Fix inconsistent name pattern * Fix documentation and inline inconsistencies in `file.rs` * Add missing inlines in `input.rs` * Improve consistency within `math.rs` * Add missing documentation to `models.rs` * Improve API consistency in `shaders.rs` * Add missing documentation to `text.rs` * Add optional attributes to `make_thin_wrapper!` * Add documentation to `texture.rs` * Add missing docs to `vr.rs` * Add missing documentation to `window.rs` * Confirm all public functions from Raylib API are documented * Add documentation comments to thin wrappers in `audio.rs`
1 parent 927dccd commit 7ed5adb

File tree

16 files changed

+825
-144
lines changed

16 files changed

+825
-144
lines changed

raylib/src/core/audio.rs

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,31 @@ use std::ffi::CString;
66
use std::marker::PhantomData;
77
use std::path::Path;
88

9-
make_thin_wrapper_lifetime!(Wave, ffi::Wave, RaylibAudio, ffi::UnloadWave);
9+
make_thin_wrapper_lifetime!(
10+
/// Wave, audio wave data
11+
Wave,
12+
ffi::Wave,
13+
RaylibAudio,
14+
ffi::UnloadWave
15+
);
1016

11-
make_thin_wrapper_lifetime!(Sound, ffi::Sound, RaylibAudio, (ffi::UnloadSound), true);
12-
make_thin_wrapper_lifetime!(Music, ffi::Music, RaylibAudio, ffi::UnloadMusicStream);
1317
make_thin_wrapper_lifetime!(
18+
/// Sound
19+
Sound,
20+
ffi::Sound,
21+
RaylibAudio,
22+
(ffi::UnloadSound),
23+
true
24+
);
25+
make_thin_wrapper_lifetime!(
26+
/// Music, audio stream, anything longer than ~10 seconds should be streamed
27+
Music,
28+
ffi::Music,
29+
RaylibAudio,
30+
ffi::UnloadMusicStream
31+
);
32+
make_thin_wrapper_lifetime!(
33+
/// AudioStream, custom audio stream
1434
AudioStream,
1535
ffi::AudioStream,
1636
RaylibAudio,
@@ -87,14 +107,14 @@ impl RaylibAudio {
87107
pub fn set_master_volume(&self, volume: f32) {
88108
unsafe { ffi::SetMasterVolume(volume) }
89109
}
90-
110+
91111
/// Sets default audio buffer size for new audio streams.
92112
#[inline]
93113
pub fn set_audio_stream_buffer_size_default(&self, size: i32) {
94114
unsafe {
95115
ffi::SetAudioStreamBufferSizeDefault(size);
96116
}
97-
}
117+
}
98118

99119
/// Loads a new sound from file.
100120
#[inline]
@@ -199,16 +219,24 @@ impl<'aud> Drop for RaylibAudio {
199219
}
200220

201221
impl<'aud> Wave<'aud> {
202-
pub fn frame_count(&self) -> u32 {
222+
/// Total number of frames (considering channels)
223+
#[inline]
224+
pub const fn frame_count(&self) -> u32 {
203225
self.0.frameCount
204226
}
205-
pub fn sample_rate(&self) -> u32 {
227+
/// Frequency (samples per second)
228+
#[inline]
229+
pub const fn sample_rate(&self) -> u32 {
206230
self.0.sampleRate
207231
}
208-
pub fn sample_size(&self) -> u32 {
232+
/// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
233+
#[inline]
234+
pub const fn sample_size(&self) -> u32 {
209235
self.0.sampleSize
210236
}
211-
pub fn channels(&self) -> u32 {
237+
/// Number of channels (1-mono, 2-stereo, ...)
238+
#[inline]
239+
pub const fn channels(&self) -> u32 {
212240
self.0.channels
213241
}
214242
pub unsafe fn inner(self) -> ffi::Wave {
@@ -217,6 +245,7 @@ impl<'aud> Wave<'aud> {
217245
inner
218246
}
219247

248+
/// Checks if wave data is valid (data loaded and parameters)
220249
#[inline]
221250
pub fn is_wave_valid(&self) -> bool {
222251
unsafe { ffi::IsWaveValid(self.0) }
@@ -229,8 +258,8 @@ impl<'aud> Wave<'aud> {
229258
unsafe { ffi::ExportWave(self.0, c_filename.as_ptr()) }
230259
}
231260

232-
/// Export wave sample data to code (.h)
233-
/*#[inline]
261+
/*/// Export wave sample data to code (.h)
262+
#[inline]
234263
pub fn export_wave_as_code(&self, filename: &str) -> bool {
235264
let c_filename = CString::new(filename).unwrap();
236265
unsafe { ffi::ExportWaveAsCode(self.0, c_filename.as_ptr()) }
@@ -279,11 +308,15 @@ impl<'aud> AsMut<ffi::AudioStream> for Sound<'aud> {
279308
}
280309

281310
impl<'aud> Sound<'aud> {
311+
/// Checks if a sound is valid (data loaded and buffers initialized)
312+
#[inline]
282313
pub fn is_sound_valid(&self) -> bool {
283314
unsafe { ffi::IsSoundValid(self.0) }
284315
}
285316

286-
pub fn frame_count(&self) -> u32 {
317+
/// Total number of frames (considering channels)
318+
#[inline]
319+
pub const fn frame_count(&self) -> u32 {
287320
self.0.frameCount
288321
}
289322
pub unsafe fn inner(self) -> ffi::Sound {
@@ -334,6 +367,7 @@ impl<'aud> Sound<'aud> {
334367
unsafe { ffi::SetSoundPitch(self.0, pitch) }
335368
}
336369

370+
/// Set pan for a sound (0.5 is center)
337371
#[inline]
338372
pub fn set_pan(&self, pan: f32) {
339373
unsafe { ffi::SetSoundPan(self.0, pan) }
@@ -354,11 +388,15 @@ impl<'aud> Sound<'aud> {
354388
}
355389

356390
impl<'aud, 'bind> SoundAlias<'aud, 'bind> {
391+
/// Checks if a sound is valid (data loaded and buffers initialized)
392+
#[inline]
357393
pub fn is_sound_valid(&self) -> bool {
358394
unsafe { ffi::IsSoundValid(self.0) }
359395
}
360396

361-
pub fn frame_count(&self) -> u32 {
397+
/// Total number of frames (considering channels)
398+
#[inline]
399+
pub const fn frame_count(&self) -> u32 {
362400
self.0.frameCount
363401
}
364402
pub unsafe fn inner(self) -> ffi::Sound {
@@ -409,6 +447,7 @@ impl<'aud, 'bind> SoundAlias<'aud, 'bind> {
409447
unsafe { ffi::SetSoundPitch(self.0, pitch) }
410448
}
411449

450+
/// Set pan for a sound (0.5 is center)
412451
#[inline]
413452
pub fn set_pan(&self, pan: f32) {
414453
unsafe { ffi::SetSoundPan(self.0, pan) }
@@ -482,33 +521,44 @@ impl<'aud> Music<'aud> {
482521
unsafe { ffi::GetMusicTimePlayed(self.0) }
483522
}
484523

524+
/// Seek music to a position (in seconds)
485525
#[inline]
486526
pub fn seek_stream(&self, position: f32) {
487527
unsafe { ffi::SeekMusicStream(self.0, position) }
488528
}
489529

530+
/// Set pan for a music (0.5 is center)
490531
#[inline]
491532
pub fn set_pan(&self, pan: f32) {
492533
unsafe { ffi::SetMusicPan(self.0, pan) }
493534
}
494535

536+
/// Checks if a music stream is valid (context and buffers initialized)
495537
#[inline]
496538
pub fn is_music_valid(&self) -> bool {
497539
unsafe { ffi::IsMusicValid(self.0) }
498540
}
499541
}
500542

501543
impl<'aud> AudioStream<'aud> {
544+
/// Checks if an audio stream is valid (buffers initialized)
545+
#[inline]
502546
pub fn is_audio_stream_valid(&self) -> bool {
503547
unsafe { ffi::IsAudioStreamValid(self.0) }
504548
}
505-
pub fn sample_rate(&self) -> u32 {
549+
/// Frequency (samples per second)
550+
#[inline]
551+
pub const fn sample_rate(&self) -> u32 {
506552
self.0.sampleRate
507553
}
508-
pub fn sample_size(&self) -> u32 {
554+
/// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
555+
#[inline]
556+
pub const fn sample_size(&self) -> u32 {
509557
self.0.sampleSize
510558
}
511-
pub fn channels(&self) -> u32 {
559+
/// Number of channels (1-mono, 2-stereo, ...)
560+
#[inline]
561+
pub const fn channels(&self) -> u32 {
512562
self.0.channels
513563
}
514564

@@ -590,6 +640,8 @@ impl<'aud> AudioStream<'aud> {
590640
unsafe { ffi::IsAudioStreamProcessed(self.0) }
591641
}
592642

643+
/// Set pan for audio stream (0.5 is centered)
644+
#[inline]
593645
pub fn set_pan(&self, pan: f32) {
594646
unsafe {
595647
ffi::SetAudioStreamPan(self.0, pan);
@@ -598,6 +650,8 @@ impl<'aud> AudioStream<'aud> {
598650
}
599651

600652
impl<'bind> Sound<'_> {
653+
/// Clone sound from existing sound data, clone does not own wave data
654+
// NOTE: Wave data must be unallocated manually and will be shared across all clones
601655
pub fn alias<'snd>(&'snd self) -> Result<SoundAlias<'bind, 'snd>, Error> {
602656
let s = unsafe { ffi::LoadSoundAlias(self.0) };
603657
if s.stream.buffer.is_null() {

raylib/src/core/automation.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ make_thin_wrapper!(
7373

7474
impl AutomationEventList {
7575
/// Length of the automation event list
76+
#[inline]
7677
pub const fn count(&self) -> u32 {
7778
self.0.count
7879
}
7980
/// The amount of automation events that can be held in this list.
81+
#[inline]
8082
pub const fn capacity(&self) -> u32 {
8183
self.0.capacity
8284
}
@@ -108,18 +110,26 @@ make_thin_wrapper!(
108110
);
109111

110112
impl AutomationEvent {
113+
/// Event frame
114+
#[inline]
111115
pub const fn frame(&self) -> u32 {
112116
self.0.frame
113117
}
118+
/// Event type (AutomationEventType)
119+
#[inline]
114120
pub const fn get_type(&self) -> u32 {
115121
self.0.type_
116122
}
123+
/// Event parameters (if required)
124+
#[inline]
117125
pub const fn params(&self) -> [i32; 4] {
118126
self.0.params
119127
}
120128
}
121129

122130
impl AutomationEvent {
131+
/// Play a recorded automation event
132+
#[inline]
123133
pub fn play(&self) {
124134
unsafe { ffi::PlayAutomationEvent(self.0) }
125135
}
@@ -130,6 +140,7 @@ fn unload_automation_event(_s: ffi::AutomationEvent) {
130140
}
131141

132142
impl RaylibHandle {
143+
/// Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS
133144
pub fn load_automation_event_list(&self, file_name: Option<PathBuf>) -> AutomationEventList {
134145
match file_name {
135146
Some(a) => {
@@ -139,17 +150,25 @@ impl RaylibHandle {
139150
None => AutomationEventList(unsafe { ffi::LoadAutomationEventList(null()) }),
140151
}
141152
}
153+
/// Set automation event list to record to
154+
#[inline]
142155
pub fn set_automation_event_list(&self, l: &mut AutomationEventList) {
143156
unsafe {
144157
ffi::SetAutomationEventList(&mut l.0 as *mut ffi::AutomationEventList);
145158
}
146159
}
160+
/// Set automation event internal base frame to start recording
161+
#[inline]
147162
pub fn set_automation_event_base_frame(&self, b: i32) {
148163
unsafe { ffi::SetAutomationEventBaseFrame(b) };
149164
}
165+
/// Start recording automation events (AutomationEventList must be set)
166+
#[inline]
150167
pub fn start_automation_event_recording(&self) {
151168
unsafe { ffi::StartAutomationEventRecording() };
152169
}
170+
/// Stop recording automation events
171+
#[inline]
153172
pub fn stop_automation_event_recording(&self) {
154173
unsafe { ffi::StopAutomationEventRecording() };
155174
}

raylib/src/core/camera.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ use crate::core::math::{Vector2, Vector3};
55
use crate::core::RaylibHandle;
66
use crate::ffi;
77

8+
/// Camera, defines position/orientation in 3d space
89
#[repr(C)]
910
#[derive(Debug, Copy, Clone)]
1011
pub struct Camera3D {
12+
/// Camera position
1113
pub position: Vector3,
14+
/// Camera target it looks-at
1215
pub target: Vector3,
16+
/// Camera up vector (rotation over its axis)
1317
pub up: Vector3,
18+
/// Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic
1419
pub fovy: f32,
20+
/// Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
1521
projection_: ffi::CameraProjection,
1622
}
23+
/// Camera type fallback, defaults to Camera3D
1724
pub type Camera = Camera3D;
1825

1926
impl From<ffi::Camera3D> for Camera3D {
@@ -40,12 +47,17 @@ impl Into<ffi::Camera3D> for &Camera3D {
4047
}
4148
}
4249

50+
/// Camera2D, defines position/orientation in 2d space
4351
#[repr(C)]
4452
#[derive(Debug, Copy, Clone, Default)]
4553
pub struct Camera2D {
54+
/// Camera offset (displacement from target)
4655
pub offset: Vector2,
56+
/// Camera target (rotation and zoom origin)
4757
pub target: Vector2,
58+
/// Camera rotation in degrees
4859
pub rotation: f32,
60+
/// Camera zoom (scaling), should be 1.0 by default
4961
pub zoom: f32,
5062
}
5163

@@ -73,8 +85,9 @@ impl Into<ffi::Camera2D> for &Camera2D {
7385
}
7486

7587
impl Camera3D {
76-
pub fn camera_type(&self) -> crate::consts::CameraProjection {
77-
unsafe { std::mem::transmute(self.projection_.clone()) }
88+
/// Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
89+
pub const fn camera_type(&self) -> crate::consts::CameraProjection {
90+
unsafe { std::mem::transmute_copy(&self.projection_) }
7891
}
7992
/// Create a perspective camera.
8093
/// fovy is in degrees
@@ -106,7 +119,8 @@ impl RaylibHandle {
106119
*camera = fficam.into();
107120
}
108121
}
109-
122+
123+
/// Update camera movement/rotation
110124
pub fn update_camera_pro(&self, camera: &mut Camera3D, movement: Vector3, rotation: Vector3, zoom: f32) {
111125
unsafe {
112126
let mut fficam: ffi::Camera3D = (*camera).into();

0 commit comments

Comments
 (0)