actual scrolling

This commit is contained in:
Booklordofthedings 2024-06-20 23:37:31 +02:00
parent bcd137f54b
commit cfefe7db2b
4 changed files with 32 additions and 7 deletions

View file

@ -116,8 +116,8 @@ class App
}
//This could probably be solved better
if(CurrentScreen.Height - Height > 0)
var wh = Raylib.GetMouseWheelMove();
if(!CurrentScreen.HandleScrollEvent(wh*wh*wh, (.)Mouse.x, (.)Mouse.y) && CurrentScreen.Height - Height > 0)
{
var w = Raylib.GetMouseWheelMove();
Wheel += w * w * w;

View file

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

View file

@ -166,6 +166,16 @@ class Container : Component
return null;
}
public override bool HandleScrollEvent(float scroll, 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.HandleScrollEvent(scroll, x, y);
}
return false;
}
public override void OnRightClick(int32 x, int32 y, Toolbar.ToolbarCategory items)
{
for(var e in Children)

View file

@ -137,7 +137,7 @@ class ScrollableContainer : Container
{
Raylib.BeginScissorMode(X, Y + soy, Width, ContainerHeight);
for(var i in Children)
i.Render(soy);
i.Render((.)(soy + Scroll));
Raylib.EndScissorMode();
}
@ -145,8 +145,8 @@ class ScrollableContainer : Container
{
for(var e in Children)
{
if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y))
return e.OnClick(x, y);
if(RaylibBeef.Rectangle(e.X, e.Y - Scroll, e.Width, e.Height).Overlaps(x, y))
return e.OnClick(x, (.)(y - Scroll));
}
return false;
}
@ -165,8 +165,8 @@ class ScrollableContainer : Container
{
for(var e in Children)
{
if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y))
return e.OnHover(x, y);
if(RaylibBeef.Rectangle(e.X, e.Y - Scroll, e.Width, e.Height).Overlaps(x, y))
return e.OnHover(x, (.)(y - Scroll));
}
return null;
}
@ -179,4 +179,18 @@ class ScrollableContainer : Container
e.OnRightClick(x, y, items);
}
}
public override bool HandleScrollEvent(float scroll, int32 x, int32 y)
{
for(var e in Children)
{
if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y))
if(e.HandleScrollEvent(scroll, x, y))
return true;
}
//Do our own rendering
Scroll += scroll;
Scroll = Math.Clamp(Scroll,-(Height-ContainerHeight),0);
return true;
}
}