|
5 | 5 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +use std::borrow::Cow; |
| 9 | +use std::marker::PhantomData; |
| 10 | +use std::ops::DerefMut; |
| 11 | + |
8 | 12 | use super::{make_callable_name, make_godot_fn, ConnectBuilder, ConnectHandle, SignalObject}; |
9 | 13 | use crate::builtin::{Callable, Variant}; |
10 | 14 | use crate::classes::object::ConnectFlags; |
11 | 15 | use crate::meta; |
12 | 16 | use crate::meta::{InParamTuple, ObjectToOwned, UniformObjectDeref}; |
13 | 17 | use crate::obj::{Gd, GodotClass, WithSignals}; |
14 | 18 | use crate::registry::signal::signal_receiver::{IndirectSignalReceiver, SignalReceiver}; |
15 | | -use std::borrow::Cow; |
16 | | -use std::marker::PhantomData; |
17 | | -use std::ops::DerefMut; |
18 | | -// ---------------------------------------------------------------------------------------------------------------------------------------------- |
19 | 19 |
|
20 | 20 | /// Type-safe version of a Godot signal. |
21 | 21 | /// |
@@ -205,38 +205,36 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> TypedSignal<'_, C, Ps> { |
205 | 205 | /// # #[derive(GodotClass)] |
206 | 206 | /// # #[class(init, base=Node)] |
207 | 207 | /// # pub struct Player { |
208 | | - /// # health_ui: OnEditor<Gd<HealthUI>>, |
| 208 | + /// # ui: OnEditor<Gd<HealthUi>>, |
209 | 209 | /// # base: Base<Node>, |
210 | 210 | /// # } |
211 | 211 | /// # #[derive(GodotClass)] |
212 | 212 | /// # #[class(init, base=Node2D)] |
213 | | - /// # pub struct HealthUI { |
| 213 | + /// # pub struct HealthUi { |
214 | 214 | /// # base: Base<Node2D>, |
215 | 215 | /// # } |
216 | | - /// # #[godot_api] |
217 | | - /// # impl Player { |
218 | | - /// # #[signal] |
219 | | - /// # fn health_changed(health: i32); |
220 | | - /// # } |
221 | | - /// impl Player { |
222 | | - /// fn change_health_anim(&mut self, health: i32) { |
223 | | - /// // Change animation based on health |
224 | | - /// } |
225 | | - /// } |
226 | | - /// impl HealthUI { |
227 | | - /// fn on_health_changed(&mut self, health: i32) { |
228 | | - /// // Change healthbar UI based on health |
229 | | - /// } |
230 | | - /// } |
| 216 | + /// #[godot_api] |
| 217 | + /// impl Player { |
| 218 | + /// #[signal] |
| 219 | + /// fn health_changed(health: i32); |
| 220 | + /// |
| 221 | + /// fn change_health_anim(&mut self, health: i32) { /* ... */ } |
| 222 | + /// } |
| 223 | + /// impl HealthUi { |
| 224 | + /// fn on_health_changed(&mut self, health: i32) { /* ... */ } |
| 225 | + /// } |
231 | 226 | /// #[godot_api] |
232 | 227 | /// impl INode for Player { |
233 | 228 | /// fn ready(&mut self) { |
234 | | - /// self.signals() // Connect to self |
| 229 | + /// // Connect to this object. |
| 230 | + /// self.signals() |
235 | 231 | /// .health_changed() |
236 | 232 | /// .connect_self(Self::change_health_anim); |
237 | | - /// self.signals() // Connect to other object (health_ui is OnEditor<Gd<HealthUI>>) |
| 233 | + /// |
| 234 | + /// // Connect to other object, where ui: OnEditor<Gd<HealthUi>>. |
| 235 | + /// self.signals() |
238 | 236 | /// .health_changed() |
239 | | - /// .connect_self(|s, amount| s.health_ui.bind_mut().on_health_changed(amount)); |
| 237 | + /// .connect_self(|this, amount| this.ui.bind_mut().on_health_changed(amount)); |
240 | 238 | /// } |
241 | 239 | /// } |
242 | 240 | /// ``` |
@@ -295,11 +293,14 @@ impl<C: WithSignals, Ps: InParamTuple + 'static> TypedSignal<'_, C, Ps> { |
295 | 293 | /// #[godot_api] |
296 | 294 | /// impl IControl for Tool { |
297 | 295 | /// fn ready(&mut self) { |
298 | | - /// self.button // Connect from other to self |
| 296 | + /// // Connect from other to self. |
| 297 | + /// self.button |
299 | 298 | /// .signals() |
300 | 299 | /// .pressed() |
301 | 300 | /// .connect_other(self, Self::execute_tool); |
302 | | - /// self.button // Connect from other to other (other_tool is OnEditor<Gd<OtherTool>>) |
| 301 | + /// |
| 302 | + /// // Connect from other to other, where other_tool: OnEditor<Gd<OtherTool>>. |
| 303 | + /// self.button |
303 | 304 | /// .signals() |
304 | 305 | /// .pressed() |
305 | 306 | /// .connect_other(&*self.other_tool, |tool| tool.set_tool_enabled(false)); |
|
0 commit comments