Override font for inputselect()?

Features wanted...
Post Reply
highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Override font for inputselect()?

Post by highend »

I know this is very specific but most people probably don't have a font setting for "Buttons and labels" that uses a fixed-size font like Consolas...

Formatting output for inputselect() where you want to have a divider always at the same position is a pain in the a** because imho there isn't a 100% reliable way to do this with tabs.
Spaces are perfect and can be calculated accurately but only if a fixed-size font is used. So... Would it be possible to give that command another parameter "font=<font>,<style>,<size>" which would allow us to override the current configured one? If <style> and <size> are left out, they could be retrieved from the current configured one...

A demo script:

Code: Select all

    $relationShips = <<<>>>
ShowDragStatusBox <--> General | Safety Belts, Network | Safety Belts | Show drag status box
DisallowDragging <--> General | Safety Belts, Network | Safety Belts | Disallow left-dragging from folder tree
DisallowDraggingFromList <--> General | Safety Belts, Network | Safety Belts | Disallow left-dragging from file list
ConfirmDrop <--> General | Safety Belts, Network | Safety Belts | Confirm drag and drop
ConfirmFileOp <--> General | Safety Belts, Network | Safety Belts | Confirm copy and move operations
ConfirmFileDelete <--> General | Safety Belts, Network | Safety Belts | Confirm delete operations
DeleteOnKeyUp <--> General | Safety Belts, Network | Safety Belts | Delete on key up
DisallowDeleteByKeyTree <--> General | Safety Belts, Network | Safety Belts | Disallow delete by key in folder tree
PortableDevicesReadOnly <--> General | Safety Belts, Network | Safety Belts | Treat portable devices as read-only
DFCProtection <--> General | Safety Belts, Network | Safety Belts | Directional formatting codes protection
NetworkNetServerEnum <--> General | Safety Belts, Network | Network | Fast network enumeration
AssumeServersExist <--> General | Safety Belts, Network | Network | Assume that servers are available
NetworkPrecheckServers <--> General | Safety Belts, Network | Network | Pre-check availability of servers
CacheServers <--> General | Safety Belts, Network | Network | Cache network servers
>>>;

    // Reformat $relationShips
    $iniKeys = regexreplace($relationShips, "^([^ ]+)([ ].*?)(?=\r?\n|$)", "$1");
    // Get longest iniKey
    $maxLen = 0;
    foreach($entry, $iniKeys, <crlf>, "e") {
        $len = strlen($entry);
        if ($len > $maxLen) { $maxLen = $len; }
    }
    // Reformat by longest iniKey as reference
    $newRelationShips = "";
    foreach($line, $relationShips, <crlf>, "e") {
        $iniKey    = regexreplace($line, "^([^ ]+)([ ].+?$)", "$1");
        $guiKey    = regexreplace($line, "^(.+ <--> )(.+?$)", "$2");
        $lenIniKey = strlen($iniKey);
        $padding   = $maxLen - $lenIniKey;
        $newRelationShips .= $iniKey . strrepeat(<space>, $padding) . " <--> " . $guiKey . <crlf>;
        // $padding   = ($maxLen - $lenIniKey) / 4;
        // $newRelationShips .= $iniKey . strrepeat(<tab>, $padding) . " <-->" . <tab> . $guiKey . <crlf>;
    }
    $sel = inputselect("Type to find...", $newRelationShips, <crlf>, 4+32+64+4096, , 800, 600);
Spaces used, Consolas font:
spaces.png
spaces.png (22.07 KiB) Viewed 2135 times
Tabs used, Segoe UI font:
tabs.png
tabs.png (20.57 KiB) Viewed 2134 times
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60567
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Override font for inputselect()?

Post by admin »

How about this:

Code: Select all

    + SC inputselect enhanced: Now you can use the Edit Text font in the list, 
      just pass bit 16384 in the style argument.
      Syntax: inputselect(header, listdata, [separator="|"], [style=1], _
                  [cancel], [width=800], [height=400], [windowcaption], [preselect])
        style: 
         16384 = Use Edit Text font (instead of the default Buttons and Labels font).
      Examples:
        text inputselect("Test", listfolder(), , 1);          // Buttons and Labels font
        text inputselect("Test", listfolder(), , 1 + 16384);  // Edit Text font

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Override font for inputselect()?

Post by highend »

Yeah, that's perfectly fine and works great with the new beta. Thanks!
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Override font for inputselect()?

Post by klownboy »

I've been experimenting with your alignment examples above highend and Don's new flag (16384) for inputselect. The results look great. From what I can tell this is not possible to achieve currently using popupmenu? It would be a nice addition to SC popupmenu (for the "caption" section of itemlist) if we could use a fixed font as well such that we could achieve a similar caption list text alignment.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Override font for inputselect()?

Post by highend »

From what I can tell this is not possible to achieve currently using popupmenu?
If Don is using the windows api to construct these menus, afaik not.
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60567
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Override font for inputselect()?

Post by admin »

No, Windows dominates the menu font.

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Override font for inputselect()?

Post by klownboy »

OK, too bad though. Thanks.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Override font for inputselect()?

Post by klownboy »

Hey highend, I used your alignment technique for a simple "Sync" folder menu using SC inputselect. Everything looks fine stepping through it and I get the proper result (i.e., the data) to be synced ($sel), but for some reason I'm getting an invalid source path because there's a final backslash added. The error I get is

Code: Select all

