Merge pull request 'parts of the input field' (#9) from input_field into main
Reviewed-on: Theater/TheaterGui#9
This commit is contained in:
commit
2a37103b38
6 changed files with 89 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
FileVersion = 1
|
||||
Dependencies = {corlib = "*", raylib-beef = "*"}
|
||||
Dependencies = {corlib = "*", corlib = "*", raylib-beef = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "TheaterGui"
|
||||
|
|
|
@ -42,6 +42,7 @@ class App
|
|||
if (_CurrentScreen != null)
|
||||
delete _CurrentScreen;
|
||||
_CurrentScreen = value;
|
||||
_CurrentScreen.Reorder(Width);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -187,6 +188,9 @@ class App
|
|||
Input.HandleRightClick();
|
||||
else
|
||||
Input.HandleHover();
|
||||
|
||||
if(Selected != null)
|
||||
Selected.WhileSelected();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ abstract class Component
|
|||
{
|
||||
public this(StringView pComponentName, StringView pLabel)
|
||||
{
|
||||
_ComponentType.Append(pComponentName);
|
||||
ComponentType = pComponentName;
|
||||
Label = pLabel;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,10 @@ class Container : Component
|
|||
}
|
||||
|
||||
private List<Component> _LayoutData = new .() ~ delete _;
|
||||
|
||||
public List<Component> Children = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
|
||||
|
||||
|
||||
///Recalculate the layout of all entries
|
||||
public virtual void Reorder(int32 w)
|
||||
|
|
72
src/Components/InputField.bf
Normal file
72
src/Components/InputField.bf
Normal 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;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,14 @@ namespace RaylibBeef
|
|||
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
|
||||
|
@ -25,7 +33,7 @@ namespace System
|
|||
Compiler.EmitTypeBody(fieldInfo.DeclaringType, scope $"""
|
||||
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);
|
||||
}};
|
||||
""");
|
||||
|
|
Loading…
Add table
Reference in a new issue