Added accept_failed callback hooks to provide feedback when the user attempts to submit a disabled field--this lets us do things like flash the text field red to get their attention.
This commit is contained in:
parent
3b985045cb
commit
4429b66c8d
|
|
@ -413,6 +413,18 @@ get_accept_prefix() {
|
|||
return "accept-";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PGEntry::get_accept_failed_prefix
|
||||
// Access: Published, Static
|
||||
// Description: Returns the prefix that is used to define the accept
|
||||
// failed event for all PGEntries. This event is the
|
||||
// concatenation of this string followed by get_id().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE string PGEntry::
|
||||
get_accept_failed_prefix() {
|
||||
return "acceptfailed-";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PGEntry::get_overflow_prefix
|
||||
// Access: Published, Static
|
||||
|
|
@ -460,6 +472,17 @@ get_accept_event(const ButtonHandle &button) const {
|
|||
return "accept-" + button.get_name() + "-" + get_id();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PGEntry::get_accept_failed_event
|
||||
// Access: Published
|
||||
// Description: Returns the event name that will be thrown when the
|
||||
// entry cannot accept an input
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE string PGEntry::
|
||||
get_accept_failed_event(const ButtonHandle &button) const {
|
||||
return "acceptfailed-" + button.get_name() + "-" + get_id();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PGEntry::get_overflow_event
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -215,6 +215,9 @@ press(const MouseWatcherParameter ¶m, bool background) {
|
|||
if (_accept_enabled) {
|
||||
accept(param);
|
||||
}
|
||||
else {
|
||||
accept_failed(param);
|
||||
}
|
||||
|
||||
} else if (button == KeyboardButton::backspace()) {
|
||||
// Backspace. Remove the character to the left of the cursor.
|
||||
|
|
@ -410,6 +413,21 @@ accept(const MouseWatcherParameter ¶m) {
|
|||
set_focus(false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PGEntry::accept_failed
|
||||
// Access: Public, Virtual
|
||||
// Description: This is a callback hook function, called whenever the
|
||||
// user presses Enter but we can't accept the input.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PGEntry::
|
||||
accept_failed(const MouseWatcherParameter ¶m) {
|
||||
PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param);
|
||||
string event = get_accept_failed_event(param.get_button());
|
||||
play_sound(event);
|
||||
throw_event(event, EventParameter(ep));
|
||||
//set_focus(false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PGEntry::overflow
|
||||
// Access: Public, Virtual
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ public:
|
|||
virtual void candidate(const MouseWatcherParameter ¶m, bool background);
|
||||
|
||||
virtual void accept(const MouseWatcherParameter ¶m);
|
||||
virtual void accept_failed(const MouseWatcherParameter ¶m);
|
||||
virtual void overflow(const MouseWatcherParameter ¶m);
|
||||
virtual void type(const MouseWatcherParameter ¶m);
|
||||
virtual void erase(const MouseWatcherParameter ¶m);
|
||||
|
|
@ -118,11 +119,13 @@ PUBLISHED:
|
|||
virtual void set_focus(bool focus);
|
||||
|
||||
INLINE static string get_accept_prefix();
|
||||
INLINE static string get_accept_failed_prefix();
|
||||
INLINE static string get_overflow_prefix();
|
||||
INLINE static string get_type_prefix();
|
||||
INLINE static string get_erase_prefix();
|
||||
|
||||
INLINE string get_accept_event(const ButtonHandle &button) const;
|
||||
INLINE string get_accept_failed_event(const ButtonHandle &button) const;
|
||||
INLINE string get_overflow_event() const;
|
||||
INLINE string get_type_event() const;
|
||||
INLINE string get_erase_event() const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue