Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ShadowTheAge#224, where long milestone names could hide remove buttons. #129

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Yafc.UI/ImGui/ImGuiBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ public SchemeColor textColor {
set => state.textColor = value;
}

public void BuildText(string text, Font font = null, bool wrap = false, RectAlignment align = RectAlignment.MiddleLeft, SchemeColor color = SchemeColor.None, float topOffset = 0f) {
public void BuildText(string text, Font font = null, bool wrap = false, RectAlignment align = RectAlignment.MiddleLeft, SchemeColor color = SchemeColor.None, float topOffset = 0f, float maxWidth = float.MaxValue) {
if (color == SchemeColor.None) {
color = state.textColor;
}

var rect = AllocateTextRect(out var cache, text, font, wrap, align, topOffset);
var rect = AllocateTextRect(out var cache, text, font, wrap, align, topOffset, maxWidth);
if (action == ImGuiAction.Build && cache != null) {
DrawRenderable(rect, cache, color);
}
}

public Rect AllocateTextRect(out TextCache cache, string text, Font font = null, bool wrap = false, RectAlignment align = RectAlignment.MiddleLeft, float topOffset = 0f) {
public Rect AllocateTextRect(out TextCache cache, string text, Font font = null, bool wrap = false, RectAlignment align = RectAlignment.MiddleLeft, float topOffset = 0f, float maxWidth = float.MaxValue) {
var fontSize = GetFontSize(font);
Rect rect;
if (string.IsNullOrEmpty(text)) {
Expand All @@ -106,7 +106,8 @@ public Rect AllocateTextRect(out TextCache cache, string text, Font font = null,
}
else {
cache = textCache.GetCached((fontSize, text, wrap ? (uint)UnitsToPixels(MathF.Max(width, 5f)) : uint.MaxValue));
rect = AllocateRect(cache.texRect.w / pixelsPerUnit, topOffset + (cache.texRect.h / pixelsPerUnit), align);
float textWidth = Math.Min(cache.texRect.w / pixelsPerUnit, maxWidth);
rect = AllocateRect(textWidth, topOffset + (cache.texRect.h / pixelsPerUnit), align);
}

if (topOffset != 0f) {
Expand Down
2 changes: 1 addition & 1 deletion Yafc/Widgets/PseudoScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Yafc {
// Pseudo screen is not an actual screen, it is a panel shown in the middle of the main screen
public abstract class PseudoScreen : IKeyboardFocus {
public readonly ImGui contents;
private readonly float width;
protected readonly float width;
protected bool opened;

protected PseudoScreen(float width = 40f) {
Expand Down
4 changes: 2 additions & 2 deletions Yafc/Windows/MilestonesEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MilestonesEditor : PseudoScreen {
private static readonly MilestonesEditor Instance = new MilestonesEditor();
private readonly VirtualScrollList<FactorioObject> milestoneList;

public MilestonesEditor() => milestoneList = new VirtualScrollList<FactorioObject>(30f, new Vector2(float.PositiveInfinity, 3f), MilestoneDrawer);
public MilestonesEditor() : base(50) => milestoneList = new VirtualScrollList<FactorioObject>(30f, new Vector2(float.PositiveInfinity, 3f), MilestoneDrawer);

public override void Open() {
base.Open();
Expand All @@ -21,7 +21,7 @@ private void MilestoneDrawer(ImGui gui, FactorioObject element, int index) {
using (gui.EnterRow()) {
var settings = Project.current.settings;
gui.BuildFactorioObjectIcon(element, MilestoneDisplay.None, 3f);
gui.BuildText(element.locName);
gui.BuildText(element.locName, maxWidth: width - 16.6f); // Experimentally determined width of the non-text parts of the editor.
if (gui.BuildButton(Icon.Close, size: 1f)) {
_ = settings.RecordUndo().milestones.Remove(element);
Rebuild();
Expand Down