Skip to content

Show full program context when eye button is clicked in Hello World example - #147

Open
RowanTL wants to merge 1 commit into
godot-rust:masterfrom
RowanTL:hello-world-change
Open

Show full program context when eye button is clicked in Hello World example#147
RowanTL wants to merge 1 commit into
godot-rust:masterfrom
RowanTL:hello-world-change

Conversation

@RowanTL

@RowanTL RowanTL commented Aug 2, 2026

Copy link
Copy Markdown

Why

When I read through a rust book, I like to click on the little eye icon to see how a block of code fits into the entirety of the program. I found myself confused after reading through the Hello World example.

Problem

The current behavior of the eye button wraps the block of code in a main function call. This is not verbose enough and confusing in my opinion. Also, none of the playground examples compile.

Proposed Changes

  • Remove playground functionality
  • When the eye icon is pressed, show the rust block in relation to the entire lib.rs file

More details about the changes

The play button is removed by adding the block below to book.toml

[output.html.playground]
runnable = false

As for showing code when the eye icon is pressed, I created a file at src/intro/code/hello-world.rs that has anchors placed in it, controlling what code is shown. I removed the line fn init(base: Base<Sprite2D>) -> Self { /* as before */ } from being mentioned as the user could simply click the eye and see the implementation. Finally, I added an admonish tip to click the eye before the Rust entry point block.

AI Usage

I used Claude Opus 5 in this PR. Claude stitched together the code blocks and placed most of the anchor points in src/intro/code/hello-world.rs. I modified the anchor points to remain loyal to the original rust blocks.

Testing

Using Godot 4.7.1, I saw icon.svg moving in a circle from the code in src/intro/code/hello-world.rs when running the scene. I have not tested whether the Custom Rust APIs block functions.

Final Notes

If anything could be changed, let me know.

@RowanTL

RowanTL commented Aug 3, 2026

Copy link
Copy Markdown
Author

Here's a visual of what I changed:

New docs:

new_docs.mp4

Old docs:

old_docs.mp4

Comment thread book.toml
Comment on lines +29 to +33
# Snippets in this book are library code (cdylib entry points, #[godot_api] impls, ...) and
# depend on the `godot` crate, so none of them can run on play.rust-lang.org. Without this,
# mdbook silently wraps every Rust block in a hidden `fn main() { ... }`, which the "show
# hidden lines" eye icon then reveals as if it were real code. Explicit `# ` hidden lines
# still work as usual.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a lot of words used while shorter one-line sentence could do a job just fine.

Comment on lines +9 to +11
// Anchor names may be opened and closed more than once; mdbook concatenates the regions and
// hides everything in between. That is how a block can show e.g. the `impl` header and one
// method without the other methods.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do you describe something which is included in mdbook documentation https://wofwca.github.io/mdBook/format/mdbook.html#including-portions-of-a-file?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sometimes I leave slop in. Planning to remove.

Comment on lines +6 to +7
// Complete source for the Hello World tutorial. Every code block in
// src/intro/hello-world.md includes one of the anchors below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what does this comment is supposed to convey?

Comment on lines +62 to +77
// ANCHOR_END: physics-process
// In GDScript, this would be:
// rotation += angular_speed * delta

// ANCHOR: physics-process
// GDScript code:
//
// rotation += angular_speed * delta
// var velocity = Vector2.UP.rotated(rotation) * speed
// position += velocity * delta

let radians = (self.angular_speed * delta) as f32;
self.base_mut().rotate(radians);
// The 'rotate' method requires a f32,
// therefore we convert 'self.angular_speed * delta' which is a f64 to a f32
// ANCHOR_END: rotate

@Yarwin Yarwin Aug 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these examples should be separate; while enlarged they are displayed as:

Image

which is very confusing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Seems like the best way around this is two have two separate Rust files or foregoing the hidden lines feature on one of the blocks. lmk what you think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think two files might be okay, people might want to copy-paste them

Comment thread src/intro/hello-world.md
// therefore we convert 'self.angular_speed * delta' which is a f64 to a f32
}
}
{{#rustdoc_include code/hello-world.rs:rotate}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Personally I would just inline this one example (or split existing one into two if somebody insists). Additionally, rotate section is misleading - the example showcases usage of virtual method physics_process.

and a small update can be made – for a long time one can use delta: f32 directly in *process methods.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Will change rotate to something else. If you're okay with losing the hidden context here, I'd be okay with inlining too (unless you want to copy and paste the entirety of hello-world.rs into the readme just for it).

New to godot and haven't really ever contributed to a large codebase personally or professionally before. Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants