Changes to WIP ScrollingRect
This commit is contained in:
@@ -18,11 +18,13 @@ namespace JUI {
|
||||
/// A Rectangle Widget which has a larger renderable area than the visible area.
|
||||
class JUI::ScrollingRect : public Rect {
|
||||
protected:
|
||||
bool vertical_scrollbar_enabled = true;
|
||||
bool horizontal_scrollbar_enabled = true;
|
||||
bool scrollbar_visible = true;
|
||||
float scrollbar_width = 12;
|
||||
Color4 scrollbar_color = Colors::Whites::Azure;
|
||||
float scroll = 0;
|
||||
Vector2i canvas_size {200, 200};
|
||||
Vector2i canvas_size {64, 128};
|
||||
JGL::RenderTarget* canvas = nullptr;
|
||||
protected:
|
||||
/* This isn't public because nothing should ever
|
||||
@@ -41,8 +43,16 @@ public:
|
||||
void CanvasSize(const Vector2i& new_size);
|
||||
void InnerDraw() override;
|
||||
void Draw() override;
|
||||
void Update(float delta) override
|
||||
{
|
||||
scroll += delta;
|
||||
Rect::Update(delta);
|
||||
|
||||
canvas->Resize(Vector2i(GetAbsoluteSize().x, GetAbsoluteSize().y));
|
||||
}
|
||||
public:
|
||||
~ScrollingRect() override { delete canvas; }
|
||||
// TODO: ClearColor is no longer required to specify with new mcolor.
|
||||
ScrollingRect() : canvas(new RenderTarget(canvas_size, {0, 0, 0, 0})) {};
|
||||
explicit ScrollingRect(Widget* parent) : Rect(parent), canvas(new RenderTarget(canvas_size, {0, 0, 0, 0})) {};
|
||||
};
|
@@ -10,10 +10,15 @@ void ScrollingRect::RecomputeRenderTarget() {
|
||||
}
|
||||
|
||||
void ScrollingRect::Draw() {
|
||||
|
||||
RecomputeRenderTarget();
|
||||
Rect::InnerDraw();
|
||||
J2D::Begin();
|
||||
J2D::DrawRenderTarget(canvas, CanvasPosition());
|
||||
|
||||
//J2D::DrawRenderTarget(canvas, CanvasPosition());
|
||||
// TODO sub_texture_size would be the size of the visible area.
|
||||
J2D::DrawPartialRenderTarget(canvas, GetAbsolutePosition(), {0, scroll}, {});
|
||||
J2D::DrawPartialRenderTarget(canvas, GetAbsolutePosition(), {0, scroll}, {64, 64});
|
||||
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
@@ -22,4 +27,13 @@ Vector2 ScrollingRect::CanvasPosition() const {
|
||||
}
|
||||
|
||||
// Wouldn't inner draw actually render everything onto the RenderTarget?
|
||||
void ScrollingRect::InnerDraw() {}
|
||||
void ScrollingRect::InnerDraw() {
|
||||
J2D::Begin(canvas, true);
|
||||
DrawChildWidgets();
|
||||
J2D::End();
|
||||
//J2D::FillRect(bg_color, {0, 0}, {64, 64});
|
||||
//RectBase::Draw(canvas,bg_color, border_color, {0, 0}, {64, 64});
|
||||
//RectBase::Draw(canvas,bg_color, border_color, {0, 70}, {64, 64});
|
||||
//Widget::Draw();
|
||||
//J2D::End();
|
||||
}
|
||||
|
Reference in New Issue
Block a user