-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
page_non_editable_field.go
66 lines (58 loc) · 2.09 KB
/
page_non_editable_field.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 1998-2024 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package ux
import (
"github.com/richardwilkes/gcs/v5/model/gurps"
"github.com/richardwilkes/unison"
"github.com/richardwilkes/unison/enums/align"
)
// NonEditablePageField holds the data for a non-editable page field.
type NonEditablePageField struct {
*unison.Label
syncer func(*NonEditablePageField)
}
// NewNonEditablePageField creates a new start-aligned non-editable field that uses the same font and size as the page
// field.
func NewNonEditablePageField(syncer func(*NonEditablePageField)) *NonEditablePageField {
return newNonEditablePageField(syncer, align.Start)
}
// NewNonEditablePageFieldEnd creates a new end-aligned non-editable field that uses the same font and size as the page
// field.
func NewNonEditablePageFieldEnd(syncer func(*NonEditablePageField)) *NonEditablePageField {
return newNonEditablePageField(syncer, align.End)
}
// NewNonEditablePageFieldCenter creates a new center-aligned non-editable field that uses the same font and size as the
// page field.
func NewNonEditablePageFieldCenter(syncer func(*NonEditablePageField)) *NonEditablePageField {
return newNonEditablePageField(syncer, align.Middle)
}
func newNonEditablePageField(syncer func(*NonEditablePageField), hAlign align.Enum) *NonEditablePageField {
f := &NonEditablePageField{
Label: unison.NewLabel(),
syncer: syncer,
}
f.Self = f
f.Font = gurps.PageFieldPrimaryFont
f.HAlign = hAlign
f.SetBorder(unison.NewEmptyBorder(unison.Insets{
Left: 1,
Bottom: 1,
Right: 1,
})) // Match normal fields
f.SetLayoutData(&unison.FlexLayoutData{
HAlign: align.Fill,
VAlign: align.Middle,
})
f.Sync()
return f
}
// Sync the field to the current value.
func (f *NonEditablePageField) Sync() {
f.syncer(f)
}