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()
39 SetViewColor(Parent()->ViewColor());
44 TTZDisplay::ResizeToPreferred()
46 BSize size
= _CalcPrefSize();
47 ResizeTo(size
.width
, size
.height
);
52 TTZDisplay::Draw(BRect
)
54 SetLowColor(ViewColor());
56 BRect bounds
= Bounds();
57 FillRect(Bounds(), B_SOLID_LOW
);
60 GetFontHeight(&height
);
61 float fontHeight
= ceilf(height
.descent
+ height
.ascent
+
64 BPoint
pt(bounds
.left
, ceilf(bounds
.top
+ height
.ascent
));
65 DrawString(fLabel
.String(), pt
);
68 DrawString(fText
.String(), pt
);
71 pt
.x
= bounds
.right
- StringWidth(fTime
.String());
72 DrawString(fTime
.String(), pt
);
77 TTZDisplay::Label() const
79 return fLabel
.String();
84 TTZDisplay::SetLabel(const char* label
)
93 TTZDisplay::Text() const
95 return fText
.String();
100 TTZDisplay::SetText(const char* text
)
109 TTZDisplay::Time() const
111 return fTime
.String();
116 TTZDisplay::SetTime(const char* time
)
125 TTZDisplay::MaxSize()
127 BSize size
= _CalcPrefSize();
128 size
.width
= B_SIZE_UNLIMITED
;
130 return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
136 TTZDisplay::MinSize()
138 return BLayoutUtils::ComposeSize(ExplicitMinSize(),
144 TTZDisplay::PreferredSize()
146 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
152 TTZDisplay::_CalcPrefSize()
154 font_height fontHeight
;
155 GetFontHeight(&fontHeight
);
158 size
.height
= 2 * ceilf(fontHeight
.ascent
+ fontHeight
.descent
+
161 // Add a little padding
162 float padding
= 10.0;
163 float firstLine
= ceilf(StringWidth(fLabel
.String()) +
164 StringWidth(" ") + StringWidth(fTime
.String()) + padding
);
165 float secondLine
= ceilf(StringWidth(fText
.String()) + padding
);
166 size
.width
= firstLine
> secondLine
? firstLine
: secondLine
;