usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / preferences / time / TZDisplay.cpp
blob1df7a4e4445666dfefe59ccc0f775726325981f2
1 /*
2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
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"
14 #include <stdio.h>
16 #include <LayoutUtils.h>
20 TTZDisplay::TTZDisplay(const char* name, const char* label)
22 BView(name, B_WILL_DRAW),
23 fLabel(label),
24 fText(""),
25 fTime("")
30 TTZDisplay::~TTZDisplay()
35 void
36 TTZDisplay::AttachedToWindow()
38 AdoptParentColors();
42 void
43 TTZDisplay::ResizeToPreferred()
45 BSize size = _CalcPrefSize();
46 ResizeTo(size.width, size.height);
50 void
51 TTZDisplay::Draw(BRect)
53 SetLowColor(ViewColor());
55 BRect bounds = Bounds();
56 FillRect(Bounds(), B_SOLID_LOW);
58 font_height height;
59 GetFontHeight(&height);
60 float fontHeight = ceilf(height.descent + height.ascent +
61 height.leading);
63 BPoint pt(bounds.left, ceilf(bounds.top + height.ascent));
64 DrawString(fLabel.String(), pt);
66 pt.y += fontHeight;
67 DrawString(fText.String(), pt);
69 pt.y -= fontHeight;
70 pt.x = bounds.right - StringWidth(fTime.String());
71 DrawString(fTime.String(), pt);
75 const char*
76 TTZDisplay::Label() const
78 return fLabel.String();
82 void
83 TTZDisplay::SetLabel(const char* label)
85 fLabel.SetTo(label);
86 Invalidate();
87 InvalidateLayout();
91 const char*
92 TTZDisplay::Text() const
94 return fText.String();
98 void
99 TTZDisplay::SetText(const char* text)
101 fText.SetTo(text);
102 Invalidate();
103 InvalidateLayout();
107 const char*
108 TTZDisplay::Time() const
110 return fTime.String();
114 void
115 TTZDisplay::SetTime(const char* time)
117 fTime.SetTo(time);
118 Invalidate();
119 InvalidateLayout();
123 BSize
124 TTZDisplay::MaxSize()
126 BSize size = _CalcPrefSize();
127 size.width = B_SIZE_UNLIMITED;
129 return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
130 size);
134 BSize
135 TTZDisplay::MinSize()
137 return BLayoutUtils::ComposeSize(ExplicitMinSize(),
138 _CalcPrefSize());
142 BSize
143 TTZDisplay::PreferredSize()
145 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(),
146 _CalcPrefSize());
150 BSize
151 TTZDisplay::_CalcPrefSize()
153 font_height fontHeight;
154 GetFontHeight(&fontHeight);
156 BSize size;
157 size.height = 2 * ceilf(fontHeight.ascent + fontHeight.descent +
158 fontHeight.leading);
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;
167 return size;