Teadrinker pointed out that, for the right-to-left trimming, the spaces don't really need to be added back. Keeping that in mind, I came up with the below...
It's not as elegant as the Teadrinker regex solution, and probably not as efficient/fast, but it is easier to understand -- LOL.
I made the GUI background transparent, then put a duplicate (non-trimming) gui behind it, with gray letters. Now, rather than "trimming" it has the visual effect of changing colors from the outside-in. Pretty cool effect--Check it out. Also added an undo.
Now I need to figure out the best way to "lock" the GUIs together. I'll post a different thread for that though.
Thanks again Fellas!
Code: Select all
#SingleInstance
#Requires AutoHotkey v2+
; disappearing text experiment
Esc::ExitApp()
guiTitle := 'Color Change'
str := 'the quick brown fox jumps over the lazy dog'
undoArr := []
mgb := Gui(, guiTitle)
mg := Gui(, guiTitle)
mgb.SetFont('s16 q3','Consolas') ; q3 = NONANTIALIASED_QUALITY
mg.SetFont('s16 q3','Consolas')
mg.BackColor := "EEAA99"
WinSetTransColor("EEAA99", mg)
sGray := mgb.Add('text', ' cGray', str)
sBlue := mg.Add('text', ' cBlue', str)
mgb.Show()
mg.Show()
#hotif WinActive(guiTitle)
Right::sBlue.Text := ChangerL(sBlue.Text)
Left::sBlue.Text := ChangerR(sBlue.Text)
^z::sBlue.Text := goUndo(sBlue.Text)
#hotif
ChangerL(txt) ; Russ' Left to right
{ undoArr.push(txt)
sp_pos := 1
While SubStr(txt,sp_pos,1) = ' '
sp_pos += 1
txt := SubStr(txt,1,sp_pos-1) . ' ' . SubStr(txt,sp_pos + 1,StrLen(txt)- 1)
Return txt
}
ChangerR(txt) ; right to left
{ undoArr.push(txt)
txt := SubStr(txt, 1, -1)
Return txt
}
goUndo(*)
{ If undoArr.Length > 1
{ undoArr.pop
txt := undoArr[undoArr.Length]
Return txt
}
}