- reworked function calling
- working on correct theming support
This commit is contained in:
MyDrift 2024-08-09 22:30:45 +02:00
parent 1132d53944
commit 47e80010d1
3 changed files with 40 additions and 48 deletions

View File

@ -12,7 +12,7 @@
"HeaderFontFamily": "Consolas, Monaco", "HeaderFontFamily": "Consolas, Monaco",
"CheckBoxBulletDecoratorFontSize": "14", "CheckBoxBulletDecoratorFontSize": "14",
"CheckBoxMargin": "15,0,0,2", "CheckBoxMargin": "5,0,0,2",
"TabButtonFontSize": "14", "TabButtonFontSize": "14",
"TabButtonWidth": "100", "TabButtonWidth": "100",
@ -86,7 +86,7 @@
"HeaderFontFamily": "Consolas, Monaco", "HeaderFontFamily": "Consolas, Monaco",
"CheckBoxBulletDecoratorFontSize": "14", "CheckBoxBulletDecoratorFontSize": "14",
"CheckBoxMargin": "15,0,0,2", "CheckBoxMargin": "5,0,0,2",
"TabButtonFontSize": "14", "TabButtonFontSize": "14",
"TabButtonWidth": "100", "TabButtonWidth": "100",
@ -158,7 +158,7 @@
"HeaderFontFamily": "Consolas, Monaco", "HeaderFontFamily": "Consolas, Monaco",
"CheckBoxBulletDecoratorFontSize": "14", "CheckBoxBulletDecoratorFontSize": "14",
"CheckBoxMargin": "15,0,0,2", "CheckBoxMargin": "5,0,0,2",
"TabButtonFontSize": "14", "TabButtonFontSize": "14",
"TabButtonWidth": "100", "TabButtonWidth": "100",

View File

