Skip to content

Commit 3c3e1df

Browse files
committed
Docs nitpicks
1 parent 84a7cd2 commit 3c3e1df

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

src/axis.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Axes descriptions of tool capabilities and limits.
2+
13
use crate::util::NicheF32;
24

35
bitflags::bitflags! {
@@ -49,6 +51,7 @@ impl AvailableAxes {
4951
strum::IntoStaticStr,
5052
strum::EnumIter,
5153
)]
54+
/// An individual Tool axis.
5255
pub enum Axis {
5356
/// The tool can sense how much force is applied, purpendicular to the pad surface.
5457
Pressure,
@@ -60,7 +63,7 @@ pub enum Axis {
6063
Roll,
6164
/// The tool has a scroll wheel. It may report continuous motion as well as discrete steps.
6265
Wheel,
63-
/// The tool has an absolute linear slider control, ranging from -1 to 1 with zero being the "natural" position.
66+
/// The tool has an absolute linear slider control, `[-1, 1]` with zero being the "natural" position.
6467
Slider,
6568
/// The tool has a pressure-sensitive button, reporting how hard the user is pressing on it.
6669
ButtonPressure,
@@ -101,8 +104,9 @@ impl<U: Union + Clone> Union for Option<U> {
101104
}
102105
}
103106

104-
/// Granularity of an axis. This does not affect the range of values.
105-
/// Describes the number of unique values between `0` and `1` of the associated unit.
107+
/// Describes the number of unique values in the entire range of the associated axis.
108+
///
109+
/// This does not affect the range of values nor the interpretation of values reported by a [`Pose`].
106110
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
107111
#[repr(transparent)]
108112
pub struct Granularity(pub std::num::NonZeroU32);
@@ -125,12 +129,18 @@ impl Union for PositionGranularity {
125129
}
126130
}
127131

128-
/// Limits of an axis's reported value.
132+
/// Limits of an axis's reported value. This does not affect the interpretation of a value reported by [`Pose`]
133+
///
134+
/// In many cases, you may ignore this value - this crate makes strong guarantees about the
135+
/// units values are reported in, and you may rely on those. However, this may desscribe e.g. that a tool only detects
136+
/// tilt in the +/-45° range.
129137
/// # Quirks
130138
/// This is a hint, and the value is not clamped - the hardware is allowed to report a value exceeding this in either direction.
131139
#[derive(Clone, Copy, Debug)]
132140
pub struct Limits {
141+
/// Inclusive minimum
133142
pub min: f32,
143+
/// Inclusive maximum
134144
pub max: f32,
135145
}
136146
impl From<Limits> for std::ops::RangeInclusive<f32> {
@@ -153,7 +163,7 @@ impl Union for Limits {
153163
}
154164
}
155165

156-
/// Represents a normalized axis, always in the range `0..=1`
166+
/// Represents a normalized axis, always in the range `[0, 1]`
157167
/// Since the min and max are fixed, only the granularity is given, if known.
158168
#[derive(Clone, Copy, Debug, Default)]
159169
pub struct NormalizedInfo {
@@ -167,14 +177,14 @@ impl Union for NormalizedInfo {
167177
}
168178
}
169179

180+
/// Info for an axis which may or may not correspond to a physical unit of length.
170181
#[derive(Clone, Copy, Debug)]
171182
pub enum LengthInfo {
172-
/// The axis reports a `0..=1` range, where the value doesn't necessarily correlate linearly with a
183+
/// The axis reports a `[0, 1]` range, where the value doesn't necessarily correlate linearly with a
173184
/// physical unit of distance.
174-
/// In this case, [`Granularity`] is to be interpreted as the total number of states between 0 and 1.
175185
Normalized(NormalizedInfo),
176186
/// The axis reports a physical distance in centimeters, within the range provided by
177-
/// [`Info::limits`]. In this case, [`Granularity`] is to be interpreted as "dots per cm".
187+
/// [`Info::limits`].
178188
Centimeters(Info),
179189
}
180190
impl LengthInfo {
@@ -218,6 +228,7 @@ impl Default for LengthInfo {
218228
}
219229
}
220230

231+
/// Generic information about an axis with hardware-defined limits.
221232
#[derive(Clone, Copy, Debug, Default)]
222233
pub struct Info {
223234
pub limits: Option<Limits>,
@@ -245,7 +256,7 @@ impl Union for PositionInfo {
245256
}
246257
}
247258

248-
/// Information about a circular axis, always reporting in the range of `0..TAU`.
259+
/// Information about a circular axis, always reporting in the range of `[0, TAU)`.
249260
#[derive(Clone, Copy, Debug, Default)]
250261
pub struct CircularInfo {
251262
pub granularity: Option<Granularity>,
@@ -258,7 +269,7 @@ impl Union for CircularInfo {
258269
}
259270
}
260271

