From 596e4a484cbb808235c2249a1102ed32d9f46512 Mon Sep 17 00:00:00 2001 From: antopilo Date: Wed, 11 Sep 2024 22:58:06 -0400 Subject: [PATCH] Added C# UIWidget API --- Nuake/src/UI/Font/Font.cpp | 55 ++++++++++---------- NuakeNet/src/UI/UIComponent.cs | 93 ++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 NuakeNet/src/UI/UIComponent.cs diff --git a/Nuake/src/UI/Font/Font.cpp b/Nuake/src/UI/Font/Font.cpp index 8330f0be..08d7ef71 100644 --- a/Nuake/src/UI/Font/Font.cpp +++ b/Nuake/src/UI/Font/Font.cpp @@ -1,35 +1,36 @@ #include "Font.h" -#include "../FileSystem.h" -namespace NuakeUI +#include "src/FileSystem/FileSystem.h" + + +using namespace NuakeUI; + +std::shared_ptr Font::New(const std::string& path) { - std::shared_ptr Font::New(const std::string& path) - { - return std::make_shared(path); - } + return std::make_shared(path); +} - Font::Font(const std::string& path) - { - mFreeTypeHandle = msdfgen::initializeFreetype(); - Load(path); - } +Font::Font(const std::string& path) +{ + mFreeTypeHandle = msdfgen::initializeFreetype(); + Load(path); +} - Font::~Font() - { - msdfgen::destroyFont(mFontHandle); - } +Font::~Font() +{ + msdfgen::destroyFont(mFontHandle); +} - bool Font::Load(const std::string& path) - { - bool exists = FileSystem::FileExists(path); - mFontHandle = msdfgen::loadFont(mFreeTypeHandle, path.c_str()); - if (!mFontHandle) - return false; +bool Font::Load(const std::string& path) +{ + bool exists = FileSystem::FileExists(path); + mFontHandle = msdfgen::loadFont(mFreeTypeHandle, path.c_str()); + if (!mFontHandle) + return false; - msdfgen::FontMetrics metrics; - msdfgen::getFontMetrics(metrics, mFontHandle); + msdfgen::FontMetrics metrics; + msdfgen::getFontMetrics(metrics, mFontHandle); - LineHeight = (float)metrics.lineHeight; - return true; - } -} \ No newline at end of file + LineHeight = (float)metrics.lineHeight; + return true; +} diff --git a/NuakeNet/src/UI/UIComponent.cs b/NuakeNet/src/UI/UIComponent.cs new file mode 100644 index 00000000..fd048fc2 --- /dev/null +++ b/NuakeNet/src/UI/UIComponent.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nuake.Net +{ + [AttributeUsage(AttributeTargets.Field)] + public sealed class UIWidgetInput : Attribute + { + private bool HasDefaultValue = false; + private int DefaultValueInternalInt; + private float DefaultValueInternalFloat; + private bool DefaultValueInternalBool; + private string DefaultValueInternalString; + + public UIWidgetInput(int DefaultValue) + { + DefaultValueInternalInt = DefaultValue; + HasDefaultValue = true; + } + + public UIWidgetInput(float DefaultValue) + { + this.DefaultValueInternalFloat = DefaultValue; + HasDefaultValue = true; + } + + public UIWidgetInput(string DefaultValue) + { + this.DefaultValueInternalString = DefaultValue; + HasDefaultValue = true; + } + + public UIWidgetInput(bool DefaultValue) + { + this.DefaultValueInternalBool = DefaultValue; + HasDefaultValue = true; + } + + public UIWidgetInput() { } + } + + public class Style + { + protected ulong ID; + + public Style(ulong id) + { + ID = id; + } + } + + [AttributeUsage(AttributeTargets.Class)] + public sealed class ExternalHTML : Attribute + { + private string HTMLPath; + public ExternalHTML(string path) + { + HTMLPath = path; + } + } + + public class UIWidget + { + public Style Style { get; set; } + + private string HTML; + + protected ulong ID { get; set; } + + public UIWidget() + { } + + protected UIWidget(ulong id) + { + ID = id; + Style = new Style(id); + HTML = ""; + } + + public virtual void OnInit() { } + public virtual void OnTick(float dt) { } + + // Events + public virtual void OnClick() + { + + } + } +}