Invalid source path:
"H:\Pictures", "I:\Pictures", 1, 0, 1, "c"\
Ignore the icons, I added those so an question mark would display since the ones I use are my ico's. Here's the partial script. Any ideas what may be causing the problem. Maybe it's a minor bug (or I'm the bug), but it's driving me nuts? Thanks.

Code: Select all

  $sync = <<<>>>
Photos <-->  Drive (I:)|"H:\Pictures", "I:\Pictures", 1, 0, 1, "c"|:sync
Taxes <-->  Drive (H:)|"G:\Taxes", "H:\Taxes", 1, 0, 1, "c"|:fvs
AHK <-->  Toshiba Rosewill|"D:\Tools\AutoHotkey", "O:\AutoHotkey", 1, 0, 1, "c"|:copyto
Photos <-->  Toshiba Rosewill|"H:\Pictures", "O:\Pictures", 1, 0, 1, "c"|:moveto
Wallpaper <-->  Toshiba Rosewill|"G:\Wallpaper", "O:\Wallpaper", 1, 0, 1, "c"|:sync
Icons <-->  Toshiba Rosewill|"D:\Graphics\Icons", "O:\Icons", 1, 0, 1, "c"|:fore
Taxes <-->  Toshiba Rosewill|"G:\Taxes", "O:\Taxes", 1, 0, 1, "c"|::openwith
XYplorer <-->  Toshiba Rosewill|"D:\Tools\XYplorer", "O:\XYbackup", 1, 0, 1, "c"|:backupto
XYplorer <-->  G:\XYBackup|"D:\Tools\XYplorer", "G:\XYbackup", 1, 0, 1, "c"|:nuke
Downloads <-->  SP flash|"G:\Downloads", "R:\Downloads", 1, 0, 1, "c"|:favs
Photos <-->  SP Flash|"H:\Pictures", "R:\Pictures", 1, 0, 1, "c"|:back
>>>;

   // Reformat $sync
    $syncKeys = regexreplace($sync, "^([^ ]+)([ ].*?)(?=\r?\n|$)", "$1");
    // Get longest iniKey
    $maxLen = 0;
    foreach($entry, $syncKeys, <crlf>, "e") {
        $len = strlen($entry);
        if ($len > $maxLen) { $maxLen = $len; }
    }
    // Reformat by longest iniKey as reference
	$newSync = "";
	foreach($line, $sync, <crlf>, "e") {
		$syncCaption = gettoken($line, 1, "|");
		$syncDataIcon = gettoken($line, 2, "|",, 2);
		$sourceKey    = regexreplace($syncCaption, "^([^ ]+)([ ].+?$)", "$1");
		$targetKey    = regexreplace($syncCaption, "^(.+ <--> )(.+?$)", "$2");
		$lenSourceKey = strlen($sourceKey);
		$padding   = $maxLen - $lenSourceKey;
		$newSync .= $sourceKey . strrepeat(<space>, $padding) . " <--> " . $targetKey . "|" . $syncDataIcon . <crlf>;
	}

	$sel = inputselect("   SOURCE             <-->             TARGET", $newSync, <crlf>,1+4+32+1024+8192+16384, , 330, 400, "SYNC OPERATIONS");
	text $sel;
		if($sel) {sync $sel;}
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Override font for inputselect()?

Post by highend »

Instead of if($sel) {sync $sel;}
use if ($sel) { load "sync $sel", , "s"; }
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Override font for inputselect()?

Post by klownboy »

Thanks highend. It turns out it was something stupid...me! I should have realized you had to use "load script" just as you do in SC popupmenu scripts like viewtopic.php?f=7&t=21133 and a million other cases. :oops: I'll blame it on Christmas cheer! It really does make a big difference in "the look" when you align the text properly especially in situations like syncing menus. I'm going to set that one up so left click goes source to target and right click reverses direction.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Override font for inputselect()?

Post by klownboy »

Thanks again highend. Hopefully you received my donation for your help on the forum. :appl: :beer:
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Override font for inputselect()?

Post by highend »

Yeah, I did (but you already know that). Thanks!
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Override font for inputselect()?

Post by klownboy »

Hi highend, the line in your code above, $iniKey = regexreplace($line, "^([^ ]+)([ ].+?$)", "$1"); which the first section prior to the <--> only yields the first word of the that section. If I were to have a couple of words with a space between them (e.g., Graphic Tools), how would you change that regx line? The second regx handles multiple words fine since it appears to be everything after the <-->. Obviously your example was using ini keys that are all one word without spaces so you weren't concerned about multiple words. I can do it with a gettoken, but was interested in how it would be accomplished with regx.

It looks like the line which determines the longest ini line would also have to be tweaked to recognize multple words. $iniKeys = regexreplace($relationShips, "^([^ ]+)([ ].*?)(?=\r?\n|$)", "$1"); Thanks.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Override font for inputselect()?

Post by highend »

Hi Ken,

Code: Select all

$sep = " <--> ";
$iniKeys = regexreplace($relationShips, "^(.+?)$sep(.+?)(?=\r?\n|$)", "$1");
...

// Same line again, only with different variables
$iniKey    = regexreplace($line, "^(.+?)$sep(.+?)(?=\r?\n|$)", "$1");
But it's safe to use gettoken() in the loop :)

Ofc this requires the usage of a separator that doesn't contain chars that would need to be escaped...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Override font for inputselect()?

Post by klownboy »

Thanks highend. I tried the regx and gettoken in the foreach loop both worked fine.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

Post Reply