Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Limiting nbr. of characters in a 'field'
Pages: [1] Print
Author Topic: Limiting nbr. of characters in a 'field'  (Read 635 times)
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Limiting nbr. of characters in a 'field'
« on: June 10, 2004, 02:07:43 PM »

In wanting to guarantee the maximum number of characters enterable into a 'field' style....I think there is no 'facet' that does so. I note that I might use the 'size-text' function whose 'x' value seems to grow in proportion
to the number of characters entered....
length? seems to be for series...when I convert the 'field' content using 'form' I seem to get the same value rerturned no matter how many characters are in the 'field'.

i.e. : print [length? form num1]     ** num1 is a 'field'

I'm sure there is a better and easier way ??
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Limiting nbr. of characters in a 'field'
« Reply #1 on: June 10, 2004, 04:57:40 PM »

size-text measures the length and height of the pixels used by a string and so isn't any use to measure the number of characters in one.  Example from the console...

>> layout [t: text "abc"] size-text t
== 22x15
>> layout [t: text "123"] size-text t
== 23x15

length? is the right word to use as a string, like blocks and many other REBOL datatypes is a series...

>> series? "a"
== true

See?  :-)

One way to restrict what you can fit in a field is to have a focus face in its block.  A quick example...
Code:
view layout [
   field [
       if 4 <> length? face/text [
           focus face
           system/view/caret
           system/view/highlight-start:
           system/view/highlight-end:
           tail system/view/caret
           show face
       ]
   ]
   field
]
The extra code there controls the block-marking of the text .  (Play with it to get the effect you'd like.)  There, you're restricted to 4 characters in the first field.

(Sorry - a rushed post - supposed to be somewhere;)
Logged

- Carl Read
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Limiting nbr. of characters in a 'field'
« Reply #2 on: June 11, 2004, 05:50:58 AM »

Quote
i.e. : print [length? form num1]     ** num1 is a 'field'
 
What about print length? num1/text ?
Logged
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Limiting nbr. of characters in a 'field'
« Reply #3 on: June 11, 2004, 12:11:20 PM »

Thanks all....progress is being made.

Gabriele,     print [length? num1/text]
works well.

I'm surprised that print [length? face/text]  does  not,
as it seems as though the face being passed to the
function IS  num1 (or num2, or num3  etc.)

Carl,
   The sample view adds new understanding...I tried running it...didn't seem to limit the entry of characters.

I could test all (6) fields (num1, num2, num3..etc.) after
each keystroke...but that's hardly efficient. I assume
that even though at the moment the
  print [length? face/text]  fails i.e. requires a field name
     as noted above.....
there is a way to recognize which
of the (6) faces  is being processed at the moment when
the keystroke enters the function.
Again, I assumed that would be 'the face' in the argument block of 'key-event'......yet only the global
field name seems to satisfy the 'length?' function now.  
Logged
Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Limiting nbr. of characters in a 'field'
« Reply #4 on: June 12, 2004, 05:59:00 AM »

face in the event func you mean? That's the window, not the field. Event functions are processed at the point where the event has not reached the field face yet.
« Last Edit: June 12, 2004, 05:59:19 AM by Gabriele » Logged
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Limiting nbr. of characters in a 'field'
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 07, 2008, 01:28:23 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2240 Posts in 584 Topics by 2210 Members
Latest Member: Wqmsewzb

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc