Truncate SoundDevice label at the UI level.

This commit is contained in:
Paul Chote
2016-01-10 23:28:52 +00:00
parent 652f38ff66
commit 8731d78594
2 changed files with 9 additions and 6 deletions

View File

@@ -37,10 +37,6 @@ namespace OpenRA
Engine = engine;
Device = device;
Label = label;
// Limit label to 32 characters
if (Label.Length > 32)
Label = "..." + Label.Substring(Label.Length - 32);
}
}

View File

@@ -335,7 +335,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var audioDeviceDropdown = panel.Get<DropDownButtonWidget>("AUDIO_DEVICE");
audioDeviceDropdown.OnMouseDown = _ => ShowAudioDeviceDropdown(audioDeviceDropdown, devices);
audioDeviceDropdown.GetText = () => soundDevice.Label;
var deviceFont = Game.Renderer.Fonts[audioDeviceDropdown.Font];
var deviceLabel = new CachedTransform<SoundDevice, string>(
s => WidgetUtils.TruncateText(s.Label, audioDeviceDropdown.UsableWidth, deviceFont));
audioDeviceDropdown.GetText = () => deviceLabel.Update(soundDevice);
return () =>
{
@@ -644,7 +648,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
() => soundDevice == options[o],
() => soundDevice = options[o]);
item.Get<LabelWidget>("LABEL").GetText = () => options[o].Label;
var deviceLabel = item.Get<LabelWidget>("LABEL");
var font = Game.Renderer.Fonts[deviceLabel.Font];
var label = WidgetUtils.TruncateText(options[o].Label, deviceLabel.Bounds.Width, font);
deviceLabel.GetText = () => label;
return item;
};