07-30-2014 06:20 AM
LV 2013 SP1, Win7
For years OS X, and lately Windows, has had the idea of "Placeholder" text for string-entry fields (controls).
The idea is that if the field is blank, then it shows some help text ("enter your name here") in gray italics in the field.
It's gray to indicate that it's not the real text in that field.
As soon as you tab into or click into that field, the placeholder disappears, and the text you type is normal black.
If you leave the field (tab/click elsewhere), if the field is blank, the placeholder comes back; if not, the text you typed remains.
I have a situation where this is the perfect solution, but there is no built-in LV facility for doing it (Is it too late to sneak it into LV2014? 😉
The pseudo-code for what I want to do is this:
When writing control:
If new value == blank
Set control value to placeholder text
Set control font to gray/italics
else
Set control value to new value
Set control font to black/normal
end
When focus arrives:
If control font == gray
Set control value to blank
Set control font to black/normal
end
When focus leaves:
if control value == blank
Set control value to placeholder text
Set control font to gray/italics
else
Set control font to black/normal
end
When reading control:
if control font == gray
report blank
else
report control value
end
--- That seems easy enough, except I see no way for LV to trigger the focus arriving / leaving.
The EVENT structure has no such events.
I don't see an INVOKE NODE that would help.
I don't see a PROPERTY that would help.
I suppose I could detect a MOUSE DOWN .OR. KEY DOWN and use that as the FOCUS ARRIVES trigger.
That's a slight change in the behavior, but I could live with it.
But I don't see a way to detect the focus leaving.
Any ideas?
Blog for (mostly LabVIEW) programmers: Tips And Tricks
07-30-2014 06:26 AM - edited 07-30-2014 06:28 AM
Hi Steve,
you surely knew my LabVIEW Idea before…
In the comments you will find a (partially) workaround.
Other idea:
You could make your string control transparent and place your "placeholder text" behind the control to fake the ValueChange. Now you only need to change the background color of the string control whenever the string gets focus…
07-30-2014 06:52 AM
Hmmm. There is a VI method called "Find Control with Key Focus". That would mean polling though.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
07-30-2014 06:54 AM
you surely knew my LabVIEW Idea before…
No, I didn't, and don't call me Shirley. 😉
Blog for (mostly LabVIEW) programmers: Tips And Tricks
07-30-2014 07:08 AM
in the comments you will find a (partially) workaround.
That project has problems, though.
#1. it doesn't work in DevSys, only the EXE.
#2... It doesn't work when you TAB into/out of the Xctl. Only when you CLICK in / out.
#3... Clicking ANYWHERE produces the LOST FOCUS message, even if it didn't have focus. (comment 3 on the panel is incorrect)
Blog for (mostly LabVIEW) programmers: Tips And Tricks
07-30-2014 07:10 AM
You could make your string control transparent and place your "placeholder text" behind the control to fake the ValueChange. Now you only need to change the background color of the string control whenever the string gets focus…
Yes, but it's the "whenever the string gets focus" that is stumping me.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
07-30-2014 07:27 AM
For the record, the KEY FOCUS property takes 17 uSec to execute, when linked directly to a string control.
It takes 19 uSec when using a REFERENCE to the control.
using the FIND CTRL WITH KEY FOCUS method, it takes 2.4 uSec to execute that and compare the result to a known refererence.
This on a 3.4 GHz i7.
My guess is that KEY FOCUS property uses FIND CTRL WITH KEY FOCUS and looks for a match in a table.
But it doesn't seem to make a difference to the 17 uSec if there are two or twenty controls, so maybe not.
Anybody know if LV2014 includes this? I'm not a beta tester this year.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
07-30-2014 07:36 AM
The ViBox - XControls toolkit/addon/package from SAPHIR includes an XControl with this functionality (placeholder text in string controls)...
It's in the LabVIEW Tools Network:
vipm://saphir_lib_vibox_xcontrols?repo_url=http://ftp.ni.com/evaluation/labview/lvtn/vipm
http://www.saphir.fr/en/produits/vibox---xcontrols-9.html
Maybe that will fit the bill?
07-30-2014 02:21 PM
ViBox - XControls toolkit/addon/package from SAPHIR
That has license fees associated, my situation cannot handle that.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
07-30-2014 03:21 PM
The FIND CTRL with KEY FOCUS tells lies though.
Given a VI reference, it will tell you if a string control at the top level of that panel is focused.
If the control is inside a TAB, it will find it.
However, if the string control is inside a CLUSTER, it says there is no control with focus.
Blog for (mostly LabVIEW) programmers: Tips And Tricks