Finished dropdowns and added basic right click behaviour
This commit is contained in:
parent
d6f4f595ea
commit
b3ffd2739a
28 changed files with 689 additions and 24 deletions
BIN
assets/dropdown.png
Normal file
BIN
assets/dropdown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 559 B |
BIN
assets/dropdown.png~
Normal file
BIN
assets/dropdown.png~
Normal file
Binary file not shown.
After Width: | Height: | Size: 117 B |
52
src/App.bf
52
src/App.bf
|
@ -9,7 +9,7 @@ class App
|
|||
{
|
||||
|
||||
//All loaded textures
|
||||
private static List<PopupComponent> Popups = new .() ~ DeleteContainerAndItems!(_);
|
||||
private static List<Popup> Popups = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
//For hover items
|
||||
private static Vector2 oldPos = .(0,0);
|
||||
|
@ -65,7 +65,7 @@ class App
|
|||
CurrentScreen.Reorder(Width);
|
||||
}
|
||||
|
||||
public static void OpenPopup(PopupComponent popup)
|
||||
public static void OpenPopup(Popup popup)
|
||||
{
|
||||
Popups.Add(popup);
|
||||
}
|
||||
|
@ -128,6 +128,21 @@ class App
|
|||
|
||||
if(Raylib.IsMouseButtonPressed(0))
|
||||
HandleLeftClick();
|
||||
else if(Raylib.IsMouseButtonDown(0))
|
||||
HandleButtonDown();
|
||||
else if(Raylib.IsMouseButtonPressed(1))
|
||||
{
|
||||
if(Popups.Count > 0)
|
||||
{
|
||||
var top = Popups[Popups.Count-1];
|
||||
if(top is RightClickPopup)
|
||||
{
|
||||
Popups.Remove(top);
|
||||
delete top;
|
||||
}
|
||||
}
|
||||
Popups.Add(new RightClickPopup((.)Mouse.x, (.)Mouse.y, new .("Items", new .("First one", new () => {}), new .("Second", new () => {}), new .("Fourth", new () => {}), new .("Third", new () => {}) )));
|
||||
}
|
||||
else
|
||||
HandleHover();
|
||||
|
||||
|
@ -177,20 +192,43 @@ class App
|
|||
{ //Only checking the topmost popup
|
||||
var top = Popups[Popups.Count-1];
|
||||
if(Rectangle(top.X, top.Y, top.Width, top.Height).Overlaps(Raylib.GetMouseX(), (.)(Raylib.GetMouseY()-Wheel)))
|
||||
top.OnClick(Raylib.GetMouseX(), Raylib.GetMouseY());
|
||||
{
|
||||
if(!top.OnClick(Raylib.GetMouseX(), Raylib.GetMouseY()))
|
||||
{
|
||||
Popups.Remove(top);
|
||||
top.OnClose(); //Any last words ?
|
||||
delete top;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
bool a = top is DropdownPopup; //TODO: Make this less horrible
|
||||
|
||||
Popups.Remove(top);
|
||||
top.OnClose(); //Any last words ?
|
||||
delete top;
|
||||
|
||||
CurrentScreen.OnClick(Raylib.GetMouseX(), (.)(Raylib.GetMouseY()-App.Wheel)); //So that we dont eat any inputs
|
||||
if(!a)
|
||||
CurrentScreen.OnClick(Raylib.GetMouseX(), (.)(Raylib.GetMouseY()-App.Wheel)); //So that we dont eat any inputs
|
||||
}
|
||||
}
|
||||
else
|
||||
CurrentScreen.OnClick(Raylib.GetMouseX(), (.)(Raylib.GetMouseY()-App.Wheel));
|
||||
}
|
||||
|
||||
private static bool HandleButtonDown()
|
||||
{
|
||||
//Topmost first
|
||||
for(var i in Popups.Reversed)
|
||||
{
|
||||
var hoverResult = i.OnDown(Raylib.GetMouseX(), Raylib.GetMouseY()-(.)Wheel);
|
||||
if(hoverResult == false)
|
||||
continue;
|
||||
return hoverResult;
|
||||
}
|
||||
return CurrentScreen.OnDown(Raylib.GetMouseX(), (.)(Raylib.GetMouseY()-App.Wheel));
|
||||
}
|
||||
|
||||
///Handles the hovering effect
|
||||
private static void HandleHover()
|
||||
{
|
||||
|
@ -233,4 +271,6 @@ class App
|
|||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ abstract class Component
|
|||
public abstract void Render(int32 soy);
|
||||
|
||||
public virtual bool OnClick(int32 x, int32 y) => false;
|
||||
public virtual bool OnDown(int32 x, int32 y) => false;
|
||||
public abstract Component OnHover(int32 x, int32 y);
|
||||
|
||||
public virtual void WhileSelected() { }
|
||||
|
|
|
@ -146,6 +146,16 @@ class Container : Component
|
|||
return false;
|
||||
}
|
||||
|
||||
public override bool OnDown(int32 x, int32 y)
|
||||
{
|
||||
for(var e in Children)
|
||||
{
|
||||
if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y))
|
||||
return e.OnDown(x, y);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Component OnHover(int32 x, int32 y)
|
||||
{
|
||||
for(var e in Children)
|
||||
|
|
57
src/Components/Dropdown.bf
Normal file
57
src/Components/Dropdown.bf
Normal file
|
@ -0,0 +1,57 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using RaylibBeef;
|
||||
|
||||
abstract class Dropdown : Component
|
||||
{
|
||||
public List<String> Entries = new .() ~ DeleteContainerAndItems!(_);
|
||||
public uint32 SelectedEntry = 0;
|
||||
|
||||
public this() : base("Dropdown", "Label")
|
||||
{
|
||||
Margin = 20;
|
||||
Sprite = App.Textures.GetAsset("dropdown");
|
||||
Width = Sprite.Width;
|
||||
Height = Sprite.Height;
|
||||
}
|
||||
|
||||
public override void Render(int32 soy)
|
||||
{
|
||||
Sprite.Render(X,Y + soy, Tint);
|
||||
var measure = Raylib.MeasureTextEx(Theme.Font, Entries[SelectedEntry], Theme.FontSize, 0);
|
||||
Raylib.DrawTextEx(Theme.Font, Entries[SelectedEntry], .(X+Width/2-measure.x/2,Y+Height/2-measure.y/2 + soy), Theme.FontSize, 0, Theme.Text);
|
||||
if(!Enabled)
|
||||
{
|
||||
Sprite.Render(X,Y + soy, Theme.DisabledTint);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_IsHovered)
|
||||
Sprite.Render(X,Y + soy, HoverTint);
|
||||
}
|
||||
_IsHovered = false;
|
||||
}
|
||||
|
||||
public override bool OnClick(int32 x, int32 y)
|
||||
{
|
||||
var list = new List<StringView>(Entries.Count);
|
||||
defer delete list;
|
||||
for(var i in Entries)
|
||||
list.Add(i);
|
||||
var popup = new DropdownPopup(X, Y + Height, Width, list);
|
||||
popup.Owner = this;
|
||||
App.OpenPopup(popup);
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void ClickAction(String pNewVal);
|
||||
|
||||
protected bool _IsHovered = false;
|
||||
public override Component OnHover(int32 x, int32 y)
|
||||
{
|
||||
_IsHovered = true;
|
||||
return this;
|
||||
}
|
||||
}
|
109
src/Components/DropdownPopup.bf
Normal file
109
src/Components/DropdownPopup.bf
Normal file
|
@ -0,0 +1,109 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using RaylibBeef;
|
||||
|
||||
class DropdownPopup : Popup
|
||||
{
|
||||
public NPatchInfo PatchInfo;
|
||||
public int32 SelectedItem = -1;
|
||||
public Dropdown Owner = null;
|
||||
public List<String> Options = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
public this(int32 x, int32 y, int32 w, params Span<StringView> options) : base("DropdownPopup", "DropdownPopup")
|
||||
{
|
||||
this.[Friend]X = x;
|
||||
this.[Friend]Y = y-1;
|
||||
Sprite = App.Textures.GetAsset("horizontal_patch");
|
||||
PatchInfo =.(Sprite.SourceRect, 2,2,2,2,(.)NPatchLayout.NPATCH_NINE_PATCH);
|
||||
for(var i in options)
|
||||
Options.Add(new .(i));
|
||||
Width = w;
|
||||
Height = ((.)Options.Count * (Theme.FontSize+10))-5;
|
||||
}
|
||||
|
||||
public this(int32 x, int32 y, int32 w, List<StringView> options) : base("DropdownPopup", "DropdownPopup")
|
||||
{
|
||||
this.[Friend]X = x;
|
||||
this.[Friend]Y = y-1;
|
||||
Sprite = App.Textures.GetAsset("horizontal_patch");
|
||||
PatchInfo =.(Sprite.SourceRect, 2,2,2,2,(.)NPatchLayout.NPATCH_NINE_PATCH);
|
||||
for(var i in options)
|
||||
Options.Add(new .(i));
|
||||
Width = w;
|
||||
Height = ((.)Options.Count * (Theme.FontSize+10))-5;
|
||||
}
|
||||
|
||||
public override void Render(int32 soy)
|
||||
{
|
||||
Raylib.DrawTextureNPatch(
|
||||
*Sprite.Source,
|
||||
PatchInfo,
|
||||
.(X, Y + soy, Width, Height),
|
||||
.(0,0),
|
||||
0,
|
||||
Tint);
|
||||
int32 y = 5;
|
||||
for(var i in Options)
|
||||
{
|
||||
Raylib.DrawTextEx(Theme.Font, scope String(i), .(X + 5, Y + y + soy), Theme.FontSize, 0, Theme.Text);
|
||||
if(@i.Index == SelectedItem)
|
||||
{
|
||||
Raylib.DrawTextureNPatch(
|
||||
*Sprite.Source,
|
||||
PatchInfo,
|
||||
.(X, Y + y - 4 + soy, Width, Theme.FontSize+10),
|
||||
.(0,0),
|
||||
0,
|
||||
HoverTint);
|
||||
}
|
||||
|
||||
y += (.)Theme.FontSize+5;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnClick(int32 x, int32 y)
|
||||
{
|
||||
if(!(x >= X && x <= X + Width))
|
||||
return false;
|
||||
|
||||
int32 pos = 5 + Y;
|
||||
for(var i in Options)
|
||||
{
|
||||
if(y >= pos && y <= pos + (.)Theme.FontSize+5)
|
||||
{
|
||||
if(Owner != null)
|
||||
{
|
||||
Owner.SelectedEntry = (.)@i.Index;
|
||||
Owner.ClickAction(i);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
pos += (.)Theme.FontSize+5;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Component OnHover(int32 x, int32 y)
|
||||
{
|
||||
int32 pos = 5 + Y;
|
||||
for(var i in Options)
|
||||
{
|
||||
if(y >= pos && y <= pos + (.)Theme.FontSize+5)
|
||||
{
|
||||
SelectedItem = (.)@i.Index;
|
||||
return this;
|
||||
}
|
||||
pos += (.)Theme.FontSize+5;
|
||||
}
|
||||
SelectedItem = -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void OnClose()
|
||||
{
|
||||
}
|
||||
}
|
11
src/Components/HSlider.bf
Normal file
11
src/Components/HSlider.bf
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
using System;
|
||||
|
||||
abstract class HSlider : NHSlider
|
||||
{
|
||||
public this(StringView pLabel) : base(32 * 6, pLabel, "HSlider")
|
||||
{
|
||||
|
||||
}
|
||||
}
|
78
src/Components/NHSlider.bf
Normal file
78
src/Components/NHSlider.bf
Normal file
|
@ -0,0 +1,78 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
using System;
|
||||
using RaylibBeef;
|
||||
|
||||
//This slider may be any size
|
||||
abstract class NHSlider : Component
|
||||
{
|
||||
private bool _CurrentlyDragged = false; //Used to stop accidental hovers
|
||||
public int32 BarWidth = 0;
|
||||
public float Percentage = 0;
|
||||
public float Min = 0;
|
||||
public float Max = 0;
|
||||
public float Value
|
||||
{
|
||||
get => Min + Percentage * (Max-Min);
|
||||
set => Percentage = (value - Min)/(Max-Min); //This should be mathematically fine, no clue if its actually fine though
|
||||
}
|
||||
|
||||
public bool ReactToValueChange = false; //Calling on value change too frequently might not be good so we clear here
|
||||
public virtual void OnValueChange(float newVal)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public this(int32 width, StringView pLabel, StringView pTypename = "NHSlider") : base(pTypename, pLabel)
|
||||
{
|
||||
Sprite = App.Textures.GetAsset("checkbox");
|
||||
Width = width + Sprite.Width;
|
||||
BarWidth = width;
|
||||
Height = Sprite.Height;
|
||||
}
|
||||
|
||||
|
||||
public override void Render(int32 soy)
|
||||
{
|
||||
Raylib.DrawRectangle(X + Sprite.Width/2, Y + Sprite.Height/2 - 4 + soy, BarWidth, 8, Raylib.BLACK);
|
||||
Sprite.Render((.)(X+ Percentage * BarWidth), Y + soy, Tint);
|
||||
if(_IsHovered)
|
||||
Sprite.Render((.)(X +Percentage * BarWidth), Y + soy, HoverTint);
|
||||
_IsHovered = false;
|
||||
|
||||
if(!Raylib.IsMouseButtonDown(0))
|
||||
_CurrentlyDragged = false;
|
||||
}
|
||||
|
||||
public override bool OnClick(int32 x, int32 y)
|
||||
{
|
||||
_CurrentlyDragged = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnDown(int32 x, int32 y)
|
||||
{
|
||||
if(_CurrentlyDragged)
|
||||
{
|
||||
float np = 0;
|
||||
np = x - X;
|
||||
np = Math.Clamp(np, Sprite.Width/2, Width - Sprite.Width/2); //Not rly clamp
|
||||
np -= Sprite.Width/2;
|
||||
np = np / (BarWidth); //I fucking hate that this works
|
||||
|
||||
float oldp = Percentage;
|
||||
Percentage = np;
|
||||
if(ReactToValueChange && oldp != Percentage)
|
||||
OnValueChange(Min + np * (Max-Min));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected bool _IsHovered = false;
|
||||
public override Component OnHover(int32 x, int32 y)
|
||||
{
|
||||
_IsHovered = true;
|
||||
return this;
|
||||
}
|
||||
}
|
78
src/Components/NVSlider.bf
Normal file
78
src/Components/NVSlider.bf
Normal file
|
@ -0,0 +1,78 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
using System;
|
||||
using RaylibBeef;
|
||||
|
||||
//This slider may be any size
|
||||
abstract class NVSlider : Component
|
||||
{
|
||||
private bool _CurrentlyDragged = false; //Used to stop accidental hovers
|
||||
public int32 BarHeight = 0;
|
||||
public float Percentage = 0;
|
||||
public float Min = 0;
|
||||
public float Max = 0;
|
||||
public float Value
|
||||
{
|
||||
get => Min + Percentage * (Max-Min);
|
||||
set => Percentage = (value - Min)/(Max-Min); //This should be mathematically fine, no clue if its actually fine though
|
||||
}
|
||||
|
||||
public bool ReactToValueChange = false; //Calling on value change too frequently might not be good so we clear here
|
||||
public virtual void OnValueChange(float newVal)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public this(int32 height, StringView pLabel, StringView pTypeName = "NVSlider") : base(pTypeName, pLabel)
|
||||
{
|
||||
Sprite = App.Textures.GetAsset("checkbox");
|
||||
Width = Sprite.Width;
|
||||
BarHeight = height;
|
||||
Height = Sprite.Height + height;
|
||||
}
|
||||
|
||||
|
||||
public override void Render(int32 soy)
|
||||
{
|
||||
Raylib.DrawRectangle(X + Sprite.Width/2 - 4, Y + Sprite.Height/2 + soy, 8, BarHeight, Raylib.BLACK);
|
||||
Sprite.Render(X, Y + soy + Percentage * BarHeight, Tint);
|
||||
if(_IsHovered)
|
||||
Sprite.Render(X, Y + soy + Percentage * BarHeight, HoverTint);
|
||||
_IsHovered = false;
|
||||
|
||||
if(!Raylib.IsMouseButtonDown(0))
|
||||
_CurrentlyDragged = false;
|
||||
}
|
||||
|
||||
public override bool OnClick(int32 x, int32 y)
|
||||
{
|
||||
_CurrentlyDragged = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnDown(int32 x, int32 y)
|
||||
{
|
||||
if(_CurrentlyDragged)
|
||||
{
|
||||
float np = 0;
|
||||
np = y - Y;
|
||||
np = Math.Clamp(np, Sprite.Height/2, Height - Sprite.Height/2); //Not rly clamp
|
||||
np -= Sprite.Height/2;
|
||||
np = np / (BarHeight); //I fucking hate that this works
|
||||
|
||||
float oldp = Percentage;
|
||||
Percentage = np;
|
||||
if(ReactToValueChange && oldp != Percentage)
|
||||
OnValueChange(Min + np * (Max-Min));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected bool _IsHovered = false;
|
||||
public override Component OnHover(int32 x, int32 y)
|
||||
{
|
||||
_IsHovered = true;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
abstract class PopupComponent : Component
|
||||
abstract class Popup : Component
|
||||
{
|
||||
public this(System.StringView pComponentName, System.StringView pLabel) : base(pComponentName, pLabel)
|
||||
{
|
111
src/Components/RightClickPopup.bf
Normal file
111
src/Components/RightClickPopup.bf
Normal file
|
@ -0,0 +1,111 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
using System;
|
||||
using RaylibBeef;
|
||||
using System.Collections;
|
||||
|
||||
class RightClickPopup : Popup
|
||||
{
|
||||
public NPatchInfo PatchInfo;
|
||||
public Toolbar.ToolbarCategory.ToolbarItem SelectedItem = null;
|
||||
|
||||
private Toolbar.ToolbarCategory _Category = null ~ delete _;
|
||||
public Toolbar.ToolbarCategory Category
|
||||
{
|
||||
get => _Category;
|
||||
set
|
||||
{
|
||||
_Category = value;
|
||||
int32 maxWidth = 0;
|
||||
for(var i in _Category.Items)
|
||||
if(maxWidth <= i.NameMeasurement.x)
|
||||
maxWidth = (.)i.NameMeasurement.x;
|
||||
|
||||
Width = maxWidth + 10 + 32;
|
||||
Height = (.)(5 +((_Category.NameMeasurement.y + 5) * _Category.Items.Count));
|
||||
}
|
||||
}
|
||||
|
||||
public this(int32 x, int32 y, Toolbar.ToolbarCategory category) : base("ToolbarPopup", category.Name)
|
||||
{
|
||||
this.[Friend]X = x;
|
||||
this.[Friend]Y = y-1;
|
||||
Sprite = App.Textures.GetAsset("n_button");
|
||||
PatchInfo =.(Sprite.SourceRect, 2,2,2,2,(.)NPatchLayout.NPATCH_NINE_PATCH);
|
||||
Category = category;
|
||||
}
|
||||
|
||||
public override void Render(int32 soy)
|
||||
{
|
||||
Raylib.DrawTextureNPatch(
|
||||
*Sprite.Source,
|
||||
PatchInfo,
|
||||
.(X, Y + soy, Width, Height),
|
||||
.(0,0),
|
||||
0,
|
||||
Tint);
|
||||
int32 y = 5;
|
||||
for(var i in Category.Items)
|
||||
{
|
||||
Raylib.DrawTextEx(Theme.Font, scope String(i.Name), .(X + 5 + 32, Y + y + soy), Theme.FontSize, 0, Theme.Text);
|
||||
if(SelectedItem == i)
|
||||
{
|
||||
Raylib.DrawTextureNPatch(
|
||||
*Sprite.Source,
|
||||
PatchInfo,
|
||||
.(X, Y + y - 5 + soy, Width, i.NameMeasurement.y+10),
|
||||
.(0,0),
|
||||
0,
|
||||
HoverTint);
|
||||
}
|
||||
|
||||
y += (.)i.NameMeasurement.y+5;
|
||||
}
|
||||
}
|
||||
|
||||
public override Component OnHover(int32 x, int32 y)
|
||||
{
|
||||
if(!(x >= X && x <= X + Width))
|
||||
{
|
||||
SelectedItem = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
int32 pos = 5 + Y;
|
||||
for(var i in Category.Items)
|
||||
{
|
||||
if(y >= pos && y <= pos + (.)i.NameMeasurement.y+5)
|
||||
{
|
||||
SelectedItem = i;
|
||||
return this;
|
||||
}
|
||||
pos += (.)i.NameMeasurement.y+5;
|
||||
}
|
||||
SelectedItem = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public override bool OnClick(int32 x, int32 y)
|
||||
{
|
||||
if(!(x >= X && x <= X + Width))
|
||||
return false;
|
||||
|
||||
int32 pos = 5 + Y;
|
||||
for(var i in Category.Items)
|
||||
{
|
||||
if(y >= pos && y <= pos + (.)i.NameMeasurement.y+5)
|
||||
{
|
||||
if(i.ClickAction != null)
|
||||
i.ClickAction();
|
||||
return false;
|
||||
}
|
||||
pos += (.)i.NameMeasurement.y+5;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnClose()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -4,24 +4,18 @@ using System;
|
|||
using System.Collections;
|
||||
using RaylibBeef;
|
||||
|
||||
class Toolbar : Component
|
||||
abstract class Toolbar : Component
|
||||
{
|
||||
public NPatchInfo PatchInfo;
|
||||
public List<ToolbarCategory> Categories = new .() ~ DeleteContainerAndItems!(_);
|
||||
private ToolbarPopup _CurrentPopup = null;
|
||||
private ToolbarCategory _SelectedPopup = null;
|
||||
|
||||
|
||||
|
||||
public this(StringView pLabel) : base("Toolbar", pLabel)
|
||||
{
|
||||
Height = 24;
|
||||
Sprite = App.Textures.GetAsset("horizontal_patch");
|
||||
PatchInfo =.(Sprite.SourceRect, 2,2,2,2,(.)NPatchLayout.NPATCH_NINE_PATCH);
|
||||
|
||||
Categories.Add(new .("File", new .("Load file", new () => { Raylib.MinimizeWindow();}), new .("Save file",null), new .("Recent Files",null)));
|
||||
Categories.Add(new .("Edit", new .("Revert",null), new .("Really long thing goes here",null)));
|
||||
Categories.Add(new .("Secret third thing", new .("Load file",null), new .("Save file",null), new .("Recent Files",null)));
|
||||
}
|
||||
|
||||
public override void Render(int32 soy)
|
||||
|
@ -60,7 +54,7 @@ class Toolbar : Component
|
|||
{
|
||||
if(x >= hor && x <= hor + i.NameMeasurement.x)
|
||||
{
|
||||
var popup = new ToolbarPopup(hor-10,Height, i);
|
||||
var popup = new ToolbarPopup(hor-10,Height + Y, i);
|
||||
popup.Owner = this;
|
||||
App.OpenPopup(popup);
|
||||
_CurrentPopup = popup;
|
||||
|
@ -94,6 +88,13 @@ class Toolbar : Component
|
|||
return null;
|
||||
}
|
||||
|
||||
public void AddToolbarCategories(params Span<ToolbarCategory> pCategories)
|
||||
{
|
||||
for(var i in pCategories)
|
||||
Categories.Add(i);
|
||||
}
|
||||
|
||||
///Toolbar data is stored in here
|
||||
public class ToolbarCategory
|
||||
{
|
||||
private String _Name = null ~ delete _;
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace TheaterGui.Components;
|
|||
using System;
|
||||
using RaylibBeef;
|
||||
|
||||
class ToolbarPopup : PopupComponent
|
||||
class ToolbarPopup : Popup
|
||||
{
|
||||
public NPatchInfo PatchInfo;
|
||||
public Toolbar Owner = null;
|
||||
|
|
11
src/Components/VSlider.bf
Normal file
11
src/Components/VSlider.bf
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace TheaterGui.Components;
|
||||
|
||||
using System;
|
||||
|
||||
abstract class VSlider : NVSlider
|
||||
{
|
||||
public this(StringView pLabel) : base(32 * 6, pLabel, "VSlider")
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ class ButtonGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : Button
|
||||
{{
|
||||
|
|
|
@ -27,7 +27,7 @@ class CheckboxGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : Checkbox
|
||||
{{
|
||||
|
|
|
@ -22,7 +22,7 @@ class ContainerGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : Screen
|
||||
{{
|
||||
|
|
54
src/Generators/DropdownGenerator.bf
Normal file
54
src/Generators/DropdownGenerator.bf
Normal file
|
@ -0,0 +1,54 @@
|
|||
namespace TheaterGui.Generators;
|
||||
|
||||
using System;
|
||||
|
||||
class DropdownGenerator : Compiler.Generator
|
||||
{
|
||||
public override String Name => "TheaterGui -> Dropdown"
|
||||
|
||||
public override void InitUI()
|
||||
{
|
||||
AddEdit("name", "Button Name", "");
|
||||
AddEdit("description", "Description", "");
|
||||
AddEdit("content", "Entries", "Seperate entries via ';'");
|
||||
}
|
||||
|
||||
public override void Generate(String outFileName, String outText, ref Flags generateFlags)
|
||||
{
|
||||
var name = mParams["name"];
|
||||
if (name.EndsWith(".bf", .OrdinalIgnoreCase))
|
||||
name.RemoveFromEnd(3);
|
||||
|
||||
var description = mParams["description"];
|
||||
var entries = mParams["content"];
|
||||
|
||||
|
||||
outFileName.Append(scope $"TG{name}");
|
||||
|
||||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Components;
|
||||
using System;
|
||||
|
||||
class TG{name} : Dropdown
|
||||
{{
|
||||
public this() : base()
|
||||
{{
|
||||
Description = "{description}";
|
||||
""");
|
||||
var split = entries.Split(';');
|
||||
for(var i in split)
|
||||
outText.Append(scope $"\t\tEntries.Add(new .(\"{i}\"));\n");
|
||||
outText.Append(scope $"""
|
||||
}}
|
||||
|
||||
//What happens when the button is clicked
|
||||
public override void ClickAction(String newValue)
|
||||
{{
|
||||
|
||||
}}
|
||||
}}
|
||||
""");
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ class IconButtonGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : IconButton
|
||||
{{
|
||||
|
|
|
@ -27,7 +27,7 @@ class LargeButtonGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : LargeButton
|
||||
{{
|
||||
|
|
|
@ -27,7 +27,7 @@ class NButtonGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : NButton
|
||||
{{
|
||||
|
|
|
@ -27,7 +27,7 @@ class RadioButtonGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : RadioButton
|
||||
{{
|
||||
|
|
|
@ -22,7 +22,7 @@ class ScreenGenerator : Compiler.Generator
|
|||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Controls;
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : Screen
|
||||
{{
|
||||
|
|
57
src/Generators/SliderGenerator.bf
Normal file
57
src/Generators/SliderGenerator.bf
Normal file
|
@ -0,0 +1,57 @@
|
|||
namespace TheaterGui.Generators;
|
||||
|
||||
using System;
|
||||
|
||||
class SliderGenerator : Compiler.Generator
|
||||
{
|
||||
public override String Name => "TheaterGui -> Generate Slider"
|
||||
|
||||
public override void InitUI()
|
||||
{
|
||||
AddEdit("name", "Slider Name", "");
|
||||
AddCombo("orientation", "Orientation", "Horizontal", .(scope StringView[]("Horizontal", "Vertical")));
|
||||
AddCheckbox("length", "Fixed Length", true);
|
||||
AddEdit("min", "Minimal Value", "0");
|
||||
AddEdit("max", "Maximal Value", "100");
|
||||
AddEdit("dfault", "Starting Value", "50");
|
||||
}
|
||||
|
||||
public override void Generate(String outFileName, String outText, ref Flags generateFlags)
|
||||
{
|
||||
var name = mParams["name"];
|
||||
if (name.EndsWith(".bf", .OrdinalIgnoreCase))
|
||||
name.RemoveFromEnd(3);
|
||||
|
||||
var orientation = mParams["orientation"];
|
||||
var fixedLength = mParams["length"];
|
||||
var min = mParams["min"];
|
||||
var max = mParams["max"];
|
||||
var dfault = mParams["dfault"];
|
||||
|
||||
|
||||
outFileName.Append(scope $"TG{name}");
|
||||
|
||||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : {(fixedLength == "True") ? "" : "N" }{(orientation == "Horizontal") ? "H" : "V"}Slider
|
||||
{{
|
||||
public this() : base({(fixedLength == "True") ? "" : "64, "}"{name}")
|
||||
{{
|
||||
//Use the thing above to set the length of the bar
|
||||
Min = {min};
|
||||
Max = {max};
|
||||
Value = {dfault};
|
||||
ReactToValueChange = true; //This indicates wether OnValueChange gets actually called
|
||||
}}
|
||||
|
||||
public override void OnValueChange(float newVal)
|
||||
{{
|
||||
|
||||
}}
|
||||
}}
|
||||
""");
|
||||
}
|
||||
}
|
44
src/Generators/ToolbarGenerator.bf
Normal file
44
src/Generators/ToolbarGenerator.bf
Normal file
|
@ -0,0 +1,44 @@
|
|||
namespace TheaterGui.Generators;
|
||||
|
||||
using System;
|
||||
|
||||
class ToolbarGenerator : Compiler.Generator
|
||||
{
|
||||
public override String Name => "TheaterGui -> Generate Toolbar"
|
||||
|
||||
public override void InitUI()
|
||||
{
|
||||
AddEdit("name", "Toolbar Name", "");
|
||||
}
|
||||
|
||||
public override void Generate(String outFileName, String outText, ref Flags generateFlags)
|
||||
{
|
||||
var name = mParams["name"];
|
||||
if (name.EndsWith(".bf", .OrdinalIgnoreCase))
|
||||
name.RemoveFromEnd(3);
|
||||
|
||||
|
||||
outFileName.Append(scope $"TG{name}");
|
||||
|
||||
outText.Append(scope $"""
|
||||
namespace {Namespace};
|
||||
|
||||
using TheaterGui.Components;
|
||||
|
||||
class TG{name} : Toolbar
|
||||
{{
|
||||
public this() : base("{name}")
|
||||
{{
|
||||
|
||||
/*
|
||||
AddToolbarCategories(
|
||||
new .("File",
|
||||
new .("Open Recent", null)
|
||||
)
|
||||
);
|
||||
*/
|
||||
}}
|
||||
}}
|
||||
""");
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ class Textures
|
|||
LoadAsset(Theme.Texture_Checkbox, "checkbox");
|
||||
LoadAsset(Theme.Texture_Checkbox_Checked, "checkbox_checked");
|
||||
LoadAsset(Theme.Horizontal_Patch, "horizontal_patch");
|
||||
LoadAsset(Theme.Dropdown, "dropdown");
|
||||
|
||||
|
||||
|
||||
LoadAsset(Theme.Texture_TheaterIcon, "theater_icon");
|
||||
|
|
|
@ -35,6 +35,7 @@ public class Theme
|
|||
public static uint8[?] Texture_Checkbox = Compiler.ReadBinary("assets/checkbox.png");
|
||||
public static uint8[?] Texture_Checkbox_Checked = Compiler.ReadBinary("assets/checkbox_checked.png");
|
||||
public static uint8[?] Horizontal_Patch = Compiler.ReadBinary("assets/horizontal_patch.png");
|
||||
public static uint8[?] Dropdown = Compiler.ReadBinary("assets/dropdown.png");
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue