Compare commits

...

4 commits
1.0 ... main

12 changed files with 158 additions and 30 deletions

View file

@ -1,5 +1,5 @@
FileVersion = 1 FileVersion = 1
Dependencies = {corlib = "*", raylib-beef = "*"} Dependencies = {corlib = "*", corlib = "*", raylib-beef = "*"}
[Project] [Project]
Name = "TheaterGui" Name = "TheaterGui"

View file

@ -1,26 +0,0 @@
FileVersion = 1
Projects = {TheaterGui = {Path = "."}, raylib-beef = {Path = "../../External/raylib-beef/raylib-beef"}, ExampleGui = {Path = "../../../Projects/ExampleGui"}}
[Workspace]
StartupProject = "ExampleGui"
[Configs.Debug.Win64]
ConfigSelections = {raylib-beef = {Config = "StaticDebug"}}
[Configs.Debug.wasm32]
AllocType = "CRT"
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false
[Configs.Release.Win64]
ConfigSelections = {raylib-beef = {Config = "StaticRelease"}}
[Configs.Paranoid.wasm32]
AllocType = "CRT"
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false
[Configs.Test.wasm32]
AllocType = "CRT"
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false

View file

@ -4,3 +4,6 @@ Dependencies = {corlib = "*", TheaterGui = "*"}
[Project] [Project]
Name = "examples" Name = "examples"
StartupObject = "examples.Program" StartupObject = "examples.Program"
[Configs.Release.wasm32]
OtherLinkFlags = "$(LinkFlags) --shell-file $(ProjectDir)/index.html"

View file

@ -3,3 +3,18 @@ Projects = {examples = {Path = "."}, TheaterGui = {Path = ".."}}
[Workspace] [Workspace]
StartupProject = "examples" StartupProject = "examples"
[Configs.Debug.wasm32]
AllocType = "CRT"
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false
[Configs.Paranoid.wasm32]
AllocType = "CRT"
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false
[Configs.Test.wasm32]
AllocType = "CRT"
EnableObjectDebugFlags = false
EmitObjectAccessCheck = false

45
examples/index.html Normal file
View file

@ -0,0 +1,45 @@
<!doctype html>
<title>Game</title>
<meta name=viewport content="width=device-width, maximum-scale=1.0, user-scalable=no, viewport-fit=cover, interactive-widget=resizes-content">
<style>
:root, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
contain: strict;
}
canvas {
width: 100%;
height: 100%;
border: 0;
background: black;
}
</style>
<canvas id=canvas></canvas>
<script>
let canvas = window.canvas
function updateCanvasSize() {
const box = canvas.getBoundingClientRect()
canvas.width = box.width * devicePixelRatio
canvas.height = box.height * devicePixelRatio
}
updateCanvasSize()
addEventListener('resize', updateCanvasSize)
Module = {
canvas,
arguments: location.hash.slice(1).split(' '),
}
onerror = (...args) => {
alert(JSON.stringify(args))
}
</script>
{{{ SCRIPT }}}

View file

@ -20,14 +20,18 @@ class ExampleToolbar : Toolbar
public void PrintVersion() public void PrintVersion()
{ {
#if !BF_PLATFORM_WASM
System.Console.WriteLine("1.0"); System.Console.WriteLine("1.0");
#endif
} }
public void PrintAbout() public void PrintAbout()
{ {
#if !BF_PLATFORM_WASM
System.Console.WriteLine(""" System.Console.WriteLine("""
TheaterGui by Booklordofthedings TheaterGui by Booklordofthedings
A simple easy to use gui library for tools A simple easy to use gui library for tools
"""); """);
#endif
} }
} }

View file

@ -18,6 +18,8 @@ class HorSlider : HSlider
public override void OnValueChange(float newVal) public override void OnValueChange(float newVal)
{ {
#if !BF_PLATFORM_WASM
System.Console.WriteLine(Value); System.Console.WriteLine(Value);
#endif
} }
} }

View file

@ -42,6 +42,7 @@ class App
if (_CurrentScreen != null) if (_CurrentScreen != null)
delete _CurrentScreen; delete _CurrentScreen;
_CurrentScreen = value; _CurrentScreen = value;
_CurrentScreen.Reorder(Width);
} }
}; };
@ -187,6 +188,9 @@ class App
Input.HandleRightClick(); Input.HandleRightClick();
else else
Input.HandleHover(); Input.HandleHover();
if(Selected != null)
Selected.WhileSelected();
} }

View file

@ -7,7 +7,7 @@ abstract class Component
{ {
public this(StringView pComponentName, StringView pLabel) public this(StringView pComponentName, StringView pLabel)
{ {
_ComponentType.Append(pComponentName); ComponentType = pComponentName;
Label = pLabel; Label = pLabel;
} }

View file

@ -11,6 +11,7 @@ class Container : Component
} }
private List<Component> _LayoutData = new .() ~ delete _; private List<Component> _LayoutData = new .() ~ delete _;
public List<Component> Children = new .() ~ DeleteContainerAndItems!(_); public List<Component> Children = new .() ~ DeleteContainerAndItems!(_);

View file

@ -0,0 +1,72 @@
namespace TheaterGui.Components;
using System;
using RaylibBeef;
class InputField : Component
{
public NPatchInfo PatchInfo;
public String InputContent = new .() ~ delete _;
String text = new .() ~ delete _;
public this(StringView pLabel) : base("InputField", pLabel)
{
Label = "Test Data";
Sprite = App.Textures.GetAsset("n_button");
Width = 128 * 2;
Height = 32;
Margin = 10;
Tint = Theme.Background;
PatchInfo = .(Sprite.SourceRect, 7, 7, 7, 7, (.)NPatchLayout.NPATCH_NINE_PATCH);
}
public override void Render(int32 soy)
{
Raylib.DrawTextureNPatch(
*Sprite.Source,
PatchInfo,
Rectangle(X, Y + soy, Width, Height),
Vector2(0, 0),
0,
Tint);
if (_IsHovered || App.Selected == this)
Raylib.DrawTextureNPatch(*Sprite.Source, PatchInfo, Rectangle(X, Y + soy, Width, Height), Vector2(0, 0), 0, Theme.Tint.SetAlpha(120));
_IsHovered = false;
var measure = Raylib.MeasureTextEx(Theme.Font, text, Theme.FontSize, 0);
Raylib.DrawTextEx(Theme.Font, text, Vector2(X + 7, Y + Height / 2 - measure.y / 2 + soy), Theme.FontSize, 0, Theme.Text);
}
protected bool _IsHovered = false;
public override Component OnHover(int32 x, int32 y)
{
_IsHovered = true;
return this;
}
public override bool OnClick(int32 x, int32 y)
{
App.Selected = this;
return true;
}
public override void WhileSelected()
{
int key = Raylib.GetCharPressed();
while (key > 0)
{
// NOTE: Only allow keys in range [32..125]
if ((key >= 32) && (key <= 125) && (text.Length < 100))
text.Append((char8)key);
key = Raylib.GetCharPressed(); // Check next character in the queue
}
if (Raylib.IsKeyPressed((.)KeyboardKey.KEY_BACKSPACE))
text.RemoveFromEnd(1);
if(Raylib.IsKeyPressed((.)KeyboardKey.KEY_ESCAPE))
App.Selected = null;
}
}

View file

@ -10,6 +10,14 @@ namespace RaylibBeef
return false; return false;
} }
} }
extension Color
{
public Color SetRed(uint8 red) => .(red, g, b, a);
public Color SetGreen(uint8 green) => .(r, green, b, a);
public Color SetBlue(uint8 blue) => .(r, g, blue, a);
public Color SetAlpha(uint8 alpha) => .(r, g, b, alpha);
}
} }
namespace System namespace System
@ -25,7 +33,7 @@ namespace System
Compiler.EmitTypeBody(fieldInfo.DeclaringType, scope $""" Compiler.EmitTypeBody(fieldInfo.DeclaringType, scope $"""
public StringView {fieldInfo.Name.Substring(1)} public StringView {fieldInfo.Name.Substring(1)}
{{ {{
public get => {fieldInfo.Name}; public get => {fieldInfo.Name} == null ? "" : {fieldInfo.Name}..EnsureNullTerminator();
public set => String.NewOrSet!({fieldInfo.Name}, value); public set => String.NewOrSet!({fieldInfo.Name}, value);
}}; }};
"""); """);