Introduce "invalid" text controls.

* MarkAsInvalid is used to enable or disable the mark
* The B_INVALID BControlLook flag is used
* invalid BTextControls are drawn with a red border.
* You ar encouraged to let the user know more precisely what's wrong, by
showing an helpful error message next to the control or in a tooltip.
This commit is contained in:
Adrien Destugues
2014-10-01 12:12:16 +02:00
parent 48ea56bf32
commit 13d147b12b
3 changed files with 18 additions and 3 deletions
+2 -1
View File
@@ -84,8 +84,9 @@ public:
B_IGNORE_OUTLINE = 1 << 6,
B_PARTIALLY_ACTIVATED = 1 << 7, // like B_ACTIVATED, but for tri-state
B_FLAT = 1 << 8, // flat look (e.g. button background)
B_INVALID = 1 << 9, // invalid value, use B_FAILURE_COLOR
B_BLEND_FRAME = 1 << 16
B_BLEND_FRAME = 1 << 16,
};
virtual BAlignment DefaultLabelAlignment() const;
+3 -1
View File
@@ -40,6 +40,7 @@ public:
virtual void SetText(const char* text);
const char* Text() const;
void MarkAsInvalid(bool invalid);
virtual void SetValue(int32 value);
virtual status_t Invoke(BMessage* message = NULL);
@@ -139,8 +140,9 @@ private:
float fDivider;
LayoutData* fLayoutData;
uint32 fLook;
uint32 _reserved[9];
uint32 _reserved[8];
};
#endif // _TEXT_CONTROL_H
+13 -1
View File
@@ -333,6 +333,16 @@ BTextControl::Text() const
}
void
BTextControl::MarkAsInvalid(bool invalid)
{
if (invalid)
fLook |= BControlLook::B_INVALID;
else
fLook &= ~BControlLook::B_INVALID;
}
void
BTextControl::SetValue(int32 value)
{
@@ -425,7 +435,7 @@ BTextControl::Draw(BRect updateRect)
if (be_control_look != NULL) {
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 flags = 0;
uint32 flags = fLook;
if (!enabled)
flags |= BControlLook::B_DISABLED;
if (active)
@@ -1122,6 +1132,8 @@ BTextControl::_InitData(const char* label, const BMessage* archive)
if (label)
fDivider = floorf(bounds.Width() / 2.0f);
fLook = 0;
}