File size: 3,519 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/box-button-create {
  box-inline-create                % => Box
  dup box-button-setup-methods
  dup /box-button add-type
} def

/box-button-get-max-width {        % => Context Box
  box-container-get-max-width
} def

/box-button-get-min-width {        % => Context Box
  box-container-get-max-width
} def

/box-button-line-break-allowed {   % => Box
  pop false
} def

/box-button-reflow {
% Check if we need a line break here

  3 copy /maybe-line-break call-method
  pop

% Append to parent line box

  dup 2 index box-container-append-line

% Determine coordinates of upper-left corner

  2 copy
  box-generic-guess-corner       % => Context Parent This

% Determine the box width

  2 index 1 index
  /get-min-width call-method
  1 index put-full-width           % => Context Parent This

  2 index 1 index
  box-container-reflow-content     % => Context Parent This

% center the button text vertically inside the button

  dup get-content 0 get            % => Context Parent This Text
  dup get-top
  1 index get-height 2 div sub     % => Context Parent This Text TextMiddle
  2 index get-top
  3 index get-height 2 div sub     % => Context Parent This Text TextMiddle ThisMiddle
  sub

  neg 0                            % => Context Parent This Text -Delta 0
  2 index /offset call-method      % => Context Parent This Text
  pop                              % => Context Parent This

% Now set the baseline of a button box to align it vertically when flowing isude the  text line

  dup get-content 0 get
  get-default-baseline
  1 index get-extra-top add
  dup 2 index put-baseline
  1 index put-default-baseline

% Offset parent curernt X coordinate

  1 index get-current-x
  1 index get-full-width
  add
  2 index put-current-x

% Extend parent height

  dup get-bottom-margin
  1 index box-generic-extend-height
  
  pop pop pop
} def

/box-button-reflow-obsolete {               % => Context Parent This
% append to parent line box

  dup 2 index box-container-append-line

% Determine coordinates of upper-left _margin_ corner

  2 copy box-generic-guess-corner  % => Context Parent This

% Determine the box width

  2 index 1 index
  /get-min-width call-method
  1 index put-full-width           % => Context Parent This

  2 index 1 index
  box-container-reflow-content     % => Context Parent This

% Offset content to align vertically in the button
% Make the text centered vertically

  dup get-content 0 get            % => Context Parent This C0
  get-default-baseline 2 div       % => 
  1 index get-height 2 div add
  
  1 index get-content 0 get
  put-baseline

  2 index context-pop-collapsed-margin
  dup get-margin-bottom
  3 index context-push-collapsed-margin
                                   % => Context Parent This

  dup get-content 0 get
  get-baseline
  1 index get-extra-top add        % => Context Parent This DB
  1 index put-default-baseline     % => Context Parent This

% offset parent current X coordinate

  dup get-full-width
  2 index get-current-x add
  2 index put-current-x

% extends parents height

  dup get-bottom-margin
  2 index box-generic-extend-height

  pop pop pop
} def

/box-button-setup-methods {
  dup /Methods get
  dup /get-max-width {box-button-get-max-width} put
  dup /get-min-width {box-button-get-min-width} put
  dup /line-break-allowed {box-button-line-break-allowed} put
  dup /reflow {box-button-reflow} put
  dup /show  {box-button-show} put
  pop pop
} def

/box-button-show {             % => Viewport This
  box-container-show
} def