Skip to content

Commit

Permalink
Fixed nested SettingCollections not showing when loaded from settings…
Browse files Browse the repository at this point in the history
….json. Improved spacing at the bottom of each SettingsView panel.
  • Loading branch information
dlamkins committed Jan 24, 2021
1 parent 5e8dd7e commit 9046377
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .idea/.idea.Blish HUD/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions Blish HUD/Controls/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ public virtual SizingMode HeightSizingMode {
get => _heightSizingMode;
set => SetProperty(ref _heightSizingMode, value);
}

private Point _autoSizePadding = Point.Zero;

/// <summary>
/// If <see cref="HeightSizingMode"/> or <see cref="WidthSizingMode"/> is set to
/// <see cref="SizingMode.AutoSize"/>, then <see cref="AutoSizePadding"/> is
/// added to the size.
/// </summary>
public Point AutoSizePadding {
get => _autoSizePadding;
set => SetProperty(ref _autoSizePadding, value);
}

public List<Control> GetDescendants() {
var allDescendants = _children.ToList();
Expand Down Expand Up @@ -211,11 +223,11 @@ public sealed override void DoUpdate(GameTime gameTime) {
if (this.Parent != null) {
this.Size = new Point(GetUpdatedSizing(this.WidthSizingMode,
this.Width,
_contentBounds.X + (this.Width - this.ContentRegion.Width),
_contentBounds.X + (this.Width - this.ContentRegion.Width) + _autoSizePadding.X,
this.Parent.ContentRegion.Width - this.Left),
GetUpdatedSizing(this.HeightSizingMode,
this.Height,
_contentBounds.Y + (this.Height - this.ContentRegion.Height),
_contentBounds.Y + (this.Height - this.ContentRegion.Height) + _autoSizePadding.Y,
this.Parent.ContentRegion.Height - this.Top));
}

Expand Down
29 changes: 20 additions & 9 deletions Blish HUD/GameServices/Settings/SettingCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ public sealed class SettingCollection : IEnumerable<SettingEntry> {

public class SettingCollectionConverter : JsonConverter<SettingCollection> {

private const string ATTR_LAZY = "Lazy";
private const string ATTR_RENDERINUI = "Ui";
private const string ATTR_ENTRIES = "Entries";

public override void WriteJson(JsonWriter writer, SettingCollection value, JsonSerializer serializer) {
var settingCollectionObject = new JObject();

if (value.LazyLoaded) {
settingCollectionObject.Add("Lazy", value.LazyLoaded);
settingCollectionObject.Add(ATTR_LAZY, value.LazyLoaded);
}

if (value.RenderInUi) {
settingCollectionObject.Add(ATTR_RENDERINUI, value.RenderInUi);
}

var entryArray = value._entryTokens as JArray;
Expand All @@ -27,27 +35,30 @@ public override void WriteJson(JsonWriter writer, SettingCollection value, JsonS
}
}

settingCollectionObject.Add("Entries", entryArray);
settingCollectionObject.Add(ATTR_ENTRIES, entryArray);

settingCollectionObject.WriteTo(writer);
}

public override SettingCollection ReadJson(JsonReader reader, Type objectType, SettingCollection existingValue, bool hasExistingValue, JsonSerializer serializer) {
if (reader.TokenType == JsonToken.Null) return null;

JObject jObj = JObject.Load(reader);
var jObj = JObject.Load(reader);

var isLazy = false;
bool isLazy = false;
bool renderInUi = false;

if (jObj["Lazy"] != null) {
isLazy = jObj["Lazy"].Value<bool>();
if (jObj[ATTR_LAZY] != null) {
isLazy = jObj[ATTR_LAZY].Value<bool>();
}

if (jObj["Entries"] != null) {
return new SettingCollection(isLazy, jObj["Entries"]);
if (jObj[ATTR_RENDERINUI] != null) {
renderInUi = jObj[ATTR_RENDERINUI].Value<bool>();
}

return new SettingCollection(isLazy);
return jObj[ATTR_ENTRIES] != null
? new SettingCollection(isLazy, jObj[ATTR_ENTRIES]) { RenderInUi = renderInUi }
: new SettingCollection(isLazy) { RenderInUi = renderInUi };
}

}
Expand Down
3 changes: 2 additions & 1 deletion Blish HUD/GameServices/Settings/UI/Views/SettingsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ protected override void BuildSetting(Panel buildPanel) {
_settingFlowPanel = new FlowPanel() {
Size = buildPanel.Size,
FlowDirection = ControlFlowDirection.SingleTopToBottom,
ControlPadding = new Vector2(5, 2),
ControlPadding = new Vector2(5, 2),
OuterControlPadding = new Vector2(10, 15),
WidthSizingMode = SizingMode.Fill,
HeightSizingMode = SizingMode.AutoSize,
AutoSizePadding = new Point(0, 15),
Parent = buildPanel
};

Expand Down

0 comments on commit 9046377

Please sign in to comment.