Revamp UI a whole lot

This commit is contained in:
2026-11-18 19:42:44 +01:00
parent 260abc2c98
commit fdde7f9d80
57 changed files with 2667 additions and 935 deletions
+132 -74
View File
@@ -307,10 +307,20 @@ namespace KernelPanic.UI
return;
}
Label title = new("installed units");
title.AddToClassList("detail-section-title");
Label title = new("$ ls -lah ~/collection/units/");
title.AddToClassList("collection-ls-command");
_detail.Add(title);
Label total = new($"total {_units.Count}");
total.AddToClassList("collection-ls-total");
_detail.Add(total);
Label columns = new(LsText($"{"MODE",-12}{"OWNER",-8}{"SIZE",-6}{"VER",-6}{"LANG",-20}NAME"));
columns.AddToClassList("unit-ls-row");
columns.AddToClassList("unit-ls-line");
columns.AddToClassList("unit-ls-header");
_detail.Add(columns);
VisualElement roster = new();
roster.AddToClassList("unit-overview-roster");
_detail.Add(roster);
@@ -604,54 +614,51 @@ namespace KernelPanic.UI
private VisualElement BuildUnitOverviewRow(DistroDefinition unit)
{
int version = GetUnitVersion(unit);
string languages = unit.PrimaryLanguage == unit.SecondaryLanguage
? GetLanguageId(unit.PrimaryLanguage)
: $"{GetLanguageId(unit.PrimaryLanguage)}/{GetLanguageId(unit.SecondaryLanguage)}";
string upgradeMarker = CanUpgradeUnit(unit) ? " *" : string.Empty;
string listing = LsText($"{"drwxr-xr-x",-12}{"player",-8}{$"{GetDistroStars(unit)}★",-6}{$"{version}/{GachaTuning.MaxVersion}",-6}{languages,-20}{unit.Id}/{upgradeMarker}");
Button row = new();
row.AddToClassList("collection-row");
row.AddToClassList("unit-overview-row");
row.AddToClassList(RarityPresentation.ForStars(GetDistroStars(unit)).ClassName);
VisualElement top = new();
top.AddToClassList("unit-overview-top");
Label line = new(listing);
line.AddToClassList("unit-ls-line");
line.style.whiteSpace = WhiteSpace.NoWrap;
line.style.unityTextAlign = TextAnchor.MiddleLeft;
line.style.color = new StyleColor(unit.AccentColor);
row.Add(line);
Label name = new(DistroPresentation.DisplayName(unit));
name.AddToClassList("collection-row-name");
name.style.color = new StyleColor(unit.AccentColor);
top.Add(name);
RarityStyle rarity = RarityPresentation.ForStars(GetDistroStars(unit));
Label rarityLabel = new(rarity.Badge);
rarityLabel.AddToClassList("unit-overview-rarity");
rarityLabel.AddToClassList(rarity.ClassName);
top.Add(rarityLabel);
if (CanUpgradeUnit(unit))
{
Label upgrade = new("upgrade");
upgrade.AddToClassList("unit-overview-upgrade");
top.Add(upgrade);
}
row.Add(top);
VisualElement meta = new();
meta.AddToClassList("unit-overview-meta");
AddLanguageTag(meta, unit.PrimaryLanguage);
AddLanguageTag(meta, unit.SecondaryLanguage);
row.Add(meta);
int version = GetUnitVersion(unit);
Label release = new($"{DistroPresentation.DisplayName(unit)} {DistroVersionCatalog.GetReleaseLabel(unit.Id, version)} · v{version}/{GachaTuning.MaxVersion}");
release.AddToClassList("unit-overview-release");
row.Add(release);
VisualElement slots = new();
slots.AddToClassList("unit-overview-slots");
AddPackageSlotDot(slots, unit, PackageSlot.Kernel);
AddPackageSlotDot(slots, unit, PackageSlot.Runtime);
AddPackageSlotDot(slots, unit, PackageSlot.Daemon);
row.Add(slots);
string system = UnitPackageName(unit, PackageSlot.Kernel);
string tools = UnitPackageName(unit, PackageSlot.Runtime);
string services = UnitPackageName(unit, PackageSlot.Daemon);
Label packages = new($"└─ loadout system={system} tools={tools} services={services}");
packages.AddToClassList("unit-loadout-line");
row.Add(packages);
row.tooltip = $"System: {system}\nTools: {tools}\nServices: {services}";
return row;
}
private string UnitPackageName(DistroDefinition unit, PackageSlot slot)
{
PackageDefinition package = _packageLoadout == null || unit == null
? null
: _packageLoadout.GetEquippedPackage(unit.Id, slot);
return package == null ? "-" : PackageName(package);
}
private static string LsText(string value)
{
// UI Toolkit may wrap ordinary alignment spaces inside Button content.
// Non-breaking spaces preserve shell-style fixed columns at narrow widths.
return (value ?? string.Empty).Replace(' ', '\u00A0');
}
private void AddLanguageTag(VisualElement target, Language language)
{
Label tag = new(language.ToString());
@@ -805,7 +812,7 @@ namespace KernelPanic.UI
_unitDetailReturnsToOverview = returnToOverview;
_mode = CollectionMode.UnitDetail;
CurrentTitle = $"$ cat ~/units/{unit.Id}";
CurrentTitle = $"$ cat /etc/distros/{unit.Id}.conf";
CurrentHint = GetUnitDetailHint();
RenderUnitDetail(unit);
if (notify)
@@ -824,7 +831,7 @@ namespace KernelPanic.UI
TerminalTheme.PreserveFocus(_detail);
_detail.Clear();
_detailScroll.scrollOffset = Vector2.zero;
CurrentTitle = $"$ cat ~/units/{unit.Id}";
CurrentTitle = $"$ cat /etc/distros/{unit.Id}.conf";
CurrentHint = GetUnitDetailHint();
string identity = unit.Id + ":" + GetUnitVersion(unit);
@@ -854,16 +861,13 @@ namespace KernelPanic.UI
VisualElement nameBlock = new();
nameBlock.AddToClassList("unit-detail-header-copy");
int version = GetUnitVersion(unit);
Label name = new($"{DistroPresentation.DisplayName(unit)} {DistroVersionCatalog.GetReleaseLabel(unit.Id, version)} · v{version}/{GachaTuning.MaxVersion}");
Label path = new($"/etc/distros/{unit.Id}.conf");
path.AddToClassList("unit-config-path");
nameBlock.Add(path);
Label name = new($"# {DistroPresentation.DisplayName(unit)} · {DistroVersionCatalog.GetReleaseLabel(unit.Id, version)} · v{version}/{GachaTuning.MaxVersion}");
name.AddToClassList("collection-detail-name");
name.style.color = new StyleColor(unit.AccentColor);
nameBlock.Add(name);
VisualElement languages = new();
languages.AddToClassList("unit-overview-meta");
AddLanguageTag(languages, unit.PrimaryLanguage);
AddLanguageTag(languages, unit.SecondaryLanguage);
nameBlock.Add(languages);
header.Add(nameBlock);
RarityStyle rarity = RarityPresentation.ForStars(GetDistroStars(unit));
@@ -907,36 +911,88 @@ namespace KernelPanic.UI
private void AddUnitOverviewTab(VisualElement target, DistroDefinition unit)
{
VisualElement identity = TerminalLayout.Section("identity",
sectionClass: "unit-info-section unit-identity-section", headingClass: "detail-section-title");
identity.Add(BuildDetailLine("lang", DistroPresentation.FormatLanguages(unit)));
VisualElement identity = new();
identity.AddToClassList("unit-info-section");
identity.AddToClassList("unit-identity-section");
identity.Add(OverviewSectionLabel("[host]"));
Label description = TerminalLayout.BodyText(string.IsNullOrWhiteSpace(unit.Description) ? "--" : unit.Description,
className: "collection-detail-description");
VisualElement facts = new();
facts.AddToClassList("unit-overview-facts");
facts.Add(OverviewFact("languages", DistroPresentation.FormatLanguages(unit), "UnitOverview_languages", true));
facts.Add(OverviewFact("uptime", unit.BaseUptime.ToString(), "UnitOverview_uptime"));
facts.Add(OverviewFact("ram", unit.BaseRam.ToString(), "UnitOverview_ram"));
facts.Add(OverviewFact("cycles", unit.BaseCyclesPerTurn.ToString(), "UnitOverview_cycles"));
identity.Add(facts);
Label description = new(string.IsNullOrWhiteSpace(unit.Description) ? "--" : unit.Description)
{
name = "UnitOverview_description"
};
description.AddToClassList("unit-overview-description");
identity.Add(description);
target.Add(identity);
AddPassiveDetails(target, unit);
VisualElement readout = new();
readout.AddToClassList("collection-detail-readout");
VisualElement passive = new();
passive.AddToClassList("unit-info-section");
passive.AddToClassList("unit-passive-section");
VisualElement passiveHeading = new();
passiveHeading.AddToClassList("unit-passive-heading");
passiveHeading.Add(OverviewSectionLabel("[passive]"));
Label passiveName = new(unit.Passive == null ? "--" : unit.Passive.Name)
{
name = "UnitPassive_name"
};
passiveName.AddToClassList("unit-passive-name");
passiveHeading.Add(passiveName);
passive.Add(passiveHeading);
Label artLabel = new();
DistroArtPresenter.ConfigureArtLabel(artLabel, _monospaceFont);
AsciiArtFitter artFitter = new(artLabel, _monospaceFont);
VisualElement artPlaceholder = DistroArtPresenter.CreatePlaceholder();
artFitter.SetArt(DistroArtPresenter.Render(artLabel, artPlaceholder, unit));
readout.Add(artPlaceholder);
readout.Add(artLabel);
Label rules = new(GetPassiveRules(unit))
{
name = "UnitPassive_rules"
};
rules.AddToClassList("unit-passive-rules");
passive.Add(rules);
if (unit.Passive != null && !string.IsNullOrWhiteSpace(unit.Passive.FlavorText))
{
Label flavor = new("# " + unit.Passive.FlavorText)
{
name = "UnitPassive_flavor"
};
flavor.AddToClassList("unit-passive-flavor");
passive.Add(flavor);
}
target.Add(passive);
}
VisualElement details = new();
details.AddToClassList("collection-detail-values");
details.Add(BuildDetailLine("lang", DistroPresentation.FormatLanguages(unit)));
details.Add(BuildDetailLine("uptime", unit.BaseUptime.ToString()));
details.Add(BuildDetailLine("ram", unit.BaseRam.ToString()));
details.Add(BuildDetailLine("cycles", unit.BaseCyclesPerTurn.ToString()));
private static Label OverviewSectionLabel(string text)
{
Label label = new(text);
label.AddToClassList("unit-overview-section-label");
return label;
}
readout.Add(details);
target.Add(readout);
private static VisualElement OverviewFact(string key, string value, string name, bool wide = false)
{
VisualElement fact = new() { name = name };
fact.AddToClassList("unit-overview-fact");
if (wide) fact.AddToClassList("unit-overview-fact-wide");
Label keyLabel = new(key);
keyLabel.AddToClassList("unit-overview-fact-key");
Label valueLabel = new(value ?? "--");
valueLabel.AddToClassList("unit-overview-fact-value");
fact.Add(keyLabel);
fact.Add(valueLabel);
return fact;
}
private static string GetPassiveRules(DistroDefinition unit)
{
if (unit?.Passive == null) return "--";
if (unit.Id != "nixos") return unit.Passive.RulesText;
var policy = new NixGovernorState();
policy.BeginWave(1);
return "governor modes: " + string.Join("; ", Enum.GetValues(typeof(NixGovernor)).Cast<NixGovernor>().Select(governor =>
$"{governor.ToString().ToLowerInvariant()} {policy.DamageFor(governor)-100:+0;-0;0}% damage / {policy.ShieldFor(governor)-100:+0;-0;0}% shield"));
}
private void AddUnitUpgradeTab(VisualElement target, DistroDefinition unit)
@@ -1268,6 +1324,7 @@ namespace KernelPanic.UI
}, TrickleDown.TrickleDown);
_packageEquipDialog = new VisualElement();
_packageEquipDialog.AddToClassList("package-equip-dialog");
_packageEquipDialog.AddToClassList("terminal-pane");
_packageEquipOverlay.Add(_packageEquipDialog);
_root.Add(_packageEquipOverlay);
}
@@ -1312,7 +1369,8 @@ namespace KernelPanic.UI
VisualElement header = new();
header.AddToClassList("package-equip-header");
Label title = new($"equip: {_equipWindowSlot.DisplayName().ToLowerInvariant()} - {DistroPresentation.DisplayName(_equipWindowUnit)}");
header.AddToClassList("terminal-pane-titlebar");
Label title = new($"[ apt install --configure {_equipWindowSlot.DisplayName().ToLowerInvariant()} :: {DistroPresentation.DisplayName(_equipWindowUnit)} ]");
title.AddToClassList("collection-detail-name");
title.style.color = new StyleColor(_equipWindowUnit.AccentColor);
header.Add(title);