actual scrolling
This commit is contained in:
parent
bcd137f54b
commit
cfefe7db2b
4 changed files with 32 additions and 7 deletions
|
@ -116,8 +116,8 @@ class App
|
||||||
}
|
}
|
||||||
|
|
||||||
//This could probably be solved better
|
//This could probably be solved better
|
||||||
|
var wh = Raylib.GetMouseWheelMove();
|
||||||
if(CurrentScreen.Height - Height > 0)
|
if(!CurrentScreen.HandleScrollEvent(wh*wh*wh, (.)Mouse.x, (.)Mouse.y) && CurrentScreen.Height - Height > 0)
|
||||||
{
|
{
|
||||||
var w = Raylib.GetMouseWheelMove();
|
var w = Raylib.GetMouseWheelMove();
|
||||||
Wheel += w * w * w;
|
Wheel += w * w * w;
|
||||||
|
|
|
@ -98,6 +98,7 @@ abstract class Component
|
||||||
|
|
||||||
public virtual bool OnClick(int32 x, int32 y) => false;
|
public virtual bool OnClick(int32 x, int32 y) => false;
|
||||||
public virtual void OnRightClick(int32 x, int32 y, Toolbar.ToolbarCategory items) {}
|
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 virtual bool OnDown(int32 x, int32 y) => false;
|
||||||
public abstract Component OnHover(int32 x, int32 y);
|
public abstract Component OnHover(int32 x, int32 y);
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,16 @@ class Container : Component
|
||||||
return null;
|
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)
|
public override void OnRightClick(int32 x, int32 y, Toolbar.ToolbarCategory items)
|
||||||
{
|
{
|
||||||
for(var e in Children)
|
for(var e in Children)
|
||||||
|
|
|
@ -137,7 +137,7 @@ class ScrollableContainer : Container
|
||||||
{
|
{
|
||||||
Raylib.BeginScissorMode(X, Y + soy, Width, ContainerHeight);
|
Raylib.BeginScissorMode(X, Y + soy, Width, ContainerHeight);
|
||||||
for(var i in Children)
|
for(var i in Children)
|
||||||
i.Render(soy);
|
i.Render((.)(soy + Scroll));
|
||||||
Raylib.EndScissorMode();
|
Raylib.EndScissorMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +145,8 @@ class ScrollableContainer : Container
|
||||||
{
|
{
|
||||||
for(var e in Children)
|
for(var e in Children)
|
||||||
{
|
{
|
||||||
if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y))
|
if(RaylibBeef.Rectangle(e.X, e.Y - Scroll, e.Width, e.Height).Overlaps(x, y))
|
||||||
return e.OnClick(x, y);
|
return e.OnClick(x, (.)(y - Scroll));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -165,8 +165,8 @@ class ScrollableContainer : Container
|
||||||
{
|
{
|
||||||
for(var e in Children)
|
for(var e in Children)
|
||||||
{
|
{
|
||||||
if(RaylibBeef.Rectangle(e.X, e.Y, e.Width, e.Height).Overlaps(x, y))
|
if(RaylibBeef.Rectangle(e.X, e.Y - Scroll, e.Width, e.Height).Overlaps(x, y))
|
||||||
return e.OnHover(x, y);
|
return e.OnHover(x, (.)(y - Scroll));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -179,4 +179,18 @@ class ScrollableContainer : Container
|
||||||
e.OnRightClick(x, y, items);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue