added right click action

This commit is contained in:
Booklordofthedings 2024-06-20 21:10:46 +02:00
parent 5a37276fa5
commit d3d9f51012
4 changed files with 23 additions and 4 deletions

View file

@ -141,7 +141,12 @@ class App
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 () => {}) )));
Toolbar.ToolbarCategory popupCat = new .("Items");
CurrentScreen.OnRightClick((.)Mouse.x, (.)Mouse.y, popupCat);
if(popupCat.Items.Count > 0)
Popups.Add(new RightClickPopup((.)Mouse.x, (.)Mouse.y, popupCat));
else
delete popupCat;
}
else
HandleHover();

View file

@ -97,6 +97,7 @@ abstract class Component
public abstract void Render(int32 soy);
public virtual bool OnClick(int32 x, int32 y) => false;
public virtual void OnRightClick(int32 x, int32 y, Toolbar.ToolbarCategory items) {}
public virtual bool OnDown(int32 x, int32 y) => false;
public abstract Component OnHover(int32 x, int32 y);

View file

@ -165,4 +165,13 @@ class Container : Component
}
return null;
}
public override void OnRightClick(int32 x, int32 y, Toolbar.ToolbarCategory items)
{
for(var e in Children)
{
if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y))
e.OnRightClick(x, y, items);
}
}
}

View file

@ -21,7 +21,7 @@ class RightClickPopup : Popup
if(maxWidth <= i.NameMeasurement.x)
maxWidth = (.)i.NameMeasurement.x;
Width = maxWidth + 10 + 32;
Width = maxWidth + 10 + 20;
Height = (.)(5 +((_Category.NameMeasurement.y + 5) * _Category.Items.Count));
}
}
@ -30,9 +30,13 @@ class RightClickPopup : Popup
{
this.[Friend]X = x;
this.[Friend]Y = y-1;
Sprite = App.Textures.GetAsset("n_button");
Sprite = App.Textures.GetAsset("horizontal_patch");
PatchInfo =.(Sprite.SourceRect, 2,2,2,2,(.)NPatchLayout.NPATCH_NINE_PATCH);
Category = category;
if(x+Width > App.Width)
this.[Friend]X -= Width;
if(y+Height > App.Height)
this.[Friend]Y -= Height;
}
public override void Render(int32 soy)
@ -47,7 +51,7 @@ class RightClickPopup : Popup
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);
Raylib.DrawTextEx(Theme.Font, scope String(i.Name), .(X + 5, Y + y + soy), Theme.FontSize, 0, Theme.Text);
if(SelectedItem == i)
{
Raylib.DrawTextureNPatch(