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

Method SizeClass

core/sizeclasses.go:25–43  ·  view source on GitHub ↗

SizeClass returns the size class of the scene in which the widget is contained.

()

Source from the content-addressed store, hash-verified

23
24// SizeClass returns the size class of the scene in which the widget is contained.
25func (wb *WidgetBase) SizeClass() SizeClasses {
26 dots := float32(wb.Scene.sceneGeom.Size.X)
27 if wb.Scene.prefSizing {
28 if currentRenderWindow != nil {
29 rg := currentRenderWindow.SystemWindow.RenderGeom()
30 dots = float32(rg.Size.X)
31 }
32 }
33 dpd := wb.Scene.Styles.UnitContext.Dp(1) // dots per dp
34 dp := dots / dpd // dots / (dots / dp) = dots * (dp / dots) = dp
35 switch {
36 case dp < 600:
37 return SizeCompact
38 case dp > 840:
39 return SizeExpanded
40 default:
41 return SizeMedium
42 }
43}

Callers 6

InitMethod · 0.80
InitMethod · 0.80
InitMethod · 0.80
effectiveMethod · 0.80
makeBlockFunction · 0.80
homePageFunction · 0.80

Calls 2

RenderGeomMethod · 0.65
DpMethod · 0.45

Tested by

no test coverage detected