Skip to content

Commit

Permalink
Fix popup of 'Target technology for cost analysis' preference
Browse files Browse the repository at this point in the history
The header is too wide for the default width of 20f. Make the width
configurable (as it is used in more places) and increase the width of this
particular popup to fit the text/label.
  • Loading branch information
veger committed Feb 27, 2024
1 parent 083cb4e commit 6c00690
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions YAFC/Widgets/ImmediateWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ public static void ShowPrecisionValueTooltip(ImGui gui, float amount, UnitOfMeas
}, 10f);
}

public static void BuildObjectSelectDropDown<T>(this ImGui gui, ICollection<T> list, IComparer<T> ordering, Action<T> select, string header, int count = 6, bool multiple = false, Predicate<T> checkmark = null, bool allowNone = false, Func<T, string> extra = null) where T : FactorioObject {
gui.ShowDropDown(imGui => imGui.BuildInlineObjectListAndButton(list, ordering, select, header, count, multiple, checkmark, allowNone, extra));
/// <summary>Shows a dropdown containing the (partial) <paramref name="list"/> of elements, with an action for when an element is selected.</summary>
/// <param name="count">Maximum number of elements in the list. If there are more another popup can be opened by the user to show the full list.</param>
/// <param name="width">Width of the popup. Make sure the header text fits!</param>
public static void BuildObjectSelectDropDown<T>(this ImGui gui, ICollection<T> list, IComparer<T> ordering, Action<T> select, string header, float width = 20f, int count = 6, bool multiple = false, Predicate<T> checkmark = null, bool allowNone = false, Func<T, string> extra = null) where T : FactorioObject {
gui.ShowDropDown(imGui => imGui.BuildInlineObjectListAndButton(list, ordering, select, header, count, multiple, checkmark, allowNone, extra), width);
}

public static GoodsWithAmountEvent BuildFactorioObjectWithEditableAmount(this ImGui gui, FactorioObject obj, float amount, UnitOfMeasure unit, out float newAmount, SchemeColor color = SchemeColor.None) {
Expand Down
9 changes: 6 additions & 3 deletions YAFC/Windows/PreferencesScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void Build(ImGui gui) {
ChoiceObject(gui, "Target technology for cost analysis: ", Database.technologies.all, prefs.targetTechnology, x => {
prefs.RecordUndo().targetTechnology = x;
gui.Rebuild();
});
}, width: 25f);

if (gui.BuildButton("Done"))
Close();
Expand All @@ -71,11 +71,14 @@ public override void Build(ImGui gui) {
Project.current.RecalculateDisplayPages();
}

private void ChoiceObject<T>(ImGui gui, string text, T[] list, T current, Action<T> select) where T : FactorioObject {
/// <summary>Add a GUI element that opens a popup to allow the user to choose from the <paramref name="list"/>, which triggers <paramref name="select"/>.</summary>
/// <param name="text">Label to show.</param>
/// <param name="width">Width of the popup. Make sure it is wide enough to fit text!</param>
private void ChoiceObject<T>(ImGui gui, string text, T[] list, T current, Action<T> select, float width = 20f) where T : FactorioObject {
using (gui.EnterRow()) {
gui.BuildText(text, topOffset: 0.5f);
if (gui.BuildFactorioObjectButtonWithText(current))
gui.BuildObjectSelectDropDown(list, DataUtils.DefaultOrdering, select, text);
gui.BuildObjectSelectDropDown(list, DataUtils.DefaultOrdering, select, text, width: width);
}
}

Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version: 0.6.2
Date: soon(tm)
Changes:
- Fix text alignment of about screen
- Fix width of 'Target technology for cost analysis' preference popup
----------------------------------------------------------------------------------------------------------------------
Version: 0.6.1
Date: Feb 2024
Expand Down

0 comments on commit 6c00690

Please sign in to comment.