summaryrefslogtreecommitdiffstatshomepage
path: root/size.go
blob: 2f03857805c0b61d60b8c01112a2e1c73e6d50f4 (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
70
71
72
73
74
75
76
77
// Copyright 2010 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"

// Size defines width and height in 1/96" units or native pixels, or dialog base units.
//
// When Size is used for DPI metrics, it defines a 1"x1" rectangle in native pixels.
type Size struct {
	Width, Height int
}

func (s Size) IsZero() bool {
	return s.Width == 0 && s.Height == 0
}

func (s Size) toSIZE() win.SIZE {
	return win.SIZE{
		CX: int32(s.Width),
		CY: int32(s.Height),
	}
}

func minSize(a, b Size) Size {
	var s Size

	if a.Width < b.Width {
		s.Width = a.Width
	} else {
		s.Width = b.Width
	}

	if a.Height < b.Height {
		s.Height = a.Height
	} else {
		s.Height = b.Height
	}

	return s
}

func maxSize(a, b Size) Size {
	var s Size

	if a.Width > b.Width {
		s.Width = a.Width
	} else {
		s.Width = b.Width
	}

	if a.Height > b.Height {
		s.Height = a.Height
	} else {
		s.Height = b.Height
	}

	return s
}

func sizeFromSIZE(s win.SIZE) Size {
	return Size{
		Width:  int(s.CX),
		Height: int(s.CY),
	}
}

func sizeFromRECT(r win.RECT) Size {
	return Size{
		Width:  int(r.Right - r.Left),
		Height: int(r.Bottom - r.Top),
	}
}