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

Adding Examples and documentation for List Widget #2302

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

ThomasMcandrew
Copy link
Contributor

Hoping to resolve #803 What is the protocol for working with issues?

Also Is there a way to link the docs to im Crate without going externally as I do. I could not find any examples of this.

/// label
/// }
/// ```
/// [`im`]: https://docs.rs/druid/0.6.0/druid/im/index.html
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the link I am referring to in the description. is there a way to do it like the flex crate below?

Copy link
Collaborator

Choose a reason for hiding this comment

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

From my tests, it seems that [`im`] alone works, but only if you build the docs with --feature=im. I wouldn't bother.

Copy link
Collaborator

@PoignardAzur PoignardAzur left a comment

Choose a reason for hiding this comment

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

My general takeaway is "this should be a bit shorter". I'm usually in favor of docs that assume the user knows very little and tries to explain things from the ground up, but in this case I think having this level of explanation for a single widget may be confusing; it may give the impression this widget composes differently than other widgets.

If you think there should be more documentation explaining how composition works, I'd recommend adding it to the book, the widget trait, or the documentation root.

/// For a static sized collection of items use [`Flex`].
/// The best data structure to use with the list widget is [`Vector`] from the [`im`] feature.
/// To include the [`im`] feature, update Cargo.toml
/// ```ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// ```ignore
/// ```toml

Marking the code as toml gets you better highlighting.

Comment on lines +52 to +100
/// ```
/// # use druid::{ Data, Lens };
/// use druid::im::Vector;
/// #[derive(Clone, Data, Lens)]
/// struct AppState {
/// list_data: Vector<String>,
/// }
/// ```
/// ## Create initial State
///
/// ```
/// # use druid::{ Data, Lens};
/// # use druid::im::Vector;
/// # #[derive(Clone, Data, Lens)]
/// # struct AppState {
/// # list_data: Vector<String>,
/// # }
/// let initial_state = AppState {
/// list_data: Vector::from(
/// vec!(
/// "one".into(),
/// "two".into(),
/// "three".into(),
/// "four".into(),
/// )),
/// };
/// ```
/// ## Create widgets
///
/// ```
/// # use druid::widget::{ Label, List };
/// # use druid::{ Data, Lens, Widget, WidgetExt, Env};
/// # use druid::im::Vector;
/// # #[derive(Clone, Data, Lens)]
/// # struct AppState {
/// # list_data: Vector<String>,
/// # }
/// fn root() -> impl Widget<AppState> {
/// let list = List::new(list_item)
/// .lens(AppState::list_data);
/// list
/// }
///
/// fn list_item() -> impl Widget<String> {
/// let label = Label::new(|data: &String, _env: &Env|
/// data.clone());
/// label
/// }
/// ```
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole example seems way too big to me. It's the example equivalent of an integration test, where you'd want a unit test.

I'd recommend skipping the AppState data structure and the lensing, and just using Vector<String> in your example.

Comment on lines +125 to +152
/// ## Complex widgets
/// List can be used with any complex widgets.
/// ```
/// # use druid::widget::{ Label, List };
/// # use druid::{ Data, Lens, Widget, WidgetExt, Env};
/// # use druid::im::Vector;
/// #[derive(Clone, Data, Lens)]
/// struct AppState {
/// list_data: Vector<InnerState>,
/// }
///
/// #[derive(Clone, Data, Lens)]
/// struct InnerState {
/// name: String,
/// }
///
/// fn root() -> impl Widget<AppState> {
/// let list = List::new(list_item)
/// .lens(AppState::list_data);
/// list
/// }
///
/// fn list_item() -> impl Widget<InnerState> {
/// let label = Label::new(|data: &InnerState, _env: &Env|
/// data.name.clone());
/// label
/// }
/// ```
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should remove that part, or at least make it way shorter. That fact that widgets can be compose doesn't need to be documented in every container widget.

Comment on lines +168 to +171
///
/// The list widget can have a function passed in as a closure, or an abstract closure can also
/// be provided.
///
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part seems superfluous. I think you can assume the vast majority of Rust users will be familiar with how closures work. (And if they aren't, this isn't the place to explain them)

Comment on lines +193 to +201
/// //This widget is the same as the two widgets above
/// //combined.
/// fn combined() -> impl Widget<AppState> {
/// let list = List::new(||
/// Label::new(|data: &String, _env: &Env|
/// data.clone()))
/// .lens(AppState::list_data);
/// list
/// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can probably remove the combined function; the other two are descriptive enough on their own.

@PoignardAzur
Copy link
Collaborator

Other than that, LGTM. Even if the PR author doesn't do any of the changes I suggested, I'd still be in favor of merging the PR as-is.

@xStrom xStrom added docs concerns documentation S-waiting-on-author waits for changes from the submitter labels Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs concerns documentation S-waiting-on-author waits for changes from the submitter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve List documentation
3 participants