1 package be
.nikiroo
.jexer
;
5 import jexer
.TScrollableWidget
;
7 import jexer
.event
.TResizeEvent
;
8 import jexer
.event
.TResizeEvent
.Type
;
10 public class TSizeConstraint
{
11 private TWidget widget
;
17 // TODO: include in the window classes I use?
19 public TSizeConstraint(TWidget widget
, Integer x1
, Integer y1
, Integer x2
,
28 public TWidget
getWidget() {
32 public Integer
getX1() {
33 if (x1
!= null && x1
< 0)
34 return widget
.getParent().getWidth() + x1
;
38 public Integer
getY1() {
39 if (y1
!= null && y1
< 0)
40 return widget
.getParent().getHeight() + y1
;
44 public Integer
getX2() {
45 if (x2
!= null && x2
<= 0)
46 return widget
.getParent().getWidth() - 2 + x2
;
50 public Integer
getY2() {
51 if (y2
!= null && y2
<= 0)
52 return widget
.getParent().getHeight() - 2 + y2
;
56 // coordinates < 0 = from the other side, x2 or y2 = 0 = max size
57 static public void setSize(List
<TSizeConstraint
> sizeConstraints
, TWidget child
,
58 Integer x1
, Integer y1
, Integer x2
, Integer y2
) {
59 sizeConstraints
.add(new TSizeConstraint(child
, x1
, y1
, x2
, y2
));
62 static public void resize(List
<TSizeConstraint
> sizeConstraints
) {
63 for (TSizeConstraint sizeConstraint
: sizeConstraints
) {
64 TWidget widget
= sizeConstraint
.getWidget();
65 Integer x1
= sizeConstraint
.getX1();
66 Integer y1
= sizeConstraint
.getY1();
67 Integer x2
= sizeConstraint
.getX2();
68 Integer y2
= sizeConstraint
.getY2();
76 widget
.setWidth(x2
- widget
.getX());
78 widget
.setHeight(y2
- widget
.getY());
80 // Resize the text field
81 // TODO: why setW/setH/reflow not enough for the scrollbars?
82 widget
.onResize(new TResizeEvent(Type
.WIDGET
, widget
.getWidth(),
85 if (widget
instanceof TScrollableWidget
) {
86 ((TScrollableWidget
) widget
).reflowData();