limit a text filed to the first 3 lines

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

limit a text filed to the first 3 lines

Post by link76 » Mon Jan 18, 2016 9:53 am

Hello,

I want to limit a text filed to the first 3 lines

Code: Select all

on keyDown thePressedKey

   if the number of lines of me  ....   

end keyDown
thank you,

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: limit a text filed to the first 3 lines

Post by Klaus » Mon Jan 18, 2016 11:24 am

Hi link7,

maybe something like this:

Code: Select all

on returninfield
   if the num of lines of me < 3 then
      pass returninfield
   end if
end returninfield

on enterinfield
     if the num of lines of me < 3 then
      pass enterinfield
   end if
end enterinfield
Tested and works!


Best

Klaus

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: limit a text filed to the first 3 lines

Post by AndyP » Mon Jan 18, 2016 11:29 am

or a slight variation

Code: Select all

on returninField
   if word 2 of the selectedLine of me >=3 then
      put line 1 to 3 of me into me
   else
      pass returninField
   end if
end returninField
Andy .... LC CLASSIC ROCKS!

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Contact:

Re: limit a text filed to the first 3 lines

Post by FredBeck » Mon Jan 18, 2016 11:36 am

Hi!
You're all assuming the don'tWrap property of the field is true!

Code: Select all

on keyDown
   if TypingAllowed() then
      pass keyDown
   end if
end keyDown

on rawKeyUp
   if not TypingAllowed() then
      repeat until TypingAllowed()
         delete last char of me
      end repeat
   end if
   pass rawKeyUp
end rawKeyUp

on returnInField
   if TypingAllowed() then pass returnInField
end returnInField

on enterInField
      if TypingAllowed() then pass enterInField
end enterInField

-----------------------------------------------------------

function TypingAllowed
   if the dontWrap of me then
      if the number lines in me < 4 then
         return true 
      end if
   else
      if the numberOfWrappedLines of me < 4 then
         return true 
      end if
   end if
   return false
end TypingAllowed

------------------------------------------------------------

getProp numberOfWrappedLines
   put the textHeightSum of me into tTextHeightSum
   if the fixedLineHeight of me then
      put the effective textHeight of me into tLineHeight
   else
      put the effective textSize of me into tLineHeight
   end if
   get tTextHeightSum / tLineHeight
   return it
end numberOfWrappedLines
Last edited by FredBeck on Mon Jan 18, 2016 11:45 am, edited 1 time in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: limit a text filed to the first 3 lines

Post by Klaus » Mon Jan 18, 2016 11:42 am

Hi Fred,
FredBeck wrote:You're all assuming the don'tWrap property of the field is true!
...
yes, we are just lazy! 8)


Best

Klaus

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Re: limit a text filed to the first 3 lines

Post by AndyP » Mon Jan 18, 2016 12:24 pm

Hmm.. I always assume things to be true ... unless proven false?
Andy .... LC CLASSIC ROCKS!

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Contact:

Re: limit a text filed to the first 3 lines

Post by FredBeck » Mon Jan 18, 2016 2:29 pm

Winter Monday morning deep in german continental climate... I feel for you, you're forgiven :mrgreen:

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: limit a text filed to the first 3 lines

Post by Klaus » Mon Jan 18, 2016 3:04 pm

Thank you, sir!

To my excuse, we are currently moving and are living out of boxes in the moment,
so many shelves, screws and nails to remove, so many things to put into these namely boxes...

I HATE IT! :D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: limit a text filed to the first 3 lines

Post by jacque » Mon Jan 18, 2016 10:42 pm

This may be a little easier:

Code: Select all

on keydown
  put (item 2 of the selectedloc of me + the vscroll of me) div (the effective textheight of me) into tLine
  if tLine < 3 then  pass keydown
end keydown
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply