Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Documentation #23

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,37 @@ where
}
}

/// Generates a lens to a struct field
///
/// Parameters:
/// - `lens_name` - name of the resulting lens struct
/// - `from` - type for which the lens is implemented
/// - `to` - type of the field
/// - `field` - name of the field
///
/// Usage:
/// ```no_run
/// use rui::*;
///
/// #[derive(Default)]
/// struct MyState {
/// value: f32,
/// }
///
/// make_lens!(ValueLens, MyState, f32, value);
///
/// fn my_view() -> impl View {
/// state(MyState::default, |state, cx| {
/// vstack((
/// cx[state].value.font_size(10).padding(Auto),
/// hslider(bind(state, ValueLens {}))
/// .thumb_color(RED_HIGHLIGHT)
/// .padding(Auto),
/// ))
/// })
/// }
/// ```

#[macro_export]
macro_rules! make_lens {
($lens_name: ident, $from: ty, $to: ty, $field: ident) => {
Expand Down
19 changes: 18 additions & 1 deletion src/views/anyview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,24 @@ impl View for AnyView {
}
}

/// Switches between views according to a boolean.
/// Erases the underlying view type, allowing
/// the function to return multiple different view types
///
/// Usage:
/// ```no_run
/// use rui::*;
///
/// fn main() {
/// rui(list(vec![7, 42], |i| {
/// if *i == 7 {
/// any_view(circle())
/// } else {
/// any_view(rectangle())
/// }
/// .padding(Auto)
/// }));
/// }
/// ```
pub fn any_view(view: impl View) -> AnyView {
AnyView {
child: Box::new(view),
Expand Down
2 changes: 1 addition & 1 deletion src/views/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where
}
}

/// Canvas for GPU drawing with Vger. See https://github.com/audulus/vger-rs.
/// Canvas for GPU drawing with Vger. See <https://github.com/audulus/vger-rs>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does that warning come from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I ran cargo doc, it threw a warning (https://doc.rust-lang.org/rustdoc/lints.html#bare_urls). Essentially, as it was it wouldn't actually render into a hyperlink, just a URL text. Adding <> should make it a hyperlink.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just compared the version on docs.rs and my local docs build, and adding <> as suggested really did turn this into a hyperlink.

Before the change:
изображение

After:
изображение

Copy link
Author

@UARTman UARTman Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning page I linked to explains why it doesn't show up unless you try and build the docs locally:

Note that, except for missing_docs, these lints are only available when running rustdoc, not rustc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool.. thanks for the info!

pub fn canvas<F: Fn(&mut Context, LocalRect, &mut Vger) + 'static>(f: F) -> impl View {
Canvas { func: f }
}
Expand Down
10 changes: 7 additions & 3 deletions src/views/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ where

impl<S1, SF, F> private::Sealed for MapView<S1, SF, F> {}

/// Maps state into local state.
///
/// For example:
/// Creates local derived state with a setter.
///
/// Arguments:
/// - `value` - local state value
/// - `set_value` - a function that will run each time the local state changes
/// - `func` - view function using the local state
///
/// Usage:
/// ```no_run
/// # use rui::*;
///
Expand Down