GUI add Text, Bold & Normal on Same Line also end location of last text.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jwinfl
Posts: 86
Joined: 16 Aug 2017, 12:37

GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by jwinfl » 02 Oct 2022, 11:25

Thank you for viewing my post. I have two problems I need help with...

Problem 1
Line 103 in the following code, I would like the bold text (txt2) to be added immediately after the normal text (txt1) from Line 99. I would prefer to NOT use... xp+%txt1len% ... to locate the x position of the bold text because it assumes that each normal text character is 5 pixels wide, which is incorrect. I tried x+0 but that didn't work nor did xp+0 (puts the bold text over the normal text).

Code: Select all

#NoEnv  ; best ahk compatibility
SendMode Input  ; sendinput
#SingleInstance force  ; only 1 instance of script running
SetTitleMatchMode, 2 ; anywhere

data =
(
arrow  2 HEADS|HK|!+
arrow  CURVED 2 HEADS|HK|!^+
arrow  CURVED|HK|^+
arrow mcr  2 HEADS|DC|!^+2
arrow mcr  CURVED 2 HEADS|DC|!^+1
arrow mcr  CURVED|DC|+2
arrow mcr  STRAIGHT|DC|+.
change  ARROW SELECTION|HK|^#a
change  ARROW SETTINGS|HK|#a
change  DIM SELECTION|HK|^#d
change  DIM SETTINGS|HK|#d
change  LINE SELECTION|HK|^#l
change  LINE SETTINGS|HK|#l
change  TEXT SELECTION|HK|^#t
change  TEXT SETTINGS|HK|#t
change mcr  ARROW SELECTION|DC|^+2
change mcr  ARROW SETTINGS|DC|^+1
change mcr  DIM SELECTION|DC|!^2
change mcr  DIM SETTINGS|DC|!^1
change mcr  LINE SELECTION|DC|^2
change mcr  LINE SETTINGS|DC|^1
change mcr  TEXT SELECTION|DC|!+2
change mcr  TEXT SETTINGS|DC|!+1
copy  CIRCLE ARRAY|DC|!a
copy  CUT TO CB|DC|^x
copy  DUPLICATE|DC|c
dim  ANGLE BTWN 2 LINES|DC|<
dim  ANGLE|DC|!^a
dim  Add LEADER to AUTO|HK|f
dim  BALLON|DC|^b
dim  BEARING|DC|!^b
dim  COORDINATE|DC|!^+c
dim  DIMENSION|DC|d
dim  DISTANCE ONLY|DC|!^+d
dim  EXTENDED|DC|d
dim  PROGRESSIVE|DC|^d
dim  PULLOUT|DC|!
dim  RADIUS|DC|!r
dim  to AUTO|HK|f
dim mcr  TEXT ABOVE|DC|f7
dim mcr  TEXT BELOW|DC|f8
dim mcr  TEXT CENTER|DC|f9
dim mcr  TYPE EXTENDED|DC|f6
draw  ARC (CNT,BEGIN,END)|DC|a
draw  ARRAY COPY|DC|!c
draw  ARROW|DC|6
draw  ARROW|DC|>
draw  BOX|DC|b
draw  CIRCLE|DC|o
draw  CURVE|DC|+c
draw  ELIPSE|DC|^+e
draw  PLANE|DC|!^+9
draw  POINTMARK|DC|!^+p
draw  POLYGON (EDGE)|DC|+p
draw  SKETCH|DC|!^s
draw mcr  DETAIL (TITLE,#,SCALE)|DC|^f5
draw mcr  ELEV (BOX,DIRECTION)|DC|^f7
)
arr1 := strsplit(data,"`n")
label := [], action := [], task := [], parm := []
loop % arr1.maxindex()
{
	txt := arr1[a_index]
	arr2 := strsplit(txt,"|")
	label[a_index] := arr2[1]
	if strlen(label[a_index]) > max_chrs
		max_chrs := strlen(label[a_index])
	action[a_index] := arr2[2]
	task[a_index] := arr2[3]
	parm[a_index] := substr(arr2[4],1,-1)
}

clms := 3, rows := ceil(arr1.maxindex()/clms), txt_w := max_chrs*5.37, txt_h := 12, xx := 0, yy := -txt_h
Gui,MA: Color, FFFACE ; gui background color
Gui,MA: Font,s8 bold cBlack,Segoe UI
gui,MA:add,text,section x1 y1 w0 h0
loop,% label.maxindex()
{
	if ((a_index-1)/rows = (a_index-1)//rows) and (a_index >1)
	{
		yy := -txt_h
		xx += txt_w
	}
	yy += txt_h
	; Gui,MA:Add,Progress,x%xx% y%yy% w%txt_w% h%txt_h% Disabled BackgroundFFFACE
	Gui,MA:Add,Progress,x%xx% y%yy% w%txt_w% h%txt_h% Disabled +border BackgroundFFFACE
	gui,MA:Font,normal
	spcloc := instr(label[a_index],"  ")
	txt1 := substr(label[a_index],1,spcloc-1) "  "
	txt1len:=strlen(txt1)*5
	xxx:=a_index
	Gui,MA:Add,Text,x%xx% y%yy% wp hp cBlack BackgroundTrans left 0x200 v%a_index% gStart,% txt1
	; Gui,MA:Add,Text,x%xx% y%yy% wp hp cBlack BackgroundTrans left 0x200 gStart,% txt1
	gui,MA:Font,bold
	txt2 := substr(label[a_index],spcloc+2)
	Gui,MA:Add,Text,xp+%txt1len% y%yy% wp hp cBlack BackgroundTrans left 0x200 gStart,% txt2
	; Gui,MA:Add,Text,xp+%txt1len% y%yy% wp hp cBlack BackgroundTrans left 0x200 v%a_index% gStart,% txt2
}
gui_w := clms*txt_w, gui_h := (rows-2)*txt_h+5
Gui,MA: Show, xcenter ycenter w%gui_w% h%gui_h%, %GuiTitle%.xAs
Gui,MA: -Caption +border +AlwaysOnTop
OnMessage(0x201, "WM_LBUTTONDOWN") ; so gui can be moved by mouse
return

WM_LBUTTONDOWN() ; so gui can be moved on screen by mouse
{
	if a_gui = MA ; so Left Mouse Buttom can Drag Window
		PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}

start:
msgbox % a_guicontrol
return
Problem 2
I would like clicking ANYWHERE in any box (see picture of gui below) to set... a_guicontrol ...to the selection's number (a_index). Except for the first column, selecting the left side of a box (the normal text) stores the bold text (txt2) from the same line from the column to the left not the selection number, selecting the right side of the box (the bold text) seems to work.

Even this doesn't seem to be working as I expected, it appears that selecting the right side is doing the same thing as selecting the left side, the a_guicontrol is using the selection immediately to the left and not the selection area clicked, example; column 2 top box, clicking it's left side results in... 2 HEADS ... which was set by line 99 (column 1's bold text), clicking the right side column 2 top box results in... 20 ...which was set by line 103, (column 2's left side normal text).
image.png
image.png (45.04 KiB) Viewed 1528 times
Any help will be appreciated.

Thank you.

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by mikeyww » 02 Oct 2022, 15:58

Code: Select all

txt1 := SubStr(label[A_Index], 1, spcloc - 1)
txt2 := SubStr(label[A_Index], spcloc + 2)
Gui, MA:Add , Text, x%xx% y%yy% hp BackgroundTrans 0x200 gStart v%A_Index%, %txt1%
Gui, MA:Font, Bold
Gui, MA:Add , Text, x+0         hp BackgroundTrans 0x200 gStart           , %txt2%
image221002-1706-001.png
Output
image221002-1706-001.png (53.85 KiB) Viewed 1481 times

Code: Select all

start:
If A_GuiControl is number
     sel := SubStr(label[A_GuiControl], Instr(label[A_GuiControl], "  ") + 2)
Else sel := A_GuiControl
MsgBox, 64, Selection, %sel%
Return

jwinfl
Posts: 86
Joined: 16 Aug 2017, 12:37

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by jwinfl » 03 Oct 2022, 07:13

@mikeyww,

Thank you.

I modified the code as you suggested, see lines 99, 104, 123-126 in the code below.

The bold text goes where I wanted it to. Thanks again.
Note, in the code below I added two spaces between the normal and bold text.

The selection process unfortunately does NOT work as I had hoped it would.

I wanted to be able to select anywhere in any box and have the msgbox show the selection box's index number (a_index).

When I run the code, clicking either the normal or bold text results in the msgbox showing the box's bold text and NOT the selection box's index number (a_index).

Also, when I click anywhere right of the bold text inside any box, nothing happens, the msgbox is not activated at all.

Below is the code with the modifications you suggested...

Code: Select all

#NoEnv  ; best ahk compatibility
SendMode Input  ; sendinput
#SingleInstance force  ; only 1 instance of script running
SetTitleMatchMode, 2 ; anywhere

data =
(
arrow  2 HEADS|HK|!+
arrow  CURVED 2 HEADS|HK|!^+
arrow  CURVED|HK|^+
arrow mcr  2 HEADS|DC|!^+2
arrow mcr  CURVED 2 HEADS|DC|!^+1
arrow mcr  CURVED|DC|+2
arrow mcr  STRAIGHT|DC|+.
change  ARROW SELECTION|HK|^#a
change  ARROW SETTINGS|HK|#a
change  DIM SELECTION|HK|^#d
change  DIM SETTINGS|HK|#d
change  LINE SELECTION|HK|^#l
change  LINE SETTINGS|HK|#l
change  TEXT SELECTION|HK|^#t
change  TEXT SETTINGS|HK|#t
change mcr  ARROW SELECTION|DC|^+2
change mcr  ARROW SETTINGS|DC|^+1
change mcr  DIM SELECTION|DC|!^2
change mcr  DIM SETTINGS|DC|!^1
change mcr  LINE SELECTION|DC|^2
change mcr  LINE SETTINGS|DC|^1
change mcr  TEXT SELECTION|DC|!+2
change mcr  TEXT SETTINGS|DC|!+1
copy  CIRCLE ARRAY|DC|!a
copy  CUT TO CB|DC|^x
copy  DUPLICATE|DC|c
dim  ANGLE BTWN 2 LINES|DC|<
dim  ANGLE|DC|!^a
dim  Add LEADER to AUTO|HK|f
dim  BALLON|DC|^b
dim  BEARING|DC|!^b
dim  COORDINATE|DC|!^+c
dim  DIMENSION|DC|d
dim  DISTANCE ONLY|DC|!^+d
dim  EXTENDED|DC|d
dim  PROGRESSIVE|DC|^d
dim  PULLOUT|DC|!
dim  RADIUS|DC|!r
dim  to AUTO|HK|f
dim mcr  TEXT ABOVE|DC|f7
dim mcr  TEXT BELOW|DC|f8
dim mcr  TEXT CENTER|DC|f9
dim mcr  TYPE EXTENDED|DC|f6
draw  ARC (CNT,BEGIN,END)|DC|a
draw  ARRAY COPY|DC|!c
draw  ARROW|DC|6
draw  ARROW|DC|>
draw  BOX|DC|b
draw  CIRCLE|DC|o
draw  CURVE|DC|+c
draw  ELIPSE|DC|^+e
draw  PLANE|DC|!^+9
draw  POINTMARK|DC|!^+p
draw  POLYGON (EDGE)|DC|+p
draw  SKETCH|DC|!^s
draw mcr  DETAIL (TITLE,#,SCALE)|DC|^f5
draw mcr  ELEV (BOX,DIRECTION)|DC|^f7
)
arr1 := strsplit(data,"`n")
label := [], action := [], task := [], parm := []
loop % arr1.maxindex()
{
	txt := arr1[a_index]
	arr2 := strsplit(txt,"|")
	label[a_index] := arr2[1]
	if strlen(label[a_index]) > max_chrs
		max_chrs := strlen(label[a_index])
	action[a_index] := arr2[2]
	task[a_index] := arr2[3]
	parm[a_index] := substr(arr2[4],1,-1)
}

clms := 3, rows := ceil(arr1.maxindex()/clms), txt_w := max_chrs*5.37, txt_h := 12, xx := 0, yy := -txt_h
Gui,MA: Color, FFFACE ; gui background color
Gui,MA: Font,s8 bold cBlack,Segoe UI
gui,MA:add,text,section x1 y1 w0 h0
loop,% label.maxindex()
{
	if ((a_index-1)/rows = (a_index-1)//rows) and (a_index >1)
	{
		yy := -txt_h
		xx += txt_w
	}
	yy += txt_h
	; Gui,MA:Add,Progress,x%xx% y%yy% w%txt_w% h%txt_h% Disabled BackgroundFFFACE
	Gui,MA:Add,Progress,x%xx% y%yy% w%txt_w% h%txt_h% Disabled +border BackgroundFFFACE
	gui,MA:Font,normal
	spcloc := instr(label[a_index],"  ")
	txt1 := substr(label[a_index],1,spcloc-1) "  "
	txt1len:=strlen(txt1)*5
	xxx:=a_index
	Gui,MA:Add,Text,x%xx% y%yy% hp BackgroundTrans 0x200 gStart v%A_Index%,%txt1%
;;Gui,MA:Add,Text,x%xx% y%yy% wp hp cBlack BackgroundTrans left 0x200 v%a_index% gStart,% txt1
	; Gui,MA:Add,Text,x%xx% y%yy% wp hp cBlack BackgroundTrans left 0x200 gStart,% txt1
	gui,MA:Font,bold
	txt2 := substr(label[a_index],spcloc+2)
	Gui,MA:Add,Text,x+0 hp BackgroundTrans 0x200 gStart,%txt2%
;;Gui,MA:Add,Text,xp+%txt1len% y%yy% wp hp cBlack BackgroundTrans left 0x200 gStart,% txt2
	; Gui,MA:Add,Text,xp+%txt1len% y%yy% wp hp cBlack BackgroundTrans left 0x200 v%a_index% gStart,% txt2
}
gui_w := clms*txt_w, gui_h := (rows-2)*txt_h+5
; Gui,MA: Show, xcenter y600 w%gui_w% h%gui_h%, %GuiTitle%.xAs
Gui,MA: Show, x1000 y300 w%gui_w% h%gui_h%, %GuiTitle%
Gui,MA: -Caption +border +AlwaysOnTop
OnMessage(0x201, "WM_LBUTTONDOWN") ; so gui can be moved by mouse
return

WM_LBUTTONDOWN() ; so gui can be moved on screen by mouse
{
	if a_gui = MA ; so Left Mouse Buttom can Drag Window
		PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}

start:
;;msgbox % a_guicontrol
If A_GuiControl is number
     sel := SubStr(label[A_GuiControl], Instr(label[A_GuiControl], "  ") + 2)
Else sel := A_GuiControl
MsgBox, 64, Selection, %sel%
return

;#include D:\BACKUP\AUTO HOT KEYS\MyFunctions.ahk ; should be last line
Any help will be greatly appreciated.

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by mikeyww » 03 Oct 2022, 07:52

Below is a general idea that you can adjust. Since you have some duplicates, you will need to add a way to handle those. There are various ways, but the easiest way is probably to have each text listing be unique. For clicking to the right of text, you could think about how to extend the width of the text control.

Code: Select all

index := {}
...
txt2        := SubStr(label[A_Index], spcloc + 2)
index[txt2] := A_Index
...
start:
If A_GuiControl is number
     sel := A_GuiControl
Else sel := index[A_GuiControl]
MsgBox, 64, Selection, %sel%
Return
A demonstration is below.

Code: Select all

Gui, Font, s10
Gui, Add, Text, x210 w200 gClik Border BackgroundTrans   , Text3
Gui, Add, Text, x110 wp   gClik Border BackgroundTrans yp, Text2
Gui, Add, Text, x10  wp   gClik Border BackgroundTrans yp, Text1
Gui, Show, x100
Return

Clik:
MsgBox, 64, Control, %A_GuiControl%
Return

jwinfl
Posts: 86
Joined: 16 Aug 2017, 12:37

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by jwinfl » 04 Oct 2022, 08:03

@mikeyww

LETS START OVER...

In the code below...
Clicking any item, anywhere inside it's box results in the selection's number (a_index) in a_guicontrol, which is exactly what I want it to do.

Code: Select all

;; "D:\BACKUP\AUTO HOT KEYS\My Scripts\- code sent to forum bold text loc and click being a_index - Modification 2 .ahk"

#NoEnv  ; best ahk compatibility
SendMode Input  ; sendinput
#SingleInstance force  ; only 1 instance of script running

data =
(
Ads  GROCERIES|run|D:\BACKUP\AUTO HOT KEYS\My Scripts\GROCERY ADS.ahk
 Ad  Aldi|run|https://www.aldi.us/en/weekly-specials/our-weekly-ads/
 Ad  DollarGenMrkt|run|http://www2.dollargeneral.com/Savings/Circulars/Pages/index.aspx?_ga=2.227862749.1140476423.1547639923-1879981032.1539005445
 Ad  Publix|run|http://weeklyad.publix.com/Publix/BrowseByPage/Index/?StoreID=2500534&PromotionCode=Publix-180621&PromotionViewMode=1#PageNumber=1
 Ad  Save A Lot|run|https://savealot.com/grocery-stores/holiday-34691-126/#circular-wrap
 Ad  Sprouts|run|https://www.sprouts.com/weekly-ad/
 Ad  Winn Dixie|run|https://coupons.winndixie.com/weeklyad/?store=655&s=
ahk  FUNCTIONS     open|activate|D:\BACKUP\AUTO HOT KEYS\MyFunctions.ahk
ahk  FUNCTIONS      list|hk|.LF.
Alarm|run|D:\BACKUP\AUTO HOT KEYS\My Scripts\ALARM - Alarm with Notice .ahk
Amazon Site|run|https://www.amazon.com/?ref_=nav_custrec_signin
Amazon Music|run|https://music.amazon.com/
Amazon Prime Video|run|https://www.amazon.com/gp/video/storefront?filterId=OFFER_FILTER=PRIME
Bldg Code FL Res 2020|run|https://codes.iccsafe.org/content/FLRC2020P1
Browser - Chrome|run|C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Browser - Edge|run|C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
Browser - Internet Explorer|run|C:\Program Files\Internet Explorer\iexplore.exe
Calculator   open|hk|.CALC.
Calendar   show|run|https://www.timeanddate.com/calendar/?country=1
CB to Screen && File|hk|.CBS.
Chrome open Cookies|chrome|chrome://settings/siteData
Date Calculator   run|run|D:\BACKUP\AUTO HOT KEYS\My Scripts\DATE - Calculates New Date .ahk
DesignCAD|run|C:\Program Files (x86)\IMSIDesign\DesignCAD 3D Max 20\Dcad20.EXE
DESKTOP   open dir|run|D:\BACKUP\-  Desktop
Bidnapper|run|https://www.bidnapper.com/list.php3
Emails to File DB|activate|D:\VB6 Programs\Email\EMAIL to File\Email to File Database (save) .txt
Envelope Printer|run|D:\_ JLW\FORMS _ Mail\Envelopes\-  Envelopes  .xlsx
Excel - exe|run|C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE
File Compare Online|run|https://text-compare.com/#difference_3
Forum  AHK|run|https://www.autohotkey.com/boards/search.php?search_id=egosearch
Forum  AHK Web Search|run|https://www.autohotkey.com/search/
Forum  Android_Moto e|run|https://androidforums.com/devices/motorola-moto-e-2020.18499/
Forum  DesignCAD|run|https://forums.designcad.com/
Forum  Microsoft|run|https://answers.microsoft.com/en-us?auth=1
Forum  Notepad+|run|https://notepad-plus-plus.org/community/category/4/help-wanted
Forum  Outlook Slipstick|run|https://forums.slipstick.com/
Frontier   website|run|www.frontier.com
Garmin Express|run|C:\Program Files (x86)\Garmin\Express\express.exe
Google Store Apps|run|https://play.google.com/store/apps
GPS from Address|run|https://dash.geocod.io/auth/login
Hills Building Permits|run|http://www.hillsboroughcounty.org/index.aspx?NID=1068
Huricane noaa.gov|run|https://www.nhc.noaa.gov/refresh/graphics_at4+shtml/161142.shtml?cone#contents
Icons - jpg to icon|run|http://convertico.com/
Internet OFF|hk|.IOFF.
Internet On|hk|.ION.
Labels 8066 File Folder|run|D:\Computer Software\Avery\Avery Labels\. Avery 8066 - FILE FOLDER .docx
Labels 8066 1 Line|run|D:\Computer Software\Avery\Avery Labels\.Avery 8066 - 1 Line .docx
Labels 8066 2 Lines|run|D:\Computer Software\Avery\Avery Labels\.Avery 8066 - 2 Lines .docx
Labels 8066 3 Lines|run|D:\Computer Software\Avery\Avery Labels\.Avery 8066 - 3 Lines .docx
Labels 8066 4 Lines|run|D:\Computer Software\Avery\Avery Labels\.Avery 8066 - 4 Lines .docx
Labels Folder (Avery)|run|D:\Computer Software\Avery\Avery Labels
MyAssistant  move gui|run|D:\BACKUP\AUTO HOT KEYS\My Scripts\MY ASSISTANT - MOVE GUI .ahk
MyAssistant  open script|activate|D:\BACKUP\AUTO HOT KEYS\My Scripts\MY ASSISTANT.ahk
MyAssistant  edit list|activate|D:\BACKUP\AUTO HOT KEYS\Data Files\MyAssitantData.txt
)
GuiTitle := "MY ASSISTANTS SELECTIONS" ; gui wTitle
arr1 := strsplit(data,"`n")
label := [], action := [], task := [], parm := []
loop % arr1.maxindex()
{
	txt := arr1[a_index]
	arr2 := strsplit(txt,"|")
	label[a_index] := arr2[1]
	if strlen(label[a_index]) > max_chrs
		max_chrs := strlen(label[a_index])
	action[a_index] := arr2[2]
	task[a_index] := arr2[3]
	parm[a_index] := substr(arr2[4],1,-1)
}
clms := 6, rows := ceil(arr1.maxindex()/clms), txt_w := max_chrs*5.37, txt_h := 12, xx := 0, yy := -txt_h
Gui,MA: Color, Yellow ; gui background color
Gui,MA: Font,s8 bold cBlack,Segoe UI
gui,MA:add,text,section x1 y1 w0 h0
loop,% label.maxindex()
{
	if ((a_index-1)/rows = (a_index-1)//rows) and (a_index >1)
	{
		yy := -txt_h
		xx += txt_w
	}
	yy += txt_h
	Gui,MA:Add,Progress,xp x%xx% y%yy% w%txt_w% h%txt_h% Disabled BackgroundYellow +border
	Gui,MA:Add,Text,xp yp wp hp cBlack BackgroundTrans left 0x200 v%a_index% gStart,% label[a_index]
}
gui_w := clms*txt_w, gui_h := (rows-2)*txt_h+5
Gui,MA: Show, xcenter y600 w%gui_w% h%gui_h%, %GuiTitle%
OnMessage( 0x200, "WM_MOUSEMOVE2" ) ; so gui can be moved by mouse
Gui,MA: -Caption +border ;  +AlwaysOnTop
return
WM_MOUSEMOVE2( wparam, lparam, msg, hwnd ) ; so gui can be moved on screen by mouse
{
	if wparam = 1 ; so Left Mouse Buttom can Drag Window
		PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
	return
}

start:
msgbox % a_guicontrol
return
The gui window looks like this...
image.png
image.png (32.36 KiB) Viewed 1320 times
What I would like the code to also do, is allow me to make one or several labels show both normal and bold text while still being clickable anywhere inside the box containing the normal and bold text and still show the selection's number (a_index) in a_guicontrol or, if necessary, get the selection's number ( a_index) to the Start: (msgbox) some other way while allowing, either or both, bold and normal text, to have duplicates, etc.

Any help will be appreciated. Thank you.

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by mikeyww » 04 Oct 2022, 10:17

Here is a new idea based on your original script. The idea is basic: sees which control is under the mouse, and then reports the index number based on that information.

Code: Select all

data =
(
arrow  2 HEADS|HK|!+
arrow  CURVED 2 HEADS|HK|!^+
arrow  CURVED|HK|^+
arrow mcr  2 HEADS|DC|!^+2
arrow mcr  CURVED 2 HEADS|DC|!^+1
arrow mcr  CURVED|DC|+2
arrow mcr  STRAIGHT|DC|+.
change  ARROW SELECTION|HK|^#a
change  ARROW SETTINGS|HK|#a
change  DIM SELECTION|HK|^#d
change  DIM SETTINGS|HK|#d
change  LINE SELECTION|HK|^#l
change  LINE SETTINGS|HK|#l
change  TEXT SELECTION|HK|^#t
change  TEXT SETTINGS|HK|#t
change mcr  ARROW SELECTION|DC|^+2
change mcr  ARROW SETTINGS|DC|^+1
change mcr  DIM SELECTION|DC|!^2
change mcr  DIM SETTINGS|DC|!^1
change mcr  LINE SELECTION|DC|^2
change mcr  LINE SETTINGS|DC|^1
change mcr  TEXT SELECTION|DC|!+2
change mcr  TEXT SETTINGS|DC|!+1
copy  CIRCLE ARRAY|DC|!a
copy  CUT TO CB|DC|^x
copy  DUPLICATE|DC|c
dim  ANGLE BTWN 2 LINES|DC|<
dim  ANGLE|DC|!^a
dim  Add LEADER to AUTO|HK|f
dim  BALLON|DC|^b
dim  BEARING|DC|!^b
dim  COORDINATE|DC|!^+c
dim  DIMENSION|DC|d
dim  DISTANCE ONLY|DC|!^+d
dim  EXTENDED|DC|d
dim  PROGRESSIVE|DC|^d
dim  PULLOUT|DC|!
dim  RADIUS|DC|!r
dim  to AUTO|HK|f
dim mcr  TEXT ABOVE|DC|f7
dim mcr  TEXT BELOW|DC|f8
dim mcr  TEXT CENTER|DC|f9
dim mcr  TYPE EXTENDED|DC|f6
draw  ARC (CNT,BEGIN,END)|DC|a
draw  ARRAY COPY|DC|!c
draw  ARROW|DC|6
draw  ARROW|DC|>
draw  BOX|DC|b
draw  CIRCLE|DC|o
draw  CURVE|DC|+c
draw  ELIPSE|DC|^+e
draw  PLANE|DC|!^+9
draw  POINTMARK|DC|!^+p
draw  POLYGON (EDGE)|DC|+p
draw  SKETCH|DC|!^s
draw mcr  DETAIL (TITLE,#,SCALE)|DC|^f5
draw mcr  ELEV (BOX,DIRECTION)|DC|^f7
)
arr1 := strsplit(data,"`n")
label := [], action := [], task := [], parm := []
loop % arr1.maxindex()
{
txt := arr1[a_index]
arr2 := strsplit(txt,"|")
label[a_index] := arr2[1]
if strlen(label[a_index]) > max_chrs
max_chrs := strlen(label[a_index])
action[a_index] := arr2[2]
task[a_index] := arr2[3]
parm[a_index] := substr(arr2[4],1,-1)
}
clms := 3, rows := ceil(arr1.maxindex()/clms), txt_w := max_chrs*5.37, txt_h := 12, xx := 0, yy := -txt_h
Gui, MA:Color, FFFACE ; gui background color
Gui, MA:Font, s8 bold cBlack,Segoe UI
Gui, MA:Add, Text, Section x1 y1 w0 h0
Loop,% label.maxindex() {
 If ((a_index-1)/rows = (a_index-1)//rows) and (a_index >1) {
  yy := -txt_h
  xx += txt_w
 }
 yy += txt_h
 Gui, MA:Add, Progress,x%xx% y%yy% w%txt_w% h%txt_h% Disabled +border BackgroundFFFACE
 Gui, MA:Font, Normal
 spcloc := instr(label[a_index],"  ")
 txt1 := SubStr(label[A_Index], 1, spcloc - 1)
 txt2 := SubStr(label[A_Index], spcloc + 2)
 Gui, MA:Add , Text, x%xx% y%yy% hp BackgroundTrans 0x200 v%A_Index%, %txt1%
 Gui, MA:Font, Bold
 Gui, MA:Add , Text, x+0         hp BackgroundTrans 0x200           , %txt2%
}
gui_w := clms*txt_w, gui_h := (rows-2)*txt_h+5
Gui, MA:Show, x50 w%gui_w% h%gui_h%, %GuiTitle%.xAs
Gui, MA:-Caption +border +AlwaysOnTop
OnMessage(0x201, "WM_LBUTTONDOWN") ; so gui can be moved by mouse
Return

WM_LBUTTONDOWN() { ; So GUI can be moved on screen by mouse
 MouseGetPos,,,, control
 number := RegExReplace(control, "\D")
 MsgBox, 64, Index, % Instr(control, "Static") ? number // 2 : SubStr(number, 3)
 If (A_Gui = "MA")   ; So Left Mouse Buttom can Drag Window
  PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}

jwinfl
Posts: 86
Joined: 16 Aug 2017, 12:37

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by jwinfl » 04 Oct 2022, 10:58

@mikeyww

I tried the code, thank you.

It gets the selection number and displays normal and bold text using the wm_lbuttondown which was being used to move the gui.

Anyway to make the gui movable too, note, the only place for the left button to move the gui is the 5 pixels along the bottom since the gui has the same number of selections in each column?

One other question, you didn't see a way for the code in my LETS START OVER post above to have normal and bold text selections since it shows the correct selection number and is also moveable?

Thanks again for your help.

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by mikeyww » 04 Oct 2022, 11:44

Here is a way to show the index number and also enable the GUI to be moved.

Code: Select all

data =
(
arrow  2 HEADS|HK|!+
arrow  CURVED 2 HEADS|HK|!^+
arrow  CURVED|HK|^+
arrow mcr  2 HEADS|DC|!^+2
arrow mcr  CURVED 2 HEADS|DC|!^+1
arrow mcr  CURVED|DC|+2
arrow mcr  STRAIGHT|DC|+.
change  ARROW SELECTION|HK|^#a
change  ARROW SETTINGS|HK|#a
change  DIM SELECTION|HK|^#d
change  DIM SETTINGS|HK|#d
change  LINE SELECTION|HK|^#l
change  LINE SETTINGS|HK|#l
change  TEXT SELECTION|HK|^#t
change  TEXT SETTINGS|HK|#t
change mcr  ARROW SELECTION|DC|^+2
change mcr  ARROW SETTINGS|DC|^+1
change mcr  DIM SELECTION|DC|!^2
change mcr  DIM SETTINGS|DC|!^1
change mcr  LINE SELECTION|DC|^2
change mcr  LINE SETTINGS|DC|^1
change mcr  TEXT SELECTION|DC|!+2
change mcr  TEXT SETTINGS|DC|!+1
copy  CIRCLE ARRAY|DC|!a
copy  CUT TO CB|DC|^x
copy  DUPLICATE|DC|c
dim  ANGLE BTWN 2 LINES|DC|<
dim  ANGLE|DC|!^a
dim  Add LEADER to AUTO|HK|f
dim  BALLON|DC|^b
dim  BEARING|DC|!^b
dim  COORDINATE|DC|!^+c
dim  DIMENSION|DC|d
dim  DISTANCE ONLY|DC|!^+d
dim  EXTENDED|DC|d
dim  PROGRESSIVE|DC|^d
dim  PULLOUT|DC|!
dim  RADIUS|DC|!r
dim  to AUTO|HK|f
dim mcr  TEXT ABOVE|DC|f7
dim mcr  TEXT BELOW|DC|f8
dim mcr  TEXT CENTER|DC|f9
dim mcr  TYPE EXTENDED|DC|f6
draw  ARC (CNT,BEGIN,END)|DC|a
draw  ARRAY COPY|DC|!c
draw  ARROW|DC|6
draw  ARROW|DC|>
draw  BOX|DC|b
draw  CIRCLE|DC|o
draw  CURVE|DC|+c
draw  ELIPSE|DC|^+e
draw  PLANE|DC|!^+9
draw  POINTMARK|DC|!^+p
draw  POLYGON (EDGE)|DC|+p
draw  SKETCH|DC|!^s
draw mcr  DETAIL (TITLE,#,SCALE)|DC|^f5
draw mcr  ELEV (BOX,DIRECTION)|DC|^f7
)
arr1 := strsplit(data,"`n")
label := [], action := [], task := [], parm := []
loop % arr1.maxindex()
{
txt := arr1[a_index]
arr2 := strsplit(txt,"|")
label[a_index] := arr2[1]
if strlen(label[a_index]) > max_chrs
max_chrs := strlen(label[a_index])
action[a_index] := arr2[2]
task[a_index] := arr2[3]
parm[a_index] := substr(arr2[4],1,-1)
}
clms := 3, rows := ceil(arr1.maxindex()/clms), txt_w := max_chrs*5.37, txt_h := 12, xx := 0, yy := -txt_h
Gui, MA:Color, FFFACE ; gui background color
Gui, MA:Font, s8 bold cBlack,Segoe UI
Gui, MA:Add, Text, Section x1 y1 w0 h0
Loop,% label.maxindex() {
 If ((a_index-1)/rows = (a_index-1)//rows) and (a_index >1) {
  yy := -txt_h
  xx += txt_w
 }
 yy += txt_h
 Gui, MA:Add, Progress,x%xx% y%yy% w%txt_w% h%txt_h% Disabled +border BackgroundFFFACE
 Gui, MA:Font, Normal
 spcloc := instr(label[a_index],"  ")
 txt1 := SubStr(label[A_Index], 1, spcloc - 1)
 txt2 := SubStr(label[A_Index], spcloc + 2)
 Gui, MA:Add , Text, x%xx% y%yy% hp BackgroundTrans 0x200 v%A_Index%, %txt1%
 Gui, MA:Font, Bold
 Gui, MA:Add , Text, x+0         hp BackgroundTrans 0x200           , %txt2%
}
gui_w := clms*txt_w, gui_h := (rows-2)*txt_h+5
Gui, MA:Show, x50 w%gui_w% h%gui_h%, %GuiTitle%.xAs
Gui, MA:-Caption +border +AlwaysOnTop
OnMessage(0x201, "WM_LBUTTONDOWN") ; so gui can be moved by mouse
Return

#If WinExist("Index ahk_class AutoHotkeyGUI")
~LButton Up::Gui, Index:Destroy
#If

WM_LBUTTONDOWN() { ; So GUI can be moved on screen by mouse
 If (A_Gui != "MA")
  Return
 MouseGetPos,,,, control
 number := RegExReplace(control, "\D")
 Gui, Index:New, +OwnerMA
 Gui, Font, s16 w700
 Gui, Color, 93CC97
 Gui, Add, Text, w230, % "INDEX = " (Instr(control, "Static") ? number // 2 : SubStr(number, 3))
 Gui, Show, x200 y200 NoActivate, Index
 PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}

jwinfl
Posts: 86
Joined: 16 Aug 2017, 12:37

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by jwinfl » 05 Oct 2022, 04:32

@mikeyww

Thank you for your reply.

I think I figured out how to have your code go to Start: and show a msgbox instead of momentarily showing a gui with the index. That way I can do further processing after Start: which makes the script easier for me to understand.

I would appreciate it if you could take a look at the revised code (after line 97) and see if it looks ok to you?

Here is the revised code...

Code: Select all

data =
(
arrow  2 HEADS|HK|!+
arrow  CURVED 2 HEADS|HK|!^+
arrow  CURVED|HK|^+
arrow mcr  2 HEADS|DC|!^+2
arrow mcr  CURVED 2 HEADS|DC|!^+1
arrow mcr  CURVED|DC|+2
arrow mcr  STRAIGHT|DC|+.
change  ARROW SELECTION|HK|^#a
change  ARROW SETTINGS|HK|#a
change  DIM SELECTION|HK|^#d
change  DIM SETTINGS|HK|#d
change  LINE SELECTION|HK|^#l
change  LINE SETTINGS|HK|#l
change  TEXT SELECTION|HK|^#t
change  TEXT SETTINGS|HK|#t
change mcr  ARROW SELECTION|DC|^+2
change mcr  ARROW SETTINGS|DC|^+1
change mcr  DIM SELECTION|DC|!^2
change mcr  DIM SETTINGS|DC|!^1
change mcr  LINE SELECTION|DC|^2
change mcr  LINE SETTINGS|DC|^1
change mcr  TEXT SELECTION|DC|!+2
change mcr  TEXT SETTINGS|DC|!+1
copy  CIRCLE ARRAY|DC|!a
copy  CUT TO CB|DC|^x
copy  DUPLICATE|DC|c
dim  ANGLE BTWN 2 LINES|DC|<
dim  ANGLE|DC|!^a
dim  Add LEADER to AUTO|HK|f
dim  BALLON|DC|^b
dim  BEARING|DC|!^b
dim  COORDINATE|DC|!^+c
dim  DIMENSION|DC|d
dim  DISTANCE ONLY|DC|!^+d
dim  EXTENDED|DC|d
dim  PROGRESSIVE|DC|^d
dim  PULLOUT|DC|!
dim  RADIUS|DC|!r
dim  to AUTO|HK|f
dim mcr  TEXT ABOVE|DC|f7
dim mcr  TEXT BELOW|DC|f8
dim mcr  TEXT CENTER|DC|f9
dim mcr  TYPE EXTENDED|DC|f6
draw  ARC (CNT,BEGIN,END)|DC|a
draw  ARRAY COPY|DC|!c
draw  ARROW|DC|6
draw  ARROW|DC|>
draw  BOX|DC|b
draw  CIRCLE|DC|o
draw  CURVE|DC|+c
draw  ELIPSE|DC|^+e
draw  PLANE|DC|!^+9
draw  POINTMARK|DC|!^+p
draw  POLYGON (EDGE)|DC|+p
draw  SKETCH|DC|!^s
draw mcr  DETAIL (TITLE,#,SCALE)|DC|^f5
draw mcr  ELEV (BOX,DIRECTION)|DC|^f7
)
arr1 := strsplit(data,"`n")
label := [], action := [], task := [], parm := []
loop % arr1.maxindex()
{
txt := arr1[a_index]
arr2 := strsplit(txt,"|")
label[a_index] := arr2[1]
if strlen(label[a_index]) > max_chrs
max_chrs := strlen(label[a_index])
action[a_index] := arr2[2]
task[a_index] := arr2[3]
parm[a_index] := substr(arr2[4],1,-1)
}
clms := 3, rows := ceil(arr1.maxindex()/clms), txt_w := max_chrs*5.37, txt_h := 12, xx := 0, yy := -txt_h
Gui, MA:Color, FFFACE ; gui background color
Gui, MA:Font, s8 bold cBlack,Segoe UI
Gui, MA:Add, Text, Section x1 y1 w0 h0
Loop,% label.maxindex() {
 If ((a_index-1)/rows = (a_index-1)//rows) and (a_index >1) {
  yy := -txt_h
  xx += txt_w
 }
 yy += txt_h
 Gui, MA:Add, Progress,x%xx% y%yy% w%txt_w% h%txt_h% Disabled +border BackgroundFFFACE
 Gui, MA:Font, Normal
 spcloc := instr(label[a_index],"  ")
 txt1 := SubStr(label[A_Index], 1, spcloc - 1) "  "
 txt2 := SubStr(label[A_Index], spcloc + 2)
 Gui, MA:Add , Text, x%xx% y%yy% hp BackgroundTrans 0x200 v%A_Index%, %txt1%
 Gui, MA:Font, Bold
 Gui, MA:Add , Text, x+0         hp BackgroundTrans 0x200           , %txt2%
}
gui_w := clms*txt_w, gui_h := (rows-2)*txt_h+5
Gui, MA:Show, x1000 w%gui_w% h%gui_h%, %GuiTitle%
Gui, MA:-Caption +border +AlwaysOnTop
OnMessage(0x201, "WM_LBUTTONDOWN") ; selection made or move gui
Return

WM_LBUTTONDOWN()
{
 If (A_Gui != "MA")
  Return
 global index
 MouseGetPos,,,, control
 index := (Instr(control, "Static") ? RegExReplace(control, "\D") // 2 : SubStr(RegExReplace(control, "\D"), 3))
 if index
	gosub start
 PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}

start:
msgbox % index
return
Again thank you for all your help on this.

Jack

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by mikeyww » 05 Oct 2022, 06:17

It looks great if you don't need to move the GUI. That is why I added the other GUI.

jwinfl
Posts: 86
Joined: 16 Aug 2017, 12:37

Re: GUI add Text, Bold & Normal on Same Line also end location of last text.

Post by jwinfl » 05 Oct 2022, 07:35

@mikeyww ,

On my computer the gui moves the same as it did before.

You have to select an area where there are no boxes with text.

There are 3 areas where the mouse will move the gui...

1) anywhere along the bottom of the gui below the bottom text boxes down to the gui's bottom border (area is 5 pixels high), in the code; gui_h := (rows-2)*txt_h+5.

2) anywhere along the gui's right side border, between the end of the line below the text and the right side border.

3) if the last column has less selections than the other columns then selecting anywhere in the area below the last text box in the last column will also move it.

Again, thank you so much for your help on this.

Jack

Post Reply

Return to “Ask for Help (v1)”