Skip to content

Commit

Permalink
Introduce "invalid" text controls.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pulkomandy committed Oct 1, 2014
1 parent 48ea56b commit 13d147b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion headers/os/interface/ControlLook.h
Expand Up @@ -84,8 +84,9 @@ class BControlLook {
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;
Expand Down
4 changes: 3 additions & 1 deletion headers/os/interface/TextControl.h
Expand Up @@ -40,6 +40,7 @@ class BTextControl : public BControl {

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);
Expand Down Expand Up @@ -139,8 +140,9 @@ class BTextControl : public BControl {
float fDivider;

LayoutData* fLayoutData;
uint32 fLook;

uint32 _reserved[9];
uint32 _reserved[8];
};

#endif // _TEXT_CONTROL_H
14 changes: 13 additions & 1 deletion src/kits/interface/TextControl.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1122,6 +1132,8 @@ BTextControl::_InitData(const char* label, const BMessage* archive)

if (label)
fDivider = floorf(bounds.Width() / 2.0f);

fLook = 0;
}


Expand Down

0 comments on commit 13d147b

Please sign in to comment.