diff --git a/assets/dropdown.png b/assets/dropdown.png new file mode 100644 index 0000000..fcf9954 Binary files /dev/null and b/assets/dropdown.png differ diff --git a/assets/dropdown.png~ b/assets/dropdown.png~ new file mode 100644 index 0000000..68daa77 Binary files /dev/null and b/assets/dropdown.png~ differ diff --git a/src/App.bf b/src/App.bf index 13316fa..1303c94 100644 --- a/src/App.bf +++ b/src/App.bf @@ -9,7 +9,7 @@ class App { //All loaded textures - private static List Popups = new .() ~ DeleteContainerAndItems!(_); + private static List 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; } -} \ No newline at end of file +} + + diff --git a/src/Components/Component.bf b/src/Components/Component.bf index fdf7d31..b375ece 100644 --- a/src/Components/Component.bf +++ b/src/Components/Component.bf @@ -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() { } diff --git a/src/Components/Container.bf b/src/Components/Container.bf index dde7cef..c097a39 100644 --- a/src/Components/Container.bf +++ b/src/Components/Container.bf @@ -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) diff --git a/src/Components/Dropdown.bf b/src/Components/Dropdown.bf new file mode 100644 index 0000000..3c8a441 --- /dev/null +++ b/src/Components/Dropdown.bf @@ -0,0 +1,57 @@ +namespace TheaterGui.Components; + +using System; +using System.Collections; +using RaylibBeef; + +abstract class Dropdown : Component +{ + public List 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(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; + } +} \ No newline at end of file diff --git a/src/Components/DropdownPopup.bf b/src/Components/DropdownPopup.bf new file mode 100644 index 0000000..c515a41 --- /dev/null +++ b/src/Components/DropdownPopup.bf @@ -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 Options = new .() ~ DeleteContainerAndItems!(_); + + public this(int32 x, int32 y, int32 w, params Span 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 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() + { + } +} \ No newline at end of file diff --git a/src/Components/HSlider.bf b/src/Components/HSlider.bf new file mode 100644 index 0000000..900ffa2 --- /dev/null +++ b/src/Components/HSlider.bf @@ -0,0 +1,11 @@ +namespace TheaterGui.Components; + +using System; + +abstract class HSlider : NHSlider +{ + public this(StringView pLabel) : base(32 * 6, pLabel, "HSlider") + { + + } +} \ No newline at end of file diff --git a/src/Components/NHSlider.bf b/src/Components/NHSlider.bf new file mode 100644 index 0000000..5836af7 --- /dev/null +++ b/src/Components/NHSlider.bf @@ -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; + } +} \ No newline at end of file diff --git a/src/Components/NVSlider.bf b/src/Components/NVSlider.bf new file mode 100644 index 0000000..a1297f0 --- /dev/null +++ b/src/Components/NVSlider.bf @@ -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; + } +} \ No newline at end of file diff --git a/src/Components/PopupComponent.bf b/src/Components/Popup.bf similarity index 83% rename from src/Components/PopupComponent.bf rename to src/Components/Popup.bf index ea55bff..b574802 100644 --- a/src/Components/PopupComponent.bf +++ b/src/Components/Popup.bf @@ -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) { diff --git a/src/Components/RightClickPopup.bf b/src/Components/RightClickPopup.bf new file mode 100644 index 0000000..63621ed --- /dev/null +++ b/src/Components/RightClickPopup.bf @@ -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() + { + } +} \ No newline at end of file diff --git a/src/Components/Toolbar.bf b/src/Components/Toolbar.bf index 3648bfd..1c9d6fd 100644 --- a/src/Components/Toolbar.bf +++ b/src/Components/Toolbar.bf @@ -4,24 +4,18 @@ using System; using System.Collections; using RaylibBeef; -class Toolbar : Component +abstract class Toolbar : Component { public NPatchInfo PatchInfo; public List 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 pCategories) + { + for(var i in pCategories) + Categories.Add(i); + } + + ///Toolbar data is stored in here public class ToolbarCategory { private String _Name = null ~ delete _; diff --git a/src/Components/ToolbarPopup.bf b/src/Components/ToolbarPopup.bf index 9c5410e..dda1a96 100644 --- a/src/Components/ToolbarPopup.bf +++ b/src/Components/ToolbarPopup.bf @@ -3,7 +3,7 @@ namespace TheaterGui.Components; using System; using RaylibBeef; -class ToolbarPopup : PopupComponent +class ToolbarPopup : Popup { public NPatchInfo PatchInfo; public Toolbar Owner = null; diff --git a/src/Components/VSlider.bf b/src/Components/VSlider.bf new file mode 100644 index 0000000..467f1b5 --- /dev/null +++ b/src/Components/VSlider.bf @@ -0,0 +1,11 @@ +namespace TheaterGui.Components; + +using System; + +abstract class VSlider : NVSlider +{ + public this(StringView pLabel) : base(32 * 6, pLabel, "VSlider") + { + + } +} \ No newline at end of file diff --git a/src/Generators/ButtonGenerator.bf b/src/Generators/ButtonGenerator.bf index e810ea1..016aff4 100644 --- a/src/Generators/ButtonGenerator.bf +++ b/src/Generators/ButtonGenerator.bf @@ -27,7 +27,7 @@ class ButtonGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : Button {{ diff --git a/src/Generators/CheckboxGenerator.bf b/src/Generators/CheckboxGenerator.bf index bb33d42..4d44a86 100644 --- a/src/Generators/CheckboxGenerator.bf +++ b/src/Generators/CheckboxGenerator.bf @@ -27,7 +27,7 @@ class CheckboxGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : Checkbox {{ diff --git a/src/Generators/ContainerGenerator.bf b/src/Generators/ContainerGenerator.bf index 00b24b2..6ba2829 100644 --- a/src/Generators/ContainerGenerator.bf +++ b/src/Generators/ContainerGenerator.bf @@ -22,7 +22,7 @@ class ContainerGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : Screen {{ diff --git a/src/Generators/DropdownGenerator.bf b/src/Generators/DropdownGenerator.bf new file mode 100644 index 0000000..605b9a9 --- /dev/null +++ b/src/Generators/DropdownGenerator.bf @@ -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) + {{ + + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Generators/IconButtonGenerator.bf b/src/Generators/IconButtonGenerator.bf index 1d05d68..e7aae63 100644 --- a/src/Generators/IconButtonGenerator.bf +++ b/src/Generators/IconButtonGenerator.bf @@ -27,7 +27,7 @@ class IconButtonGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : IconButton {{ diff --git a/src/Generators/LargeButtonGenerator.bf b/src/Generators/LargeButtonGenerator.bf index a520eed..6804efc 100644 --- a/src/Generators/LargeButtonGenerator.bf +++ b/src/Generators/LargeButtonGenerator.bf @@ -27,7 +27,7 @@ class LargeButtonGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : LargeButton {{ diff --git a/src/Generators/NButtonGenerator.bf b/src/Generators/NButtonGenerator.bf index 10043b5..4620e39 100644 --- a/src/Generators/NButtonGenerator.bf +++ b/src/Generators/NButtonGenerator.bf @@ -27,7 +27,7 @@ class NButtonGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : NButton {{ diff --git a/src/Generators/RadioButtonGenerator.bf b/src/Generators/RadioButtonGenerator.bf index cdbee98..1b3797a 100644 --- a/src/Generators/RadioButtonGenerator.bf +++ b/src/Generators/RadioButtonGenerator.bf @@ -27,7 +27,7 @@ class RadioButtonGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : RadioButton {{ diff --git a/src/Generators/ScreenGenerator.bf b/src/Generators/ScreenGenerator.bf index f628f61..da919fa 100644 --- a/src/Generators/ScreenGenerator.bf +++ b/src/Generators/ScreenGenerator.bf @@ -22,7 +22,7 @@ class ScreenGenerator : Compiler.Generator outText.Append(scope $""" namespace {Namespace}; - using TheaterGui.Controls; + using TheaterGui.Components; class TG{name} : Screen {{ diff --git a/src/Generators/SliderGenerator.bf b/src/Generators/SliderGenerator.bf new file mode 100644 index 0000000..0e2d55c --- /dev/null +++ b/src/Generators/SliderGenerator.bf @@ -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) + {{ + + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Generators/ToolbarGenerator.bf b/src/Generators/ToolbarGenerator.bf new file mode 100644 index 0000000..1d7421a --- /dev/null +++ b/src/Generators/ToolbarGenerator.bf @@ -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) + ) + ); + */ + }} + }} + """); + } +} \ No newline at end of file diff --git a/src/Textures.bf b/src/Textures.bf index 080cb7c..ae81be8 100644 --- a/src/Textures.bf +++ b/src/Textures.bf @@ -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"); diff --git a/src/Theme.bf b/src/Theme.bf index c1d131c..efe7e37 100644 --- a/src/Theme.bf +++ b/src/Theme.bf @@ -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"); }