/
frame.go
51 lines (44 loc) · 1.25 KB
/
frame.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2018, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package core
import (
"cogentcore.org/core/abilities"
"cogentcore.org/core/styles"
"cogentcore.org/core/units"
)
// Frame is a Layout that renders a background according to the
// background-color style setting, and optional striping for grid layouts
type Frame struct {
Layout
}
func (fr *Frame) OnInit() {
fr.Layout.HandleEvents()
fr.SetStyles()
}
func (fr *Frame) SetStyles() {
fr.Style(func(s *styles.Style) {
// note: using Clickable here so we get clicks, but don't change to Active state.
// getting clicks allows us to clear focus on click.
s.SetAbilities(true, abilities.Clickable)
s.Padding.Set(units.Dp(2))
s.Grow.Set(1, 1)
// we never want borders on frames
s.MaxBorder = styles.Border{}
})
fr.StyleFinal(func(s *styles.Style) {
s.SetAbilities(s.Overflow.X == styles.OverflowAuto || s.Overflow.Y == styles.OverflowAuto, abilities.Scrollable, abilities.Slideable)
})
}
func (fr *Frame) Render() {
fr.RenderStandardBox()
}
func (fr *Frame) RenderWidget() {
if fr.PushBounds() {
fr.Render()
fr.RenderChildren()
fr.RenderParts()
fr.RenderScrolls()
fr.PopBounds()
}
}