Skip to content

Commit 274f7b2

Browse files
committed
Wrap buttons in a horizontal layout to simplify adding extra buttons to them
1 parent c092694 commit 274f7b2

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

ComponentSelectorAdditions/DefaultHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static TextField MakeGenericArgumentInput(UIBuilder ui, Type component, T
6060
{
6161
var textField = ui.HorizontalElementWithLabel(genericArgument.Name, .05f, () =>
6262
{
63-
var textField = ui.TextField(null, false, null, false);
63+
var textField = ui.TextField(parseRTF: false);
6464
textField.Text.NullContent.AssignLocaleString(Mod.GetLocaleString("EnterType"));
6565

6666
return textField;
@@ -88,13 +88,15 @@ public static void MakePermanentButton(UIBuilder ui, LocaleString name, colorX t
8888
ui.PushStyle();
8989
ui.Style.MinHeight = category is not null ? ConfigSection.IndirectButtonHeight : ConfigSection.DirectButtonHeight;
9090

91+
ui.HorizontalLayout(4, 0, Alignment.MiddleCenter);
92+
ui.Style.FlexibleWidth = 1;
93+
9194
var button = ui.Button(name, tint, callback, argument, .35f);
9295
button.Label.ParseRichText.Value = false;
9396

9497
if (category is not null)
9598
{
9699
var buttonLabel = button.Label;
97-
buttonLabel.ParseRichText.Value = false;
98100
ui.NestInto(button.RectTransform);
99101

100102
var panel = ui.Panel();

ComponentSelectorAdditions/FavoritesCategories.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ComponentSelectorAdditions.Events;
2-
using Elements.Core;
32
using FrooxEngine;
43
using FrooxEngine.UIX;
54
using MonkeyLoader.Events;
@@ -179,32 +178,26 @@ protected override bool OnShutdown(bool applicationExiting)
179178
private static void AddFavoriteButton(UIBuilder builder, Button button, bool isComponent,
180179
Func<TypeManager, string, bool> isFavorite, Func<TypeManager, string, bool> toggleFavorite)
181180
{
181+
builder.PushStyle();
182+
182183
var types = button.World.Types;
183184
builder.NestInto(button.Slot.Parent);
184185

185-
var height = button.Slot.GetComponent<LayoutElement>().MinHeight;
186-
builder.Style.MinHeight = height;
187-
188-
var panel = builder.Panel();
189-
builder.VerticalFooter(height + 4, out var footer, out var content);
190-
191-
button.Slot.Parent = content.Slot;
192-
panel.Slot.OrderOffset = button.Slot.OrderOffset;
193-
button.Slot.OrderOffset = 0;
194-
195-
footer.OffsetMin.Value += new float2(4, 0);
196-
builder.NestInto(footer);
186+
var height = button.Slot.Parent.GetComponent<LayoutElement>().MinHeight;
187+
builder.Style.MinWidth = height;
197188

198189
var name = button.Slot.GetComponent<ButtonRelay<string>>().Argument.Value;
199190
if (isComponent)
200191
{
201192
var lastSlashIndex = name.LastIndexOf('/');
202-
name = name.Substring(lastSlashIndex + 1);
193+
name = name[(lastSlashIndex + 1)..];
203194
}
204195

205196
var favColor = isFavorite(types, name) ? RadiantUI_Constants.Hero.YELLOW : RadiantUI_Constants.Neutrals.DARKLIGHT;
206197

207198
var favoriteButton = builder.Button(OfficialAssets.Graphics.Icons.World_Categories.FeaturedRibbon, RadiantUI_Constants.BUTTON_COLOR, favColor);
199+
favoriteButton.Slot.OrderOffset = 1;
200+
208201
var icon = favoriteButton.Slot.GetComponentsInChildren<Image>().Last();
209202

210203
favoriteButton.LocalPressed += (btn, btnEvent) =>
@@ -214,6 +207,8 @@ private static void AddFavoriteButton(UIBuilder builder, Button button, bool isC
214207

215208
Config.Save();
216209
};
210+
211+
builder.PopStyle();
217212
}
218213

219214
private static bool ToggleHashSetContains<T>(ISet<T> set, T value)

0 commit comments

Comments
 (0)