本文整理匯總了Golang中github.com/nelsam/gxui/math.Size.Contract方法的典型用法代碼示例。如果您正苦於以下問題:Golang Size.Contract方法的具體用法?Golang Size.Contract怎麽用?Golang Size.Contract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nelsam/gxui/math.Size
的用法示例。
在下文中一共展示了Size.Contract方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LayoutChildren
func (l *List) LayoutChildren() {
if l.adapter == nil {
l.outer.RemoveAll()
return
}
if !l.RelayoutSuspended() {
// Disable relayout on AddChild / RemoveChild as we're performing layout here.
l.SetRelayoutSuspended(true)
defer l.SetRelayoutSuspended(false)
}
s := l.outer.Size().Contract(l.Padding())
o := l.Padding().LT()
var itemSize math.Size
if l.orientation.Horizontal() {
itemSize = math.Size{W: l.itemSize.W, H: s.H}
} else {
itemSize = math.Size{W: s.W, H: l.itemSize.H}
}
startIndex, endIndex := l.VisibleItemRange(true)
majorAxisItemSize := l.MajorAxisItemSize()
d := startIndex*majorAxisItemSize - l.scrollOffset
mark := l.layoutMark
l.layoutMark++
for idx := startIndex; idx < endIndex; idx++ {
item := l.adapter.ItemAt(idx)
details, found := l.details[item]
if found {
if details.mark == mark {
panic(fmt.Errorf("Adapter for control '%s' returned duplicate item (%v) for indices %v and %v",
gxui.Path(l.outer), item, details.index, idx))
}
} else {
control := l.adapter.Create(l.theme, idx)
details.onClickSubscription = control.OnClick(func(ev gxui.MouseEvent) {
l.ItemClicked(ev, item)
})
details.child = l.AddChildAt(0, control)
}
details.mark = mark
details.index = idx
l.details[item] = details
c := details.child
cm := c.Control.Margin()
cs := itemSize.Contract(cm).Max(math.ZeroSize)
if l.orientation.Horizontal() {
c.Layout(math.CreateRect(d, cm.T, d+cs.W, cm.T+cs.H).Offset(o))
} else {
c.Layout(math.CreateRect(cm.L, d, cm.L+cs.W, d+cs.H).Offset(o))
}
d += majorAxisItemSize
}
// Reap unused items
for item, details := range l.details {
if details.mark != mark {
details.onClickSubscription.Unlisten()
l.RemoveChild(details.child.Control)
delete(l.details, item)
}
}
if l.scrollBarEnabled {
ss := l.scrollBar.DesiredSize(math.ZeroSize, s)
if l.Orientation().Horizontal() {
l.scrollBarChild.Layout(math.CreateRect(0, s.H-ss.H, s.W, s.H).Canon().Offset(o))
} else {
l.scrollBarChild.Layout(math.CreateRect(s.W-ss.W, 0, s.W, s.H).Canon().Offset(o))
}
// Only show the scroll bar if needed
entireContentVisible := startIndex == 0 && endIndex == l.itemCount
l.scrollBar.SetVisible(!entireContentVisible)
}
l.UpdateItemMouseOver()
}