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

Method Init

core/widget.go:229–273  ·  view source on GitHub ↗

Init should be called by every [Widget] type in its custom Init if it has one to establish all the default styling and event handling that applies to all widgets.

()

Source from the content-addressed store, hash-verified

227// Init if it has one to establish all the default styling
228// and event handling that applies to all widgets.
229func (wb *WidgetBase) Init() {
230 wb.Styler(func(s *styles.Style) {
231 s.MaxBorder.Style.Set(styles.BorderSolid)
232 s.MaxBorder.Color.Set(colors.Scheme.Primary.Base)
233 s.MaxBorder.Width.Set(units.Dp(1))
234
235 // if we are disabled, we do not react to any state changes,
236 // and instead always have the same gray colors
237 if s.Is(states.Disabled) {
238 s.Cursor = cursors.NotAllowed
239 s.Opacity = 0.38
240 return
241 }
242 // TODO(kai): what about context menus on mobile?
243 tt, _ := wb.This.(Widget).WidgetTooltip(image.Pt(-1, -1))
244 s.SetAbilities(tt != "", abilities.LongHoverable, abilities.LongPressable)
245
246 if s.Is(states.Selected) {
247 s.Background = colors.Scheme.Select.Container
248 s.Color = colors.Scheme.Select.OnContainer
249 }
250 })
251 wb.FinalStyler(func(s *styles.Style) {
252 if s.Is(states.Focused) {
253 s.Border.Style = s.MaxBorder.Style
254 s.Border.Color = s.MaxBorder.Color
255 s.Border.Width = s.MaxBorder.Width
256 }
257 if !s.AbilityIs(abilities.Focusable) {
258 // never need bigger border if not focusable
259 s.MaxBorder = s.Border
260 }
261 })
262
263 // TODO(kai): maybe move all of these event handling functions into one function
264 wb.handleWidgetClick()
265 wb.handleWidgetStateFromMouse()
266 wb.handleLongHoverTooltip()
267 wb.handleWidgetStateFromFocus()
268 wb.handleWidgetContextMenu()
269 wb.handleWidgetMagnify()
270 wb.handleValueOnChange()
271
272 wb.Updater(wb.UpdateFromMake)
273}
274
275// OnAdd is called when widgets are added to a parent.
276// It sets the scene of the widget to its widget parent.

Callers

nothing calls this directly

Calls 15

StylerMethod · 0.95
FinalStylerMethod · 0.95
AbilityIsMethod · 0.95
handleWidgetClickMethod · 0.95
handleWidgetMagnifyMethod · 0.95
handleValueOnChangeMethod · 0.95
DpFunction · 0.92
SetAbilitiesMethod · 0.80

Tested by

no test coverage detected