Create GUI
MrScautHD edited this page Oct 23, 2023
·
2 revisions
Initially, begin by crafting a new class that extends from the Gui
class. Following this, you'll choose a new data structure, in this case, Is called LabelData
, and configure its properties as desired.
Once this setup is complete, you can proceed to create a new Element, for instance, a LabelElement
, and seamlessly integrate it into the Gui
using the AddElement
method.
public class MyGui : Gui {
public MyGui(string name) : base(name) { }
protected override void Init() {
base.Init();
LabelData labelData = new LabelData() {
Font = FontHelper.GetDefault(),
FontSize = 50,
Spacing = 4,
Text = "Sparkle Engine!",
Color = Color.WHITE,
HoverColor = Color.GRAY,
Rotation = 0
};
this.AddElement(new LabelElement("name", labelData, Anchor.Center, Vector2.Zero));
// ADD MORE ELEMENTS HERE:
}
}
At first we need to create a new class and extend from GuiElements, after that we doing a new struct for all the datas that want to get implimented
public struct MyGuiElementData {
public string Text;
// Add more...
public MyGuiElementData() {
Text = string.Empty;
// Add more...
}
}
public class MyGuiElement : GuiElement {
public string Text;
public MyGuiElement(string name, MyGuiElementData data, Anchor anchor, Vector2 offset, Vector2 size, Func<bool>? clickClickFunc) : base(name, anchor, offset, size, clickClickFunc) {
this.Text = data.Text;
}
protected override void Draw() { }
}
Sparkle Engine - Visit the official Sparkle GitHub repository for the latest updates and source code.
Copyright © [Stellution Studios] | Licensed under the MIT License