Code: Select all
the_arr=
(
The standard Lorem Ipsum passage, used since the 1500s
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
)
the_arr:=StrSplit(the_arr, a_space , "`r`n.,")
the_sorted_arr_acending:=sort_by_length(the_arr)
ScrollBox("Unsorted `n`n" st_printarr(the_arr),"P")
ScrollBox("Sorted ascending ?? `n`n >> Not working !! `n`n " . st_printarr(the_sorted_arr_acending),"P")
exitapp
sort_by_length(the_arr){
;create a new array. Set an element's string length as its key and write to the new array :clap: I feel clever. :crazy:
arr_temp:=[]
for key, val in the_arr
{
this_len:= strlen(val)
if (arr_temp[this_len]="") {
ObjRawSet(arr_temp, this_len, val)
} else {
arr_temp.InsertAt(this_len, val)
}
}
return arr_temp
}
;String Things by tidbit
;https://autohotkey.com/boards/viewtopic.php?f=6&t=53&sid=5c401643235e7a2e73d769f1e5deac0f
st_printArr(array, depth=5, indentLevel="")
{
for k,v in Array
{
list.= indentLevel "[" k "]"
if (IsObject(v) && depth>1)
list.="`n" st_printArr(v, depth-1, indentLevel . " ")
Else
list.=" => " v
list.="`n"
}
return rtrim(list)
}
; ScrollBox by Fanatic Guru v 2015 04 29 Version 1.10
;https://autohotkey.com/boards/viewtopic.php?f=6&t=4837
ScrollBox(String := "", Options := "", Label := "")
{
Static Gui_List, Gui_Index
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" :
SetWinDelay, % (Setting_A_WinDelay := A_WinDelay) ? 0 : 0
if !Gui_List
Gui_List := {}
if Label
{
Gui_Label := "ScrollBox_Gui_Label_" RegExReplace(Label, "i)[^0-9a-z#_@\$]", "")
Gui_Hwnd := Gui_List[Gui_Label]
Win_Hwnd := DllCall("GetParent", UInt, Gui_Hwnd)
if RegExMatch(RegExReplace(Options, "\{.*}"), "i)d")
Gui, %Gui_Label%:Destroy
else if WinExist("ahk_id " Win_Hwnd)
{
if String
GuiControl,,%Gui_Hwnd%, %String%
WinGetPos, WinX, WinY, WinW, WinH
if RegExMatch(Options, "i)x(\d+)", Match)
WinX := Match1
if RegExMatch(Options, "i)y(\d+)", Match)
WinY := Match1
if RegExMatch(Options, "i)w(\d+)", Match)
WinW := Match1
if RegExMatch(Options, "i)h(\d+)", Match)
WinH := Match1
Winmove, ahk_id %Win_Hwnd%,, WinX, WinY, WinW, WinH
if RegExMatch(Options, "i)h(?!\d)", Match)
Gui, %Gui_Label%:Hide
if RegExMatch(Options, "i)s", Match)
Gui, %Gui_Label%:Show
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
SetWinDelay, %Setting_A_WinDelay%
return
}
}
else
{
Gui_Index ++
Gui_Label := "ScrollBox_Gui_Label_" Gui_Index
}
if (!String and !Options)
{
if Label
{
Gui_List.Delete(Gui_Label)
Gui, %Gui_Label%:Destroy
}
else
{
for key, element in Gui_List
Gui, %key%:Destroy
Gui_List := {}
}
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
SetWinDelay, %Setting_A_WinDelay%
return
}
Gui %Gui_Label%:Default
Gui +LabelAllGui
Adjust1 := 10
ButtonPushed := -2
if RegExMatch(Options, "i)f(\d+)", Match)
{
Gui, Font, s%Match1%
Adjust1 := Match1
}
else if RegExMatch(Options, "i)f\{(.*)}", Match)
{
Options := RegExReplace(Options, "i)f\{.*}")
StringSplit, Match, Match1, `,
Gui, Font, %Match1%, % Trim(Match2)
RegExMatch(Match1, "i)s(\d+)", Adjust)
}
else
Gui, Font
Gui, Margin, 20, 20
Gui, +MinSize200x200 +Resize
Gui, Color, FFFFFF
Opt := "hwndGui_Hwnd ReadOnly -E0x200 "
if !(Options ~= "i)w(?!\d)")
Opt .= "+0x300000 -wrap "
if RegExMatch(Options, "i)h(\d+)", Match)
Opt .= "h" Match1 " ", Control := true
if RegExMatch(Options, "i)w(\d+)", Match)
Opt .= "w" Match1 " ", Control := true
if (Options ~= "i)c")
Opt .= "center "
if (Options ~= "i)l")
Opt .= "left "
if (Options ~= "i)r")
Opt .= "right "
Opt_Show := "AutoSize "
if RegExMatch(Options, "i)x(\d+)", Match)
Opt_Show .= "x" Match1 " "
if RegExMatch(Options, "i)y(\d+)", Match)
Opt_Show .= "y" Match1 " "
if Control
{
Gui, Add, Edit, % Opt
GuiControl, , %Gui_Hwnd%, %String%
}
else
Gui, Add, Edit, % Opt, %String%
if RegExMatch(Options, "i)b(1|2)", Match)
{
Button := Match1
if (Button = 1)
Gui, Add, Button, gAllGuiButtonOK hwndScrollBox_Button1_Hwnd Default, OK
else
{
Gui, Add, Button, gAllGuiButtonYES hwndScrollBox_Button1_Hwnd Default, YES
Gui, Add, Button, gAllGuiButtonNO hwndScrollBox_Button2_Hwnd, % " NO "
}
}
Gui, Show, % Opt_Show, % Label ? Label : "ScrollBox"
Gui_List[Gui_Label] := Gui_Hwnd
Win_Hwnd := DllCall("GetParent", UInt, Gui_Hwnd)
WinGetPos,X,Y,W,H, ahk_id %Win_Hwnd%
WinMove, ahk_id %Win_Hwnd%,,X,Y,W-1,H-1 ; Move
WinMove, ahk_id %Win_Hwnd%,,X,Y,W,H ; And Move Back to Force Recalculation of Margins
if Button
ControlSend,,{Tab}{Tab}+{Tab}, ahk_id %Gui_Hwnd% ; Move to Button
else
ControlSend,,^{Home}, ahk_id %Gui_Hwnd% ; Unselect Text and Move to Top of Control
DllCall("HideCaret", "Int", Gui_Hwnd)
if ((Options ~= "i)p(?!\d)") or (!(Options ~= "i)p") and Button))
while (ButtonPushed = -2)
Sleep 50
else if RegExMatch(Options, "i)p(\d+)", Match)
{
TimeEnd := A_TickCount + Match1
while (A_TickCount < TimeEnd and ButtonPushed = -2)
Sleep 50
Gui_List.Delete(Gui_Label)
Gui, Destroy
}
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
SetWinDelay, %Setting_A_WinDelay%
return ButtonPushed
AllGuiSize:
Resize_Gui_Hwnd := Gui_List[A_Gui]
if Button
{
if (Button = 1)
{
EditWidth := A_GuiWidth - 20
EditHeight := A_GuiHeight - 20 - (Adjust1 * 3)
ButtonX := EditWidth / 2 - Adjust1
ButtonY := EditHeight + 20 + (Adjust1/6)
GuiControl, Move, %Resize_Gui_Hwnd%, W%EditWidth% H%EditHeight%
GuiControl, Move, %ScrollBox_Button1_Hwnd%, X%ButtonX% Y%ButtonY%
}
else
{
EditWidth := A_GuiWidth - 20
EditHeight := A_GuiHeight - 20 - (Adjust1 * 3)
Button1X := EditWidth / 4 - (Adjust1 * 2)
Button2X := 3 * EditWidth / 4 - (Adjust1 * 1.5)
ButtonY := EditHeight + 20 + (Adjust1/6)
GuiControl, Move, %Resize_Gui_Hwnd%, W%EditWidth% H%EditHeight%
GuiControl, Move, %ScrollBox_Button1_Hwnd%, X%Button1X% Y%ButtonY%
GuiControl, Move, %ScrollBox_Button2_Hwnd%, X%Button2X% Y%ButtonY%
}
}
else
{
EditWidth := A_GuiWidth - 20
EditHeight := A_GuiHeight - 20
GuiControl, Move, %Resize_Gui_Hwnd%, W%EditWidth% H%EditHeight%
}
return
AllGuiButtonOK:
ButtonPushed := 1
Gui, %A_Gui%:Destroy
Gui_List.Delete(A_Gui)
return
AllGuiButtonYES:
ButtonPushed := 1
Gui, %A_Gui%:Destroy
Gui_List.Delete(A_Gui)
return
AllGuiButtonNO:
ButtonPushed := 0
Gui, %A_Gui%:Destroy
Gui_List.Delete(A_Gui)
return
AllGuiEscape:
AllGuiClose:
ButtonPushed := -1
Gui, %A_Gui%:Destroy
Gui_List.Delete(A_Gui)
return
}