Hiding text in a field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mlapl1
Posts: 3
Joined: Fri Apr 13, 2007 11:15 pm

Hiding text in a field

Post by mlapl1 » Sat Apr 28, 2007 4:16 pm

Hello

How do I hide text in a field? In Toolbook I could simply use a command like:

hide text of field "ABC"

In runrev, the only way I can achieve this is to change the textcolor to be the same as that of the background. Is there some more generic way of doing this? I may want to change the background of a field and would prefer not to have to run through all my code to change the various textcolors that I may have set.

Many thanks
Andrew Lian

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Hiding text in a field

Post by marielle » Sat Apr 28, 2007 4:57 pm

mlapl1 wrote:hide text of field "ABC"
There is no such command. However it's not too difficult to implement. I would avoid to change the color of the text as it is too dependent on the formatting of the field itself. Furthermore, changing the color won't change the color of any link. Then, if no more is done than change the color, the user may still be able to select the text and even to cut or modify it (if permitted)

Code: Select all

...
put the long id of field "ABC" into tRef
hidetext tRef
...
showtext tRef
...

on hidetext pRef
  put the text of pRef into the cHiddenText of pRef
 set the text of pRef to empty
end hidetext

on showtext pRef
  set the text of pRef to the cHiddenText of pRef
  set the cHiddenText of pRef to empty
end showtext
If the text is formatted, use the htmltext rather than the text.

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Hiding text in a field

Post by marielle » Sat Apr 28, 2007 5:18 pm

Another solution is to display a white rectangle in front of the text box.

There is one button on the stack and one field, the button contains the following script:

Code: Select all

on mouseup
  put the long id of field 1 into tRef
  if the label of me is "show" then
    showtext tRef
    set the label of me to "hide"
  else
    hidetext tRef
    set the label of me to "show"
  end if
end mouseup

on hidetext pRef

  -- Deciding of a name to give to the graphic
  -- As we will delete it later, that's a good idea to add a prefix
  -- to make sure we won't delete the wrong object
  put the short name of pRef into tName
  put ("hider" & tName) into tName

  -- these 4 lines are to adjust the size of the rectangle
  -- so to avoid to hide the vertical or horizontal scrollbars if they
  -- exist
  put 0 into tMarginH
  if the hscrollbar of pRef is true then put the scrollbarWidth of pRef into tMarginH
  put 0 into tMarginV
  if the vscrollbar of pRef is true then put the scrollbarWidth of pRef into tMarginV

  -- Setting the format and appearance of the rectangle
  -- by defining the templateGraphic
  set the style of the templateGraphic to rectangle
  set the opaque of the templateGraphic to true
  set the linesize of the templateGraphic to 0
  set the backgroundcolor of the templateGraphic to white
  set the width of the templateGraphic to (the width of pRef-tMarginH-2)
  set the height of the templateGraphic to (the height of pRef -tMarginV- 2)
  set the left of the templateGraphic to (the left of pRef+1)
  set the top of the templateGraphic to (the top of pRef+1)

  -- Drawing the graphic on screen
  create graphic tName

end hidetext

on showtext pRef
  put the short name of pRef into tName
  put ("hider" & tName) into tName
  if exists(graphic tName) then delete graphic tName
end showtext
using templategraphic allows you to pop the graphic on screen without having to use lock screen. You can of course first create the graphic and reformat it, but then you will need to use lock screen to avoid the format changes to be visible to the user.

mlapl1
Posts: 3
Joined: Fri Apr 13, 2007 11:15 pm

Thank you

Post by mlapl1 » Sat Apr 28, 2007 7:21 pm

Thank you very much for your help. At first sight, I prefer the first solution as it appears more elegant and more generalisable.

Cheers
Andrew

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Re: Thank you

Post by marielle » Sat Apr 28, 2007 9:32 pm

mlapl1 wrote:I prefer the first solution as it appears more elegant and more generalisable.
Excellent choice :-). Note however that there is a reason I introduced the second one. This has to do with standalone releases. I let you discover the issue with the first option and report back here on how you addressed that problem (there is a better solution than the drawing rectangle option). Sorry, I am a facetious teacher ;-).

Post Reply