File tree Expand file tree Collapse file tree 2 files changed +3
-7
lines changed Expand file tree Collapse file tree 2 files changed +3
-7
lines changed Original file line number Diff line number Diff line change 3
3
Example for how to create a base widget which exposes virtual methods that other widgets can override.
4
4
In this case, a ` BaseButton ` class is defined which is a gtk::Button with two additional methods:
5
5
6
- * ` sync_method ` : Synchronous method that updates the button label to ` BaseButton sync ` , or ` BaseButton sync {} `
7
- where {} is replaced with the ` extra_text ` parameter, if it's ` Some ` . This showcases how arguments
8
- can be added to virtual methods. The ` Option<String> ` has to be boxed to be FFI-safe.
6
+ * sync_method` : Synchronous method that updates the button label to ` BaseButton sync` , or ` BaseButton sync {extra_text}`. This showcases how arguments
7
+ can be passed to virtual methods. The ` Option<String> ` has to be boxed to be FFI-safe.
9
8
* ` async_method ` : Asynchronous method that updates the button label to ` BaseButton async `
10
9
11
10
` DerivedButton ` overrides the two methods. During construction ` sync_method ` is called in
12
11
` BaseButton ` which will set the label to ` BaseButton sync ` for ` BaseButton ` and to
13
- ` DerivedButton sync ` for ` DerivedButton ` . In the ` VirtualMethodsWindow ` , ` connect_clicked ` is
14
- called on both buttons. Each handler for ` ::clicked ` will invoke the respective ` async_method ` .
15
- This updates the button's label accordingly when clicking it.
12
+ ` DerivedButton sync ` for ` DerivedButton ` .
Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ fn main() {
21
21
22
22
base_button. connect_clicked ( |b| {
23
23
let ctx = glib:: MainContext :: default ( ) ;
24
- let b = b. clone ( ) ;
25
24
ctx. spawn_local ( clone ! ( @weak b => async move {
26
25
b. async_method( ) . await . unwrap( ) ;
27
26
} ) ) ;
You can’t perform that action at this time.
0 commit comments