Skip to content

Commit ab8b0f3

Browse files
committed
improve some window/widget APIs
1 parent f9b509b commit ab8b0f3

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

WoLua/Lua/Api/Script/Ui/ScriptWidgetApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class ScriptWidgetApi(ScriptContainer source): ApiBase(source) { // TODO:
2222

2323
public CollapsableWidget CollapsableSection(string title, IDisplayWidget content) => new(title, content);
2424
public CollapsableWidget CollapsableSection(string title, string content) => new(title, new TextWidget(content));
25+
public CollapsableWidget Section(string title, IDisplayWidget content) => this.CollapsableSection(title, content);
26+
public CollapsableWidget Section(string title, string content) => this.CollapsableSection(title, content);
2527

2628
public static IDisplayWidget FromLuaValue(DynValue dv) => dv.Type switch {
2729
DataType.Boolean => new SeparatorWidget().SetBar(dv.Boolean),

WoLua/Lua/Api/Script/Ui/ScriptWindowApi.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,21 @@ public bool AutoResize {
6363

6464
public bool Empty => this.ScriptWindow.Empty;
6565

66+
public void ClearContent() {
67+
this.ScriptWindow.content = [];
68+
this.Owner.Log($"Cleared window contents", LogTag.ScriptWindow);
69+
}
6670
public void SetContent(List<DynValue> contents) {
6771
this.ScriptWindow.content = contents.Select(ScriptWidgetApi.FromLuaValue).ToArray();
6872
this.Owner.Log($"Set window content list to {this.ScriptWindow.content.Length} elements", LogTag.ScriptWindow);
6973
}
74+
public void AddContent(List<DynValue> contents) {
75+
this.ScriptWindow.content = this.ScriptWindow.content.Concat(contents.Select(ScriptWidgetApi.FromLuaValue)).ToArray();
76+
this.Owner.Log($"Set window content list to {this.ScriptWindow.content.Length} elements", LogTag.ScriptWindow);
77+
}
78+
public void PushContent(DynValue item) {
79+
this.ScriptWindow.content = this.ScriptWindow.content.Append(ScriptWidgetApi.FromLuaValue(item)).ToArray();
80+
this.Owner.Log($"Set window content list to {this.ScriptWindow.content.Length} elements", LogTag.ScriptWindow);
81+
}
7082

7183
}

WoLua/Lua/Api/Script/Ui/Widget/ContentGroup.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23

34
using MoonSharp.Interpreter;
45

56
namespace VariableVixen.WoLua.Lua.Api.Script.Ui.Widget;
67

78
[MoonSharpUserData]
89
public class ContentGroup: IDisplayWidget { // TODO: luadocs
9-
private readonly List<IDisplayWidget> content = [];
10+
private List<IDisplayWidget> content = [];
1011

11-
public ContentGroup Add(DynValue content) {
12+
public ContentGroup Clear() {
13+
this.content.Clear();
14+
return this;
15+
}
16+
public ContentGroup Push(DynValue content) {
1217
this.content.Add(ScriptWidgetApi.FromLuaValue(content));
1318
return this;
1419
}
20+
public ContentGroup Add(List<DynValue> content) {
21+
this.content.AddRange(content.Select(ScriptWidgetApi.FromLuaValue));
22+
return this;
23+
}
24+
public ContentGroup Set(List<DynValue> content) {
25+
this.content = content.Select(ScriptWidgetApi.FromLuaValue).ToList();
26+
return this;
27+
}
1528

1629
[MoonSharpHidden]
1730
public void Render(ScriptContainer script) {

0 commit comments

Comments
 (0)