@ -4,10 +4,18 @@ function Invoke-WPFUIElements {
Adds UI elements to a specified Grid in the WinUtil GUI based on a JSON configuration. Adds UI elements to a specified Grid in the WinUtil GUI based on a JSON configuration.
.PARAMETER configVariable .PARAMETER configVariable
The variable/link containing the JSON configuration. The variable/link containing the JSON configuration.
.PARAMETER panel .PARAMETER targetGridName
The name of the panel for which the UI elements should be added. The name of the grid to which the UI elements should be added.
.PARAMETER columncount
The number of columns to be used in the Grid. If not provided, a default value is used based on the panel.
.PARAMETER categoryPanelMap
A hashtable that maps specific categories to specific panels.
.EXAMPLE .EXAMPLE
Invoke-WinUtilUIElements -configVariable $sync.configs.applications -panel "install" $categoryPanelMap = @{
"Essential Tweaks" = 0
"Customize Preferences" = 1
}
Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "install" -columncount 4 -categoryPanelMap $categoryPanelMap
#> #>
param( param(
@ -15,30 +23,12 @@ function Invoke-WPFUIElements {
[PSCustomObject]$configVariable, [PSCustomObject]$configVariable,
[Parameter(Mandatory)] [Parameter(Mandatory)]
[ValidateSet("install", "tweaks", "features")] [string]$targetGridName,
[string]$panel
[int]$columncount
) )
# Ensure configVariable is not null $theme = $sync.configs.themes.$ctttheme
if ($null -eq $configVariable) {
throw "The configuration variable is null."
}
# Determine target grid and column count based on the panel
switch ($panel) {
"install" {
$targetGridName = "appspanel"
$columncount = 5
}
"tweaks" {
$targetGridName = "tweakspanel"
$columncount = 2
}
"features" {
$targetGridName = "featurespanel"
$columncount = 2
}
}
# Convert PSCustomObject to Hashtable # Convert PSCustomObject to Hashtable
$configHashtable = @{} $configHashtable = @{}
@ -48,17 +38,17 @@ function Invoke-WPFUIElements {
$organizedData = @{} $organizedData = @{}
# Iterate through JSON data and organize by panel and category # Iterate through JSON data and organize by panel and category
foreach ($appName in $configHashtable.Keys) { foreach ($entry in $configHashtable.Keys) {
$appInfo = $configHashtable[$appName] $appInfo = $configHashtable[$entry]
# Create an object for the application # Create an object for the application
$appObject = [PSCustomObject]@{ $appObject = [PSCustomObject]@{
Name = $appName Name = $entry
Category = $appInfo.Category Category = $appInfo.Category
Content = $appInfo.Content Content = $appInfo.Content
Choco = $appInfo.choco Choco = $appInfo.choco
Winget = $appInfo.winget Winget = $appInfo.winget
Panel = "0" # Set to 0 to force even distribution across columns Panel = if ($appInfo.Panel -ne $null) { $appInfo.Panel } else { "0" }
Link = $appInfo.link Link = $appInfo.link
Description = $appInfo.description Description = $appInfo.description
Type = $appInfo.type Type = $appInfo.type
@ -76,7 +66,7 @@ function Invoke-WPFUIElements {
} }
# Store application data in a sub-array under the category # Store application data in a sub-array under the category
$organizedData[$appObject.Panel][$appInfo.Category]["$($appInfo.order)$appName"] = $appObject $organizedData[$appObject.Panel][$appInfo.Category]["$($appInfo.order)$entry"] = $appObject
} }
# Retrieve the main window and the target Grid by name # Retrieve the main window and the target Grid by name
@ -149,13 +139,13 @@ function Invoke-WPFUIElements {
} }
$label = New-Object Windows.Controls.Label $label = New-Object Windows.Controls.Label
$label.Content = $category $label.Content = $category -replace ".*__"
$label.FontSize = 16 $label.FontSize = $theme.FontSizeHeading
$label.FontFamily = "Segoe UI" $label.FontFamily = $theme.HeaderFontFamily
$stackPanel.Children.Add($label) | Out-Null $stackPanel.Children.Add($label) | Out-Null
$sortedApps = $organizedData[$panelKey][$category].Keys | Sort-Object $sortedApps = $organizedData[$panelKey][$category].Keys | Sort-Object
foreach ($appName in $sortedApps) { foreach ($entry in $sortedApps) {
$count++ $count++
if ($columncount -gt 0) { if ($columncount -gt 0) {
$panelcount2 = [Int](($count) / $maxcount - 0.5) $panelcount2 = [Int](($count) / $maxcount - 0.5)
@ -179,14 +169,13 @@ function Invoke-WPFUIElements {
} }
} }
$appInfo = $organizedData[$panelKey][$category][$appName] $appInfo = $organizedData[$panelKey][$category][$entry]
switch ($appInfo.Type) { switch ($appInfo.Type) {
"Toggle" { "Toggle" {
$dockPanel = New-Object Windows.Controls.DockPanel $dockPanel = New-Object Windows.Controls.DockPanel
$checkBox = New-Object Windows.Controls.CheckBox $checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $appInfo.Name $checkBox.Name = $appInfo.Name
$checkBox.HorizontalAlignment = "Right" $checkBox.HorizontalAlignment = "Right"
$checkBox.FontSize = 14
$dockPanel.Children.Add($checkBox) | Out-Null $dockPanel.Children.Add($checkBox) | Out-Null
$checkBox.Style = $window.FindResource("ColorfulToggleSwitchStyle") $checkBox.Style = $window.FindResource("ColorfulToggleSwitchStyle")
@ -194,7 +183,8 @@ function Invoke-WPFUIElements {
$label.Content = $appInfo.Content $label.Content = $appInfo.Content
$label.ToolTip = $appInfo.Description $label.ToolTip = $appInfo.Description
$label.HorizontalAlignment = "Left" $label.HorizontalAlignment = "Left"
$label.FontSize = 14 $label.FontSize = $theme.FontSize
# Implement for consistent theming later on $label.Style = $window.FindResource("labelfortweaks")
$dockPanel.Children.Add($label) | Out-Null $dockPanel.Children.Add($label) | Out-Null
$stackPanel.Children.Add($dockPanel) | Out-Null $stackPanel.Children.Add($dockPanel) | Out-Null
@ -209,13 +199,13 @@ function Invoke-WPFUIElements {
$label.Content = $appInfo.Content $label.Content = $appInfo.Content
$label.HorizontalAlignment = "Left" $label.HorizontalAlignment = "Left"
$label.VerticalAlignment = "Center" $label.VerticalAlignment = "Center"
$label.FontSize = 14 $label.FontSize = $theme.ButtonFontSize
$horizontalStackPanel.Children.Add($label) | Out-Null $horizontalStackPanel.Children.Add($label) | Out-Null
$comboBox = New-Object Windows.Controls.ComboBox $comboBox = New-Object Windows.Controls.ComboBox
$comboBox.Name = $appInfo.Name $comboBox.Name = $appInfo.Name
$comboBox.Height = 32 $comboBox.Height = $theme.ButtonHeight
$comboBox.Width = 186 $comboBox.Width = $theme.ButtonWidth
$comboBox.HorizontalAlignment = "Left" $comboBox.HorizontalAlignment = "Left"
$comboBox.VerticalAlignment = "Center" $comboBox.VerticalAlignment = "Center"
$comboBox.Margin = "5,5" $comboBox.Margin = "5,5"
@ -223,7 +213,7 @@ function Invoke-WPFUIElements {
foreach ($comboitem in ($appInfo.ComboItems -split " ")) { foreach ($comboitem in ($appInfo.ComboItems -split " ")) {
$comboBoxItem = New-Object Windows.Controls.ComboBoxItem $comboBoxItem = New-Object Windows.Controls.ComboBoxItem
$comboBoxItem.Content = $comboitem $comboBoxItem.Content = $comboitem
$comboBoxItem.FontSize = 14 $comboBoxItem.FontSize = $theme.ButtonFontSize
$comboBox.Items.Add($comboBoxItem) | Out-Null $comboBox.Items.Add($comboBoxItem) | Out-Null
} }
@ -238,6 +228,7 @@ function Invoke-WPFUIElements {
$button.HorizontalAlignment = "Left" $button.HorizontalAlignment = "Left"
$button.Margin = "5" $button.Margin = "5"
$button.Padding = "20,5" $button.Padding = "20,5"
$button.FontSize = $theme.ButtonFontSize
if ($appInfo.ButtonWidth -ne $null) { if ($appInfo.ButtonWidth -ne $null) {
$button.Width = $appInfo.ButtonWidth $button.Width = $appInfo.ButtonWidth
} }
@ -248,8 +239,9 @@ function Invoke-WPFUIElements {
$checkBox = New-Object Windows.Controls.CheckBox $checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $appInfo.Name $checkBox.Name = $appInfo.Name
$checkBox.Content = $appInfo.Content $checkBox.Content = $appInfo.Content
$checkBox.FontSize = $theme.FontSize
$checkBox.ToolTip = $appInfo.Description $checkBox.ToolTip = $appInfo.Description
$checkBox.Margin = "5,0" $checkBox.Margin = $theme.CheckBoxMargin
if ($appInfo.Checked -ne $null) { if ($appInfo.Checked -ne $null) {
$checkBox.IsChecked = $appInfo.Checked $checkBox.IsChecked = $appInfo.Checked
} }

View File

@ -85,9 +85,9 @@ try {
# Load the configuration files # Load the configuration files
Invoke-WPFUIElements -configVariable $sync.configs.applications -panel "install" Invoke-WPFUIElements -configVariable $sync.configs.applications -targetGridName "appspanel" -columncount 5
Invoke-WPFUIElements -configVariable $sync.configs.tweaks -panel "tweaks" Invoke-WPFUIElements -configVariable $sync.configs.tweaks -targetGridName "tweakspanel" -columncount 2
Invoke-WPFUIElements -configVariable $sync.configs.feature -panel "features" Invoke-WPFUIElements -configVariable $sync.configs.feature -targetGridName "featurespanel" -columncount 2
#=========================================================================== #===========================================================================