Mail: change look of disabled text controls.

* Added HeaderTextControl that draws the text in black, and uses the
  panel background without a frame when it's disabled. Only the label
  is still drawn as disabled.
* Changed AddressTextControl to behave in the same way.
* The date view is now a HeaderTextControl, too.
* Unfortunately, the label is not vertically aligned with the contents.
This commit is contained in:
Axel Dörfler
2015-09-04 17:33:22 +02:00
parent 7bdee8beab
commit 4182c53bc4
4 changed files with 141 additions and 27 deletions
+11 -7
View File
@@ -36,7 +36,6 @@
static const uint32 kMsgAddAddress = 'adad'; static const uint32 kMsgAddAddress = 'adad';
static const float kHorizontalTextRectInset = 4.0;
static const float kVerticalTextRectInset = 2.0; static const float kVerticalTextRectInset = 2.0;
@@ -393,9 +392,9 @@ AddressTextControl::TextView::_AlignTextRect()
textRect.left = 0.0; textRect.left = 0.0;
float vInset = max_c(1, float vInset = max_c(1,
floorf((textRect.Height() - LineHeight(0)) / 2.0 + 0.5)); floorf((textRect.Height() - LineHeight(0)) / 2.0 + 0.5));
float hInset = kHorizontalTextRectInset;
if (be_control_look) float hInset = 0;
if (be_control_look != NULL)
hInset = be_control_look->DefaultLabelSpacing(); hInset = be_control_look->DefaultLabelSpacing();
textRect.InsetBy(hInset, vInset); textRect.InsetBy(hInset, vInset);
@@ -692,6 +691,9 @@ AddressTextControl::WindowActivated(bool active)
void void
AddressTextControl::Draw(BRect updateRect) AddressTextControl::Draw(BRect updateRect)
{ {
if (!IsEditable())
return;
BRect bounds(Bounds()); BRect bounds(Bounds());
rgb_color base(LowColor()); rgb_color base(LowColor());
uint32 flags = 0; uint32 flags = 0;
@@ -724,7 +726,7 @@ AddressTextControl::SetEnabled(bool enabled)
fPopUpButton->SetEnabled(enabled); fPopUpButton->SetEnabled(enabled);
_UpdateTextViewColors(enabled); _UpdateTextViewColors();
} }
@@ -959,13 +961,13 @@ AddressTextControl::_AddAddress(const char* text)
void void
AddressTextControl::_UpdateTextViewColors(bool enabled) AddressTextControl::_UpdateTextViewColors()
{ {
BFont font; BFont font;
fTextView->GetFontAndColor(0, &font); fTextView->GetFontAndColor(0, &font);
rgb_color textColor; rgb_color textColor;
if (enabled) if (!IsEditable() || IsEnabled())
textColor = ui_color(B_DOCUMENT_TEXT_COLOR); textColor = ui_color(B_DOCUMENT_TEXT_COLOR);
else { else {
textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
@@ -975,7 +977,9 @@ AddressTextControl::_UpdateTextViewColors(bool enabled)
fTextView->SetFontAndColor(&font, B_FONT_ALL, &textColor); fTextView->SetFontAndColor(&font, B_FONT_ALL, &textColor);
rgb_color color; rgb_color color;
if (enabled) if (!IsEditable())
color = ui_color(B_PANEL_BACKGROUND_COLOR);
else if (IsEnabled())
color = ui_color(B_DOCUMENT_BACKGROUND_COLOR); color = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
else { else {
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
+1 -1
View File
@@ -44,7 +44,7 @@ public:
private: private:
void _AddAddress(const char* text); void _AddAddress(const char* text);
void _UpdateTextViewColors(bool enabled); void _UpdateTextViewColors();
private: private:
class TextView; class TextView;
+125 -15
View File
@@ -104,6 +104,20 @@ private:
}; };
class HeaderTextControl : public BTextControl {
public:
HeaderTextControl(const char* label,
const char* name, BMessage* message);
virtual void AttachedToWindow();
virtual void SetEnabled(bool enabled);
virtual void Draw(BRect updateRect);
private:
void _UpdateTextViewColors();
};
// #pragma mark - LabelView // #pragma mark - LabelView
@@ -143,6 +157,101 @@ LabelView::Draw(BRect updateRect)
} }
// #pragma mark - HeaderTextControl
HeaderTextControl::HeaderTextControl(const char* label, const char* name,
BMessage* message)
:
BTextControl(label, name, message)
{
}
void
HeaderTextControl::AttachedToWindow()
{
BTextControl::AttachedToWindow();
_UpdateTextViewColors();
}
void
HeaderTextControl::SetEnabled(bool enabled)
{
BTextControl::SetEnabled(enabled);
_UpdateTextViewColors();
}
void
HeaderTextControl::Draw(BRect updateRect)
{
bool enabled = IsEnabled();
bool active = TextView()->IsFocus() && Window()->IsActive();
BRect rect = TextView()->Frame();
rect.InsetBy(-2, -2);
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 flags = 0;
if (!enabled)
flags = BControlLook::B_DISABLED;
if (enabled) {
if (active)
flags |= BControlLook::B_FOCUSED;
be_control_look->DrawTextControlBorder(this, rect, updateRect, base,
flags);
}
if (Label() != NULL) {
rect = CreateLabelLayoutItem()->Frame().OffsetByCopy(-Frame().left,
-Frame().top);
alignment labelAlignment;
GetAlignment(&labelAlignment, NULL);
be_control_look->DrawLabel(this, Label(), rect, updateRect,
base, flags, BAlignment(labelAlignment, B_ALIGN_MIDDLE));
}
}
void
HeaderTextControl::_UpdateTextViewColors()
{
BTextView* textView = TextView();
BFont font;
textView->GetFontAndColor(0, &font);
rgb_color textColor;
if (!textView->IsEditable() || IsEnabled())
textColor = ui_color(B_DOCUMENT_TEXT_COLOR);
else {
textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DISABLED_LABEL_TINT);
}
textView->SetFontAndColor(&font, B_FONT_ALL, &textColor);
rgb_color color;
if (!textView->IsEditable())
color = ui_color(B_PANEL_BACKGROUND_COLOR);
else if (IsEnabled())
color = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
else {
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_LIGHTEN_2_TINT);
}
textView->SetViewColor(color);
textView->SetLowColor(color);
}
// #pragma mark - THeaderView // #pragma mark - THeaderView
@@ -152,13 +261,13 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
fAccountID(defaultAccount), fAccountID(defaultAccount),
fFromControl(NULL), fFromControl(NULL),
fBccControl(NULL), fBccControl(NULL),
fDateView(NULL), fDateControl(NULL),
fIncoming(incoming), fIncoming(incoming),
fResending(resending) fResending(resending)
{ {
// From // From
if (fIncoming) { if (fIncoming) {
fFromControl = new BTextControl(B_TRANSLATE("From:"), NULL, NULL); fFromControl = new HeaderTextControl(B_TRANSLATE("From:"), NULL, NULL);
fFromControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fFromControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fFromControl->SetEnabled(false); fFromControl->SetEnabled(false);
} }
@@ -251,7 +360,7 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
} }
// Subject // Subject
fSubjectControl = new BTextControl(B_TRANSLATE("Subject:"), NULL, fSubjectControl = new HeaderTextControl(B_TRANSLATE("Subject:"), NULL,
new BMessage(SUBJECT_FIELD)); new BMessage(SUBJECT_FIELD));
msg = new BMessage(FIELD_CHANGED); msg = new BMessage(FIELD_CHANGED);
msg->AddInt32("bitmask", FIELD_SUBJECT); msg->AddInt32("bitmask", FIELD_SUBJECT);
@@ -261,17 +370,17 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
fSubjectControl->SetEnabled(false); fSubjectControl->SetEnabled(false);
// Date // Date
LabelView* dateLabel = NULL;
if (fIncoming) { if (fIncoming) {
dateLabel = new LabelView(B_TRANSLATE("Date:")); fDateControl = new HeaderTextControl(B_TRANSLATE("Date:"), NULL, NULL);
dateLabel->SetEnabled(false); fDateControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
fDateView = new BStringView("", ""); fDateControl->SetEnabled(false);
fDateView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
} }
BGridLayout* layout = GridLayout(); BGridLayout* layout = GridLayout();
layout->SetInsets(B_USE_DEFAULT_SPACING); layout->SetInsets(B_USE_DEFAULT_SPACING);
if (fIncoming)
layout->SetHorizontalSpacing(0);
layout->SetVerticalSpacing(B_USE_HALF_ITEM_SPACING); layout->SetVerticalSpacing(B_USE_HALF_ITEM_SPACING);
int32 row = 0; int32 row = 0;
@@ -297,9 +406,10 @@ THeaderView::THeaderView(bool incoming, bool resending, int32 defaultAccount)
layout->AddItem(fSubjectControl->CreateTextViewLayoutItem(), 1, row++, layout->AddItem(fSubjectControl->CreateTextViewLayoutItem(), 1, row++,
3, 1); 3, 1);
if (fDateView != NULL) { if (fDateControl != NULL) {
layout->AddView(dateLabel, 0, row); layout->AddItem(fDateControl->CreateLabelLayoutItem(), 0, row);
layout->AddView(fDateView, 1, row++, 3, 1); layout->AddItem(fDateControl->CreateTextViewLayoutItem(), 1, row++,
3, 1);
} }
} }
@@ -426,7 +536,7 @@ THeaderView::IsDateEmpty() const
const char* const char*
THeaderView::Date() const THeaderView::Date() const
{ {
return fDateView != NULL ? fDateView->Text() : NULL; return fDateControl != NULL ? fDateControl->Text() : NULL;
} }
@@ -435,7 +545,7 @@ THeaderView::SetDate(time_t date)
{ {
fDate = date; fDate = date;
if (fDateView != NULL) { if (fDateControl != NULL) {
BDateTimeFormat formatter; BDateTimeFormat formatter;
BString string; BString string;
@@ -449,8 +559,8 @@ THeaderView::SetDate(time_t date)
void void
THeaderView::SetDate(const char* date) THeaderView::SetDate(const char* date)
{ {
if (fDateView != NULL) if (fDateControl != NULL)
fDateView->SetText(date); fDateControl->SetText(date);
} }
+4 -4
View File
@@ -37,7 +37,6 @@ All rights reserved.
#include <GridView.h> #include <GridView.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <TextControl.h>
#include "AddressTextControl.h" #include "AddressTextControl.h"
@@ -48,6 +47,7 @@ class BMenuField;
class BMenuItem; class BMenuItem;
class BPopUpMenu; class BPopUpMenu;
class BStringView; class BStringView;
class HeaderTextControl;
class LabelView; class LabelView;
@@ -95,14 +95,14 @@ public:
private: private:
BPopUpMenu* fAccountMenu; BPopUpMenu* fAccountMenu;
int32 fAccountID; int32 fAccountID;
BTextControl* fFromControl; HeaderTextControl* fFromControl;
LabelView* fToLabel; LabelView* fToLabel;
AddressTextControl* fToControl; AddressTextControl* fToControl;
LabelView* fCcLabel; LabelView* fCcLabel;
AddressTextControl* fCcControl; AddressTextControl* fCcControl;
AddressTextControl* fBccControl; AddressTextControl* fBccControl;
BTextControl* fSubjectControl; HeaderTextControl* fSubjectControl;
BStringView* fDateView; HeaderTextControl* fDateControl;
time_t fDate; time_t fDate;
bool fIncoming; bool fIncoming;
bool fResending; bool fResending;