FuncButton is a button that is set up to call a function when it is pressed, using a dialog to prompt the user for any arguments. Also, it automatically sets various properties of the button like the text and tooltip based on the properties of the function, using [reflect] and [types]. The function
| 44 | // its receiver type must be added to [types] to get documentation. |
| 45 | // The main function to call first is [FuncButton.SetFunc]. |
| 46 | type FuncButton struct { |
| 47 | Button |
| 48 | |
| 49 | // typesFunc is the [types.Func] associated with this button. |
| 50 | // This function can also be a method, but it must be |
| 51 | // converted to a [types.Func] first. It should typically |
| 52 | // be set using [FuncButton.SetFunc]. |
| 53 | typesFunc *types.Func |
| 54 | |
| 55 | // reflectFunc is the [reflect.Value] of the function or |
| 56 | // method associated with this button. It should typically |
| 57 | // bet set using [FuncButton.SetFunc]. |
| 58 | reflectFunc reflect.Value |
| 59 | |
| 60 | // Args are the [FuncArg] objects associated with the |
| 61 | // arguments of the function. They are automatically set in |
| 62 | // [FuncButton.SetFunc], but they can be customized to configure |
| 63 | // default values and other options. |
| 64 | Args []FuncArg `set:"-"` |
| 65 | |
| 66 | // Returns are the [FuncArg] objects associated with the |
| 67 | // return values of the function. They are automatically |
| 68 | // set in [FuncButton.SetFunc], but they can be customized |
| 69 | // to configure options. The [FuncArg.Value]s are not set until |
| 70 | // the function is called, and are thus not typically applicable |
| 71 | // to access. |
| 72 | Returns []FuncArg `set:"-"` |
| 73 | |
| 74 | // Confirm is whether to prompt the user for confirmation |
| 75 | // before calling the function. |
| 76 | Confirm bool |
| 77 | |
| 78 | // ShowReturn is whether to display the return values of |
| 79 | // the function (and a success message if there are none). |
| 80 | // The way that the return values are shown is determined |
| 81 | // by ShowReturnAsDialog. Non-nil error return values will |
| 82 | // always be shown, even if ShowReturn is set to false. |
| 83 | ShowReturn bool |
| 84 | |
| 85 | // ShowReturnAsDialog, if and only if ShowReturn is true, |
| 86 | // indicates to show the return values of the function in |
| 87 | // a dialog, instead of in a snackbar, as they are by default. |
| 88 | // If there are multiple return values from the function, or if |
| 89 | // one of them is a complex type (pointer, struct, slice, |
| 90 | // array, map), then ShowReturnAsDialog will |
| 91 | // automatically be set to true. |
| 92 | ShowReturnAsDialog bool |
| 93 | |
| 94 | // NewWindow makes the return value dialog a NewWindow dialog. |
| 95 | NewWindow bool |
| 96 | |
| 97 | // WarnUnadded is whether to log warnings when a function that |
| 98 | // has not been added to [types] is used. It is on by default and |
| 99 | // must be set before [FuncButton.SetFunc] is called for it to |
| 100 | // have any effect. Warnings are never logged for anonymous functions. |
| 101 | WarnUnadded bool `default:"true"` |
| 102 | |
| 103 | // Context is used for opening dialogs if non-nil. |
nothing calls this directly
no outgoing calls
no test coverage detected