Started dropdown and added sliders
This commit is contained in:
parent
9e7330d47c
commit
f6c0049e78
9 changed files with 243 additions and 13 deletions
|
@ -34,6 +34,7 @@ class MainScreen : Screen
|
|||
|
||||
AddChild("Toolbar", toAdd);
|
||||
AddChild("Button", new Button(new (val) => {Console.WriteLine("Hellau :)");}));
|
||||
AddChild("dd", new Dropdown(new (val) => {Console.WriteLine("Hellau :)");}));
|
||||
AddChild("Label", new Label("LMAO"));
|
||||
AddChild("CBox", new Checkbox("Box"));
|
||||
|
||||
|
@ -42,6 +43,9 @@ class MainScreen : Screen
|
|||
r.Label.Add(new .("Two"));
|
||||
r.Label.Add(new .("Three"));
|
||||
AddChild("radio", r);
|
||||
AddChild("hslider", new HSlider());
|
||||
AddChild("vslider", new VSlider());
|
||||
|
||||
|
||||
Layout = new (val, width) =>
|
||||
{
|
||||
|
@ -51,7 +55,11 @@ class MainScreen : Screen
|
|||
val.Component("Button");
|
||||
val.Component("CBox", 5);
|
||||
val.Linebreak();
|
||||
val.Component("radio");
|
||||
val.Component("radio", 5);
|
||||
val.Component("hslider");
|
||||
val.Component("vslider");
|
||||
val.Linebreak();
|
||||
val.Component("dd", 5);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ class Button : Component
|
|||
public String Label ~ delete _;
|
||||
delegate void(TGRuntime rt) Action ~ delete _;
|
||||
|
||||
public this(delegate void(TGRuntime rt) pToCall, StringView pName = "Button")
|
||||
public this(delegate void(TGRuntime rt) pAction, StringView pLabel = "Button")
|
||||
{
|
||||
Action = pToCall;
|
||||
Label = new .(pName);
|
||||
Label = new .(pLabel);
|
||||
Action = pAction;
|
||||
}
|
||||
|
||||
public override void Update(TheaterGui.Core.TGRuntime rt)
|
||||
|
|
68
src/Components/Dropdown.bf
Normal file
68
src/Components/Dropdown.bf
Normal file
|
@ -0,0 +1,68 @@
|
|||
namespace TheaterGui.Components;
|
||||
using TheaterGui.Core;
|
||||
using TheaterGui.Core.Structs;
|
||||
|
||||
using System;
|
||||
|
||||
class Dropdown : Component
|
||||
{
|
||||
private bool _Hovered = false;
|
||||
private bool _AlreadyHovered = false;
|
||||
|
||||
public String Label ~ delete _;
|
||||
delegate void(TGRuntime rt) Action ~ delete _;
|
||||
|
||||
public this(delegate void(TGRuntime rt) pAction, StringView pLabel = "Button")
|
||||
{
|
||||
Label = new .(pLabel);
|
||||
Action = pAction;
|
||||
}
|
||||
|
||||
public override void Update(TheaterGui.Core.TGRuntime rt)
|
||||
{
|
||||
if(_Hovered != _AlreadyHovered)
|
||||
{
|
||||
_Hovered = _AlreadyHovered;
|
||||
rt.Dirty();
|
||||
}
|
||||
_AlreadyHovered = false;
|
||||
}
|
||||
|
||||
public override void Draw(TGRuntime rt, rect rect)
|
||||
{
|
||||
rt.Platform.DrawTexture("Dropdown", rect, rt.Scheme.PrimaryColor);
|
||||
if(_Hovered)
|
||||
rt.Platform.DrawTexture("Dropdown", rect, rt.Scheme.HoverColor);
|
||||
|
||||
var tsize = rt.Platform.MeasureTextSize(Label, "Font_Normal");
|
||||
rt.Platform.DrawText(Label, "Font_Normal",
|
||||
.((.)(rect.x + 0.5*rect.width - tsize[0]*0.5),
|
||||
(.)(rect.y + 0.5*rect.height - tsize[1]*0.5))
|
||||
,rt.Scheme.TextColor);
|
||||
}
|
||||
|
||||
public override int32[2] Resize(TheaterGui.Core.TGRuntime rt, int32 width)
|
||||
{
|
||||
return rt.Platform.MeasureTextureSize("Dropdown");
|
||||
}
|
||||
|
||||
public override bool OnHover(TGRuntime rt, int32[2] mPos)
|
||||
{
|
||||
_AlreadyHovered = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnLeftClick(TGRuntime rt, int32[2] mPos)
|
||||
{
|
||||
Action.Invoke(rt);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnScroll(TGRuntime rt, float pOffset) => false;
|
||||
|
||||
public override bool OnRightClick(TGRuntime rt, int32[2] mPos, System.Collections.List<(String, delegate void(TGRuntime))> pList)
|
||||
{
|
||||
pList.Add((.)(new String(scope $"Click {Label}"), new (rt) => {this.Action.Invoke(rt);}));
|
||||
return true;
|
||||
}
|
||||
}
|
75
src/Components/HSlider.bf
Normal file
75
src/Components/HSlider.bf
Normal file
|
@ -0,0 +1,75 @@
|
|||
namespace TheaterGui.Components;
|
||||
using TheaterGui.Core;
|
||||
using TheaterGui.Core.Structs;
|
||||
|
||||
using System;
|
||||
|
||||
class HSlider : Component
|
||||
{
|
||||
private bool _Hovered = false;
|
||||
private bool _AlreadyHovered = false;
|
||||
|
||||
public float Value = 0;
|
||||
|
||||
public this()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(TheaterGui.Core.TGRuntime rt)
|
||||
{
|
||||
if (_Hovered != _AlreadyHovered)
|
||||
{
|
||||
_Hovered = _AlreadyHovered;
|
||||
rt.Dirty();
|
||||
}
|
||||
_AlreadyHovered = false;
|
||||
}
|
||||
|
||||
public override void Draw(TGRuntime rt, rect rect)
|
||||
{
|
||||
var ts = rt.Platform.MeasureTextureSize("Checkbox");
|
||||
|
||||
rt.Platform.DrawColorRect(.() { x = rect.x + ts[0], width = rect.width-2*ts[0], y = rect.y + ts[1] / 2 - 4, height = 8 }, rt.Scheme.AcceptColor);
|
||||
rt.Platform.DrawTexture("Checkbox", .() { x = (.)(rect.x + ts[0] + Value * 10*ts[0]-ts[0]/2), y = rect.y, width = ts[0], height = ts[1] }, rt.Scheme.PrimaryColor);
|
||||
if (_Hovered)
|
||||
rt.Platform.DrawTexture("Checkbox", .() { x = (.)(rect.x + ts[0] + Value * 10*ts[0]-ts[0]/2), y = rect.y, width = ts[0], height = ts[1] }, rt.Scheme.HoverColor);
|
||||
}
|
||||
|
||||
public override int32[2] Resize(TheaterGui.Core.TGRuntime rt, int32 width)
|
||||
{
|
||||
var ts = rt.Platform.MeasureTextureSize("Checkbox");
|
||||
return .(ts[0] * 12, ts[1]);
|
||||
}
|
||||
|
||||
public override bool OnHover(TGRuntime rt, int32[2] mPos)
|
||||
{
|
||||
_AlreadyHovered = true;
|
||||
if(rt.Platform.MouseLeftClick())
|
||||
{
|
||||
float oldVal = Value;
|
||||
OnLeftClick(rt, mPos);
|
||||
if(Value != oldVal)
|
||||
rt.Dirty();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnLeftClick(TGRuntime rt, int32[2] mPos)
|
||||
{
|
||||
var ts = rt.Platform.MeasureTextureSize("Checkbox");
|
||||
if(mPos[0] <= ts[0])
|
||||
Value = 0;
|
||||
else if(mPos[0] >= ts[0] * 11)
|
||||
Value = 1;
|
||||
else
|
||||
{
|
||||
float ofst = mPos[0] - ts[0];
|
||||
Value = Math.Clamp(ofst / (ts[0]*10)
|
||||
,0,1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnScroll(TGRuntime rt, float pOffset) => false;
|
||||
public override bool OnRightClick(TGRuntime rt, int32[2] mPos, System.Collections.List<(String, delegate void(TGRuntime))> pList) => false;
|
||||
}
|
|
@ -59,12 +59,12 @@ class RadioButton : Component
|
|||
for(var label in Label)
|
||||
{
|
||||
var tsize = rt.Platform.MeasureTextSize(label, "Font_Normal");
|
||||
if(tsize[0] + 5 < xAddition)
|
||||
if(tsize[0] + 5 > xAddition)
|
||||
xAddition = tsize[0] + 5;
|
||||
textureSize[1] += rt.Platform.MeasureTextureSize("Checkbox")[1];
|
||||
}
|
||||
|
||||
textureSize[0] += xAddition;
|
||||
textureSize[0] = textureSize[0] + xAddition;
|
||||
textureSize[1] = (.)(textureSize[1] * Label.Count);
|
||||
return textureSize;
|
||||
}
|
||||
|
||||
|
|
76
src/Components/VSlider.bf
Normal file
76
src/Components/VSlider.bf
Normal file
|
@ -0,0 +1,76 @@
|
|||
namespace TheaterGui.Components;
|
||||
using TheaterGui.Core;
|
||||
using TheaterGui.Core.Structs;
|
||||
|
||||
using System;
|
||||
|
||||
class VSlider : Component
|
||||
{
|
||||
private bool _Hovered = false;
|
||||
private bool _AlreadyHovered = false;
|
||||
|
||||
public float Value = 0;
|
||||
|
||||
public this()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Update(TheaterGui.Core.TGRuntime rt)
|
||||
{
|
||||
if (_Hovered != _AlreadyHovered)
|
||||
{
|
||||
_Hovered = _AlreadyHovered;
|
||||
rt.Dirty();
|
||||
}
|
||||
_AlreadyHovered = false;
|
||||
}
|
||||
|
||||
public override void Draw(TGRuntime rt, rect rect)
|
||||
{
|
||||
var ts = rt.Platform.MeasureTextureSize("Checkbox");
|
||||
|
||||
rt.Platform.DrawColorRect(.() { x = rect.x + ts[0] / 2 - 4, width = 8, y = rect.y + ts[1], height = rect.height-2*ts[1] }, rt.Scheme.AcceptColor);
|
||||
|
||||
rt.Platform.DrawTexture("Checkbox", .() { y = (.)(rect.y + ts[1] + Value * 10*ts[1]-ts[1]/2), x = rect.x, height = ts[1], width = ts[0] }, rt.Scheme.PrimaryColor);
|
||||
if (_Hovered)
|
||||
rt.Platform.DrawTexture("Checkbox", .() { y = (.)(rect.y + ts[1] + Value * 10*ts[1]-ts[1]/2), x = rect.x, height = ts[1], width = ts[0] }, rt.Scheme.HoverColor);
|
||||
}
|
||||
|
||||
public override int32[2] Resize(TheaterGui.Core.TGRuntime rt, int32 width)
|
||||
{
|
||||
var ts = rt.Platform.MeasureTextureSize("Checkbox");
|
||||
return .(ts[0], ts[1] * 12);
|
||||
}
|
||||
|
||||
public override bool OnHover(TGRuntime rt, int32[2] mPos)
|
||||
{
|
||||
_AlreadyHovered = true;
|
||||
if(rt.Platform.MouseLeftClick())
|
||||
{
|
||||
float oldVal = Value;
|
||||
OnLeftClick(rt, mPos);
|
||||
if(Value != oldVal)
|
||||
rt.Dirty();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnLeftClick(TGRuntime rt, int32[2] mPos)
|
||||
{
|
||||
var ts = rt.Platform.MeasureTextureSize("Checkbox");
|
||||
if(mPos[1] <= ts[1])
|
||||
Value = 0;
|
||||
else if(mPos[1] >= ts[1] * 11)
|
||||
Value = 1;
|
||||
else
|
||||
{
|
||||
float ofst = mPos[1] - ts[1];
|
||||
Value = Math.Clamp(ofst / (ts[1]*10)
|
||||
,0,1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnScroll(TGRuntime rt, float pOffset) => false;
|
||||
public override bool OnRightClick(TGRuntime rt, int32[2] mPos, System.Collections.List<(String, delegate void(TGRuntime))> pList) => false;
|
||||
}
|
|
@ -8,6 +8,7 @@ struct theme
|
|||
private static uint8[?] _Theme_Button = Compiler.ReadBinary("assets/button.png");
|
||||
private static uint8[?] _Theme_Checkbox = Compiler.ReadBinary("assets/checkbox.png");
|
||||
private static uint8[?] _Theme_Checkbox_Checked = Compiler.ReadBinary("assets/checkbox_checked.png");
|
||||
private static uint8[?] _Theme_Dropdown = Compiler.ReadBinary("assets/dropdown.png");
|
||||
|
||||
/*
|
||||
private static uint8[?] Texture_SquareButton = Compiler.ReadBinary("assets/square_button.png");
|
||||
|
@ -15,11 +16,12 @@ struct theme
|
|||
private static uint8[?] Texture_NButton = Compiler.ReadBinary("assets/n_button.png");
|
||||
|
||||
private static uint8[?] Horizontal_Patch = Compiler.ReadBinary("assets/horizontal_patch.png");
|
||||
private static uint8[?] Dropdown = Compiler.ReadBinary("assets/dropdown.png");
|
||||
*/
|
||||
|
||||
public (Span<uint8>, uint8) Font_Normal = (.(&_Theme_Font, _Theme_Font.Count),16);
|
||||
public Span<uint8> Button = .(&_Theme_Button, _Theme_Button.Count);
|
||||
public Span<uint8> Checkbox = .(&_Theme_Checkbox, _Theme_Checkbox.Count);
|
||||
public Span<uint8> Checkbox_Checked = .(&_Theme_Checkbox_Checked, _Theme_Checkbox_Checked.Count);
|
||||
public Span<uint8> Dropdown = .(&_Theme_Dropdown, _Theme_Dropdown.Count);
|
||||
|
||||
}
|
|
@ -120,6 +120,7 @@ class TGRuntime
|
|||
Platform.LoadFont(pStartingTheme.Font_Normal.0, "Font_Normal", pStartingTheme.Font_Normal.1);
|
||||
Platform.LoadTexture(pStartingTheme.Button, "Button");
|
||||
Platform.LoadTexture(pStartingTheme.Checkbox, "Checkbox");
|
||||
Platform.LoadTexture(pStartingTheme.Dropdown, "Dropdown");
|
||||
Platform.LoadTexture(pStartingTheme.Checkbox_Checked, "Checkbox_Checked");
|
||||
|
||||
}
|
||||
|
|
10
src/TODO
10
src/TODO
|
@ -2,17 +2,17 @@ TODO:
|
|||
TabbedContainers
|
||||
Fixed size containers
|
||||
Collapseables
|
||||
Dropdown
|
||||
Textfields
|
||||
Textboxes
|
||||
TextDisplays
|
||||
Icon buttons
|
||||
Horizontal sliders
|
||||
Vertical sliders
|
||||
Code cleanup
|
||||
|
||||
|
||||
Being Worked on:
|
||||
Dropdown
|
||||
|
||||
Done
|
||||
Radio Buttons
|
||||
Done:
|
||||
Radio Buttons
|
||||
Horizontal sliders
|
||||
Vertical sliders
|
Loading…
Add table
Add a link
Reference in a new issue