MCPcopy Create free account
hub / github.com/cogentcore/core / setFuncImpl

Method setFuncImpl

core/funcbutton.go:241–284  ·  view source on GitHub ↗

setFuncImpl is the underlying implementation of [FuncButton.SetFunc]. It should typically not be used by end-user code.

(gfun *types.Func, rfun reflect.Value)

Source from the content-addressed store, hash-verified

239// setFuncImpl is the underlying implementation of [FuncButton.SetFunc].
240// It should typically not be used by end-user code.
241func (fb *FuncButton) setFuncImpl(gfun *types.Func, rfun reflect.Value) *FuncButton {
242 fb.typesFunc = gfun
243 fb.reflectFunc = rfun
244 fb.setArgs()
245 fb.setReturns()
246 snm := fb.typesFunc.Name
247 // get name without package
248 li := strings.LastIndex(snm, ".")
249 isAnonymous := isAnonymousFunction(snm)
250 if snm == "reflect.makeFuncStub" { // used for anonymous functions in yaegi
251 snm = "Anonymous function"
252 li = -1
253 } else if isAnonymous {
254 snm = strings.TrimRightFunc(snm, func(r rune) bool {
255 return unicode.IsDigit(r) || r == '.'
256 })
257 snm = strings.TrimSuffix(snm, ".func")
258 // we cut at the second to last period (we want to keep the
259 // receiver / package for anonymous functions)
260 li = strings.LastIndex(snm[:strings.LastIndex(snm, ".")], ".")
261 }
262 if li >= 0 {
263 snm = snm[li+1:] // must also get rid of "."
264 // if we are a global function, we may have gone too far with the second to last period,
265 // so we go after the last slash if there still is one
266 if strings.Contains(snm, "/") {
267 snm = snm[strings.LastIndex(snm, "/")+1:]
268 }
269 }
270 snm = strings.Map(func(r rune) rune {
271 if r == '(' || r == ')' || r == '*' {
272 return -1
273 }
274 return r
275 }, snm)
276 txt := strcase.ToSentence(snm)
277 fb.SetText(txt)
278 // doc formatting interferes with anonymous functions
279 if !isAnonymous {
280 fb.typesFunc.Doc = types.FormatDoc(fb.typesFunc.Doc, snm, txt)
281 }
282 fb.SetTooltip(fb.typesFunc.Doc)
283 return fb
284}
285
286func (fb *FuncButton) goodContext() Widget {
287 ctx := fb.Context

Callers 2

SetFuncMethod · 0.95
setMethodImplMethod · 0.95

Calls 9

setArgsMethod · 0.95
setReturnsMethod · 0.95
SetTextMethod · 0.95
ToSentenceFunction · 0.92
FormatDocFunction · 0.92
isAnonymousFunctionFunction · 0.85
MapMethod · 0.80
SetTooltipMethod · 0.80
ContainsMethod · 0.45

Tested by

no test coverage detected