summaryrefslogtreecommitdiffstatshomepage
path: root/separator.go
blob: e7cd64dd902e64e4d247e51d40cb38c3968582e1 (plain) (blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2017 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build windows

package walk

import (
	"github.com/lxn/win"
)

type Separator struct {
	WidgetBase
	vertical bool
}

func NewHSeparator(parent Container) (*Separator, error) {
	return newSeparator(parent, false)
}

func NewVSeparator(parent Container) (*Separator, error) {
	return newSeparator(parent, true)
}

func newSeparator(parent Container, vertical bool) (*Separator, error) {
	s := &Separator{vertical: vertical}

	if err := InitWidget(
		s,
		parent,
		"STATIC",
		win.WS_VISIBLE|win.SS_ETCHEDHORZ,
		0); err != nil {
		return nil, err
	}

	return s, nil
}

func (s *Separator) CreateLayoutItem(ctx *LayoutContext) LayoutItem {
	var layoutFlags LayoutFlags
	if s.vertical {
		layoutFlags = GrowableHorz | GreedyHorz
	} else {
		layoutFlags = GrowableVert | GreedyVert
	}

	return &separatorLayoutItem{
		layoutFlags: layoutFlags,
	}
}

type separatorLayoutItem struct {
	LayoutItemBase
	layoutFlags LayoutFlags
}

func (li *separatorLayoutItem) LayoutFlags() LayoutFlags {
	return li.layoutFlags
}

func (li *separatorLayoutItem) IdealSize() Size {
	return li.MinSize()
}

func (li *separatorLayoutItem) MinSize() Size {
	return SizeFrom96DPI(Size{2, 2}, li.ctx.dpi)
}