261-
/// Information about a slider axis, always reporting in the range of `-1..=1` with zero being the resting point.
272+
/// Information about a slider axis, always reporting in the range of `[-1, 1]` with zero being the resting point.
262273
#[derive(Clone, Copy, Debug, Default)]
263274
pub struct SliderInfo {
264275
pub granularity: Option<Granularity>,
@@ -272,19 +283,15 @@ impl Union for SliderInfo {
272283
}
273284

274285
/// A report of the limits and capabilities of all axes, or None if the axis is
275-
/// not supported by the device.
286+
/// not supported by the device. See [`Pose`] for descriptions.
276287
#[derive(Debug, Copy, Clone, Default)]
277288
pub struct FullInfo {
278289
/// The X and Y axes - always supported, and with units of logical pixels.
279290
pub position: [PositionInfo; 2],
280-
/// A unitless normalized value in [-1, 1]
281291
pub slider: Option<SliderInfo>,
282-
/// The rotation around the tool's long axis, always reported in radians `0..TAU` if available.
283292
pub roll: Option<CircularInfo>,
284-
// Force axes. Ink *can* report these in grams, but for simplicities sake we normalize. Todo?
285293
pub pressure: Option<NormalizedInfo>,
286294
pub button_pressure: Option<NormalizedInfo>,
287-
/// X/Y tilt, in radians from vertical. See [`Pose::tilt`].
288295
pub tilt: Option<Info>,
289296
pub wheel: Option<CircularInfo>,
290297
pub distance: Option<LengthInfo>,
@@ -312,6 +319,7 @@ impl Union for FullInfo {
312319

313320
#[derive(thiserror::Error, Debug, Copy, Clone, PartialEq, Eq, Hash)]
314321
#[error("axis not supported")]
322+
/// An axis was queried that is not reported as available.
315323
pub struct UnsupportedAxisError;
316324

317325
impl FullInfo {
@@ -441,7 +449,8 @@ pub struct Pose {
441449
///
442450
/// This may have sub-pixel precision, and may exceed your window size in the negative or positive directions.
443451
pub position: [f32; 2],
444-
/// Perpendicular distance from the surface of the tablet. See [`FullInfo::distance`] for interpretation.
452+
/// Perpendicular distance from the surface of the tablet. This may be an arbitrary, unitless `[0, 1]` value, or
453+
/// reported in physical centimeters, see the [`FullInfo::distance`] of the reporting [`Tool`](crate::tool::Tool) for interpretation.
445454
///
446455
/// # Quirks
447456
/// This will not necessarily be zero when in contact with the device, and may
@@ -472,6 +481,6 @@ pub struct Pose {
472481
/// Absolute slider position, in `[-1, 1]`, where zero is the "natural" position.
473482
pub slider: NicheF32,
474483
/// The size of the contact ellipse. First element describes the X-axis width of the ellipse,
475-
/// and second describes the Y-axis height. See [`FullInfo::contact_size`] for interpretation.
484+
/// and second describes the Y-axis height. See [`FullInfo::contact_size`] of the reporting [`Tool`](crate::tool::Tool) for units.
476485
pub contact_size: Option<[f32; 2]>,
477486
}

src/events/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ impl std::ops::Sub for FrameTimestamp {
2828
}
2929
}
3030

31-
/// Events associated with a specific `Tool`.
31+
/// Events associated with a specific [`Tool`].
32+
///
3233
/// Events other than Added and Removed are logically grouped into "Frames" representing grouping
3334
/// of events in time, providing the timestamp that the group's events occured at if available.
3435
/// Events within a frame are arbitrarily ordered and to be interpreted
@@ -87,7 +88,7 @@ pub enum ToolEvent<'a> {
8788
/// The tool has left sensing range or left the window region of the tablet.
8889
Out,
8990
}
90-
/// Events associated with a specific `Tablet`.
91+
/// Events associated with a specific [`Tablet`].
9192
#[derive(Clone, Copy, Debug)]
9293
pub enum TabletEvent {
9394
/// The tablet is new. May be enumerated at the start of the program,
@@ -96,7 +97,7 @@ pub enum TabletEvent {
9697
/// Unplugged or otherwise becomes unavailable. The tablet will be removed from the hardware report.
9798
Removed,
9899
}
99-
/// Events associated with a specific `Pad`.
100+
/// Events associated with a specific [`Pad`](pad::Pad).
100101
#[derive(Clone, Copy, Debug)]
101102
pub enum PadEvent<'a> {
102103
/// The pad is new. May be enumerated at the start of the program,
@@ -124,7 +125,7 @@ pub enum PadEvent<'a> {
124125
/// The pad has lost it's tablet association.
125126
Exit,
126127
}
127-
/// Events associated with a specific group within a larger Pad.
128+
/// Events associated with a specific [`Group`](pad::Group) within a larger [`Pad`](pad::Pad).
128129
#[derive(Clone, Copy, Debug)]
129130
pub enum PadGroupEvent<'a> {
130131
/// A ring was interacted.

src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ enum Backing {
6767
Raw,
6868
}
6969
#[derive(Clone, Copy, Debug)]
70+
71+
/// List of supported backends. This is not affected by enabled features.
7072
// Some are never constructed due to disabled features/target platform.
7173
#[allow(dead_code)]
7274
pub enum Backend {
@@ -89,7 +91,7 @@ pub enum PumpError {
8991
WaylandDispatch(#[from] wayland_client::DispatchError),
9092
}
9193

92-
/// Manages a connection to the OS's tablet server. This is the main
94+
/// Maintains a connection to the OS's tablet server. This is the main
9395
/// entry point for enumerating hardware and listening for events.
9496
pub struct Manager {
9597
pub(crate) internal: platform::PlatformManager,
@@ -100,7 +102,9 @@ pub struct Manager {
100102
pub(crate) _backing: Backing,
101103
}
102104
impl Manager {
103-
/// Dispatch pending events without blocking, updating hardware reports and returning an [`IntoIterator`] containing the events.
105+
/// Dispatch pending events, updating hardware reports and returning an [`IntoIterator`] containing the events.
106+
///
107+
/// This will not wait for new events, and will return immediately with empty events if there is nothing to do.
104108
#[allow(clippy::missing_errors_doc)]
105109
pub fn pump(&mut self) -> Result<Events<'_>, PumpError> {
106110
self.internal.pump()?;

src/pad.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ pub mod group {
3434
/// The type of interactable being queried in a [`FeedbackFn`]
3535
#[derive(Copy, Clone)]
3636
pub enum FeedbackElement<'a> {
37-
/// The [button](super::Pad::total_buttons) with the given pad index. This will only
37+
/// The [button](super::Pad::total_buttons) index with the given pad. This will only
3838
/// be called with buttons [owned](Group::buttons) by the relevant group.
3939
Button(u32),
4040
Ring(&'a super::Ring),
4141
Strip(&'a super::Strip),
4242
}
4343

4444
/// After the group switches to the given mode index, provide feedback to the OS as to the roles
45-
/// of buttons, sliders, and rings within the group. Called potentially many times per switch.
45+
/// of buttons, sliders, and rings within the group. Called potentially many times per mode switch.
4646
pub type FeedbackFn = dyn FnMut(&Group, u32, FeedbackElement<'_>) -> String;
4747

48+
/// A Pad reports one or more Groups. See the [pad module docs](crate::pad) for more info.
4849
pub struct Group {
4950
pub(crate) internal_id: crate::InternalID,
5051
/// How many mode layers does this group cycle through?
@@ -53,7 +54,9 @@ pub mod group {
5354
/// Sorted list of the pad button indices that are owned by this group.
5455
/// This is some subset of the [buttons reported by the Pad](super::Pad::total_buttons).
5556
pub buttons: Vec<u32>,
57+
/// The set of rings belonging to this group.
5658
pub rings: Vec<super::Ring>,
59+
/// The set of strips belonging to this strip.
5760
pub strips: Vec<super::Strip>,
5861
/// Called synchronously for each group element (buttons, rings, and strips) after a modeswitch on supporting platforms.
5962
/// Provides new description text for the roles of each element, which may be shown by on-screen displays or other means.

src/tool.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Also called a *stylus* or *pointer*, these represent the device that the user holds to interact with a pad.
44
//! "Tools" do not correspond with directly with the above concepts, for example a
55
//! single stylus with a tip and eraser represents *two* tools, one for each end. These can be re-associated with
6-
//! each other through [`Tool::id`].
6+
//! each other through [`Tool::hardware_id`].
77
//!
88
//! See [`Type`] for more ideas of what a "tool" may represent.
99
//!
@@ -41,6 +41,7 @@ impl std::fmt::Debug for ButtonID {
4141
#[repr(transparent)]
4242
pub struct HardwareID(pub(crate) u64);
4343

44+
/// Describes the class of hardware a tool represents
4445
#[derive(Clone, Copy, Debug, strum::AsRefStr, PartialEq, Eq)]
4546
pub enum Type {
4647
Pen,

0 commit comments

Comments
 (0)