2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Andrew McCall <mccall@@digitalparadise.co.uk>
7 * Mike Berg <mike@berg-net.us>
8 * Julun <host.haiku@gmx.de>
9 * Hamish Morrison <hamish@lavabit.com>
12 #include "TZDisplay.h"
16 #include <LayoutUtils.h>
20 TTZDisplay::TTZDisplay(const char* name
, const char* label
)
22 BView(name
, B_WILL_DRAW
),
30 TTZDisplay::~TTZDisplay()
36 TTZDisplay::AttachedToWindow()
43 TTZDisplay::ResizeToPreferred()
45 BSize size
= _CalcPrefSize();
46 ResizeTo(size
.width
, size
.height
);
51 TTZDisplay::Draw(BRect
)
53 SetLowColor(ViewColor());
55 BRect bounds
= Bounds();
56 FillRect(Bounds(), B_SOLID_LOW
);
59 GetFontHeight(&height
);
60 float fontHeight
= ceilf(height
.descent
+ height
.ascent
+
63 BPoint
pt(bounds
.left
, ceilf(bounds
.top
+ height
.ascent
));
64 DrawString(fLabel
.String(), pt
);
67 DrawString(fText
.String(), pt
);
70 pt
.x
= bounds
.right
- StringWidth(fTime
.String());
71 DrawString(fTime
.String(), pt
);
76 TTZDisplay::Label() const
78 return fLabel
.String();
83 TTZDisplay::SetLabel(const char* label
)
92 TTZDisplay::Text() const
94 return fText
.String();
99 TTZDisplay::SetText(const char* text
)
108 TTZDisplay::Time() const
110 return fTime
.String();
115 TTZDisplay::SetTime(const char* time
)
124 TTZDisplay::MaxSize()
126 BSize size
= _CalcPrefSize();
127 size
.width
= B_SIZE_UNLIMITED
;
129 return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
135 TTZDisplay::MinSize()
137 return BLayoutUtils::ComposeSize(ExplicitMinSize(),
143 TTZDisplay::PreferredSize()
145 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
151 TTZDisplay::_CalcPrefSize()
153 font_height fontHeight
;
154 GetFontHeight(&fontHeight
);
157 size
.height
= 2 * ceilf(fontHeight
.ascent
+ fontHeight
.descent
+
160 // Add a little padding
161 float padding
= 10.0;
162 float firstLine
= ceilf(StringWidth(fLabel
.String()) +
163 StringWidth(" ") + StringWidth(fTime
.String()) + padding
);
164 float secondLine
= ceilf(StringWidth(fText
.String()) + padding
);
165 size
.width
= firstLine
> secondLine
? firstLine
: secondLine
;