mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +01:00
made multi-line links be highlighted together
This commit is contained in:
parent
500a771136
commit
2461b78f1b
2 changed files with 21 additions and 4 deletions
|
@ -88,7 +88,7 @@ namespace MLEM.Ui.Elements {
|
|||
public override void Update(GameTime time) {
|
||||
this.QueryTextCallback();
|
||||
base.Update(time);
|
||||
|
||||
|
||||
this.TimeIntoAnimation += time.ElapsedGameTime;
|
||||
|
||||
if (this.TokenizedText != null)
|
||||
|
@ -134,9 +134,10 @@ namespace MLEM.Ui.Elements {
|
|||
this.RemoveChildren(c => c is Link);
|
||||
foreach (var link in linkTokens) {
|
||||
var areas = link.GetArea(Vector2.Zero, this.TextScale).ToArray();
|
||||
var cluster = new Link[areas.Length];
|
||||
for (var i = 0; i < areas.Length; i++) {
|
||||
var area = areas[i];
|
||||
this.AddChild(new Link(Anchor.TopLeft, link, area.Size) {
|
||||
cluster[i] = this.AddChild(new Link(Anchor.TopLeft, link, area.Size, cluster) {
|
||||
PositionOffset = area.Location,
|
||||
// only allow selecting the first part of a link
|
||||
CanBeSelected = i == 0
|
||||
|
@ -159,9 +160,11 @@ namespace MLEM.Ui.Elements {
|
|||
public class Link : Element {
|
||||
|
||||
public readonly Token Token;
|
||||
public readonly Link[] LinkCluster;
|
||||
|
||||
public Link(Anchor anchor, Token token, Vector2 size) : base(anchor, size) {
|
||||
public Link(Anchor anchor, Token token, Vector2 size, Link[] linkCluster) : base(anchor, size) {
|
||||
this.Token = token;
|
||||
this.LinkCluster = linkCluster;
|
||||
this.OnPressed += e => {
|
||||
foreach (var code in token.AppliedCodes.OfType<LinkCode>()) {
|
||||
try {
|
||||
|
@ -173,6 +176,18 @@ namespace MLEM.Ui.Elements {
|
|||
};
|
||||
}
|
||||
|
||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
|
||||
if (this.LinkCluster.Length > 1 && this.Controls.SelectedElement == this) {
|
||||
// also draw the selection box around all other links in the cluster
|
||||
foreach (var link in this.LinkCluster) {
|
||||
if (link == this)
|
||||
continue;
|
||||
this.System.OnSelectedElementDrawn?.Invoke(link, time, batch, alpha);
|
||||
}
|
||||
}
|
||||
base.Draw(time, batch, alpha, blendState, samplerState, matrix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -98,7 +98,9 @@ namespace MLEM.Formatting {
|
|||
var split = token.DisplayString.Split('\n');
|
||||
for (var i = 0; i < split.Length; i++) {
|
||||
var size = font.MeasureString(split[i]);
|
||||
area.Add(new RectangleF(innerOffset, size));
|
||||
var rect = new RectangleF(innerOffset, size);
|
||||
if (!rect.IsEmpty)
|
||||
area.Add(rect);
|
||||
|
||||
if (i < split.Length - 1) {
|
||||
innerOffset.X = 0;
|
||||
|
|
Loading…
Reference in a new issue