Added C# UIWidget API

This commit is contained in:
antopilo
2024-09-11 22:58:06 -04:00
parent a5bf5d99c7
commit 596e4a484c
2 changed files with 121 additions and 27 deletions

View File

@@ -1,35 +1,36 @@
#include "Font.h"
#include "../FileSystem.h"
namespace NuakeUI
#include "src/FileSystem/FileSystem.h"
using namespace NuakeUI;
std::shared_ptr<Font> Font::New(const std::string& path)
{
std::shared_ptr<Font> Font::New(const std::string& path)
{
return std::make_shared<Font>(path);
}
return std::make_shared<Font>(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;
}
}
LineHeight = (float)metrics.lineHeight;
return true;
}

View File

@@ -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()
{
}
}
}