Browse Source

suggested changes from Clemens Pecinovsky to better support scrollable widgets

David Rose 17 years ago
parent
commit
5c45275656
3 changed files with 33 additions and 10 deletions
  1. 15 6
      panda/src/pgui/pgEntry.I
  2. 16 2
      panda/src/pgui/pgEntry.cxx
  3. 2 2
      panda/src/pgui/pgEntry.h

+ 15 - 6
panda/src/pgui/pgEntry.I

@@ -20,12 +20,16 @@
 //               entry.  This uses the Unicode encoding currently
 //               specified for the "focus" TextNode; therefore, the
 //               TextNode must exist before calling set_text().
+//
+//               The return value is true if all the text is accepted,
+//               or false if some was truncated (see set_max_width(),
+//               etc.).
 ////////////////////////////////////////////////////////////////////
-INLINE void PGEntry:: 
+INLINE bool PGEntry:: 
 set_text(const string &text) {
   TextNode *text_node = get_text_def(S_focus);
-  nassertv(text_node != (TextNode *)NULL);
-  set_wtext(text_node->decode_text(text));
+  nassertr(text_node != (TextNode *)NULL, false);
+  return set_wtext(text_node->decode_text(text));
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -519,15 +523,20 @@ get_erase_event() const {
 //       Access: Published
 //  Description: Changes the text currently displayed within the
 //               entry.
+//
+//               The return value is true if all the text is accepted,
+//               or false if some was truncated (see set_max_width(),
+//               etc.).
 ////////////////////////////////////////////////////////////////////
-INLINE void PGEntry:: 
+INLINE bool PGEntry:: 
 set_wtext(const wstring &wtext) {
-  _text.set_wtext(wtext);
+  bool ret = _text.set_wtext(wtext);
   if (_obscure_mode) {
-    _obscure_text.set_wtext(wstring(_text.get_num_characters(), '*'));
+    ret = _obscure_text.set_wtext(wstring(_text.get_num_characters(), '*'));
   }
   _text_geom_stale = true;
   set_cursor_position(min(_cursor_position, _text.get_num_characters()));
+  return ret;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 16 - 2
panda/src/pgui/pgEntry.cxx

@@ -239,14 +239,26 @@ press(const MouseWatcherParameter &param, bool background) {
         } else if (button == KeyboardButton::left()) {
           if (_cursor_keys_active) {
             // Left arrow.  Move the cursor position to the left.
-            _cursor_position = max(_cursor_position - 1, 0);
+            --_cursor_position;
+            if (_cursor_position < 0) {
+              _cursor_position = 0;
+              overflow(param);
+            } else {
+              type(param);    
+            }
             _cursor_stale = true;
           }
           
         } else if (button == KeyboardButton::right()) {
           if (_cursor_keys_active) {
             // Right arrow.  Move the cursor position to the right.
-            _cursor_position = min(_cursor_position + 1, _text.get_num_characters());
+            ++_cursor_position;
+            if (_cursor_position > _text.get_num_characters()) {
+              _cursor_position = _text.get_num_characters();
+              overflow(param);
+            } else {
+              type(param);
+            }
             _cursor_stale = true;
           }
           
@@ -255,6 +267,7 @@ press(const MouseWatcherParameter &param, bool background) {
             // Home.  Move the cursor position to the beginning.
             _cursor_position = 0;
             _cursor_stale = true;
+            type(param);
           }
           
         } else if (button == KeyboardButton::end()) {
@@ -262,6 +275,7 @@ press(const MouseWatcherParameter &param, bool background) {
             // End.  Move the cursor position to the end.
             _cursor_position = _text.get_num_characters();
             _cursor_stale = true;
+            type(param);
           }
         }          
       }

+ 2 - 2
panda/src/pgui/pgEntry.h

@@ -72,7 +72,7 @@ PUBLISHED:
   void setup(float width, int num_lines);
   void setup_minimal(float width, int num_lines);
 
-  INLINE void set_text(const string &text);
+  INLINE bool set_text(const string &text);
   INLINE string get_plain_text() const;
   INLINE string get_text() const;
 
@@ -127,7 +127,7 @@ PUBLISHED:
   INLINE string get_type_event() const;
   INLINE string get_erase_event() const;
 
-  INLINE void set_wtext(const wstring &wtext);
+  INLINE bool set_wtext(const wstring &wtext);
   INLINE wstring get_plain_wtext() const;
   INLINE wstring get_wtext() const;
   INLINE void set_accept_enabled(bool enabled);