MCPcopy Index your code
hub / github.com/lxn/walk / CreateLayoutItem

Method CreateLayoutItem

scrollview.go:304–369  ·  view source on GitHub ↗
(ctx *LayoutContext)

Source from the content-addressed store, hash-verified

302}
303
304func (sv *ScrollView) CreateLayoutItem(ctx *LayoutContext) LayoutItem {
305 svli := new(scrollViewLayoutItem)
306 svli.ctx = ctx
307 cli := CreateLayoutItemsForContainerWithContext(sv.composite, ctx)
308 cli.AsLayoutItemBase().parent = svli
309 svli.children = append(svli.children, cli)
310
311 if box, ok := cli.(*boxLayoutItem); ok {
312 if len(box.children) > 0 {
313 if _, ok := box.children[len(box.children)-1].(*spacerLayoutItem); !ok {
314 // To retain the previous behavior with box layouts, we add a fake spacer at the end.
315 // Maybe this should just be an option.
316 box.children = append(box.children, &spacerLayoutItem{
317 LayoutItemBase: LayoutItemBase{ctx: ctx},
318 layoutFlags: ShrinkableHorz | ShrinkableVert | GrowableVert | GreedyVert,
319 })
320 }
321 }
322 }
323
324 svli.idealSize = cli.MinSize()
325
326 h, v := sv.Scrollbars()
327
328 if h {
329 svli.layoutFlags |= ShrinkableHorz | GrowableHorz | GreedyHorz
330
331 if !v {
332 maxSize := SizeFrom96DPI(sv.maxSize96dpi, ctx.dpi)
333 if svli.idealSize.Width > sv.geometry.ClientSize.Width && sv.geometry.ClientSize.Width > 0 && maxSize.Width == 0 ||
334 svli.idealSize.Width > maxSize.Width && maxSize.Width > 0 {
335 svli.sbSize.Height = int(win.GetSystemMetricsForDpi(win.SM_CYHSCROLL, uint32(ctx.dpi)))
336 svli.idealSize.Height += svli.sbSize.Height
337 }
338
339 svli.minSize.Height = svli.idealSize.Height
340 }
341 }
342
343 if v {
344 svli.layoutFlags |= GreedyVert | GrowableVert | ShrinkableVert
345
346 if !h {
347 maxSize := SizeFrom96DPI(sv.maxSize96dpi, ctx.dpi)
348 if svli.idealSize.Height > sv.geometry.ClientSize.Height && sv.geometry.ClientSize.Height > 0 && maxSize.Height == 0 ||
349 svli.idealSize.Height > maxSize.Height && maxSize.Height > 0 {
350 svli.sbSize.Width = int(win.GetSystemMetricsForDpi(win.SM_CXVSCROLL, uint32(ctx.dpi)))
351 svli.idealSize.Width += svli.sbSize.Width
352 }
353
354 svli.minSize.Width = svli.idealSize.Width
355 }
356 }
357
358 var si win.SCROLLINFO
359 si.CbSize = uint32(unsafe.Sizeof(si))
360 si.FMask = win.SIF_POS | win.SIF_RANGE
361

Callers

nothing calls this directly

Calls 5

ScrollbarsMethod · 0.95
SizeFrom96DPIFunction · 0.85
AsLayoutItemBaseMethod · 0.65
MinSizeMethod · 0.65

Tested by

no test coverage detected