From d3b4e1071b1595f184266a6d95775c000e45b499 Mon Sep 17 00:00:00 2001 From: Lfu001 <82690385+Lfu001@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:58:19 +0900 Subject: [PATCH] feat: add sample scene (#35) --- tears/MainScene.cpp | 240 +++++++++++++++++++++++++++++++++++--------- tears/MainScene.hpp | 10 ++ 2 files changed, 202 insertions(+), 48 deletions(-) diff --git a/tears/MainScene.cpp b/tears/MainScene.cpp index 01cb251..0e1ac8e 100644 --- a/tears/MainScene.cpp +++ b/tears/MainScene.cpp @@ -6,6 +6,8 @@ // Copyright © 2024 tears team. All rights reserved. // +#include +#include "math/Interval.hpp" #include "view/container/HStack.hpp" #include "view/container/VStack.hpp" #include "view/container/ZStack.hpp" @@ -14,9 +16,7 @@ #include "view/separator/Spacer.hpp" #include "view/shape/Capsule.hpp" #include "view/shape/Circle.hpp" -#include "view/shape/Ellipse.hpp" #include "view/shape/Rectangle.hpp" -#include "view/shape/RoundedRectangle.hpp" #include "MainScene.hpp" namespace tears { @@ -25,60 +25,204 @@ using namespace std; // constructor MainScene::MainScene(TearsEngine* aEngine, Size screenSize): Scene(aEngine, screenSize) { - auto roundedRect = make_unique(24.f); - roundedRect->setBackgroundColor(Color(100, 200, 248, 200)); - auto circle = make_unique(); - circle->setBackgroundColor(Color::YELLOW, EdgeLeading) - .setBackgroundColor(Color::GREEN, EdgeTrailing) - .setPadding(EdgeAll, 15.f) - .setOffsetX(50.f); - auto zstack = make_unique(std::move(roundedRect), std::move(circle)); - zstack->setWidth(300.f).setPadding(EdgeBottom, 20.f); - - auto capsule = make_unique(); - capsule->setBackgroundColor(Color(233, 255, 138, 200)).setHeight(40.f); - auto hstack = make_unique(std::move(zstack), std::move(capsule)); - hstack->setHeight(200.f); - - auto ellipse = make_unique(); - ellipse->setBackgroundColor(Color(255, 148, 148, 200)) - .setSize(300.f, 100.f) - .setPadding(EdgeBottom, 10.f); - auto rectangle = make_unique(); - rectangle->setBackgroundColor(Color(255, 174, 0, 200)).setSize(200.f, 100.f); + unique_ptr heading = createHeading(); + heading->setHeightRatio(0.3f); + unique_ptr content = createContent(); + + unique_ptr footer = createFooter(); + footer->setHeight(70.f); + + auto vstack = make_unique(std::move(heading), std::move(content), std::move(footer)); + + addChild(std::move(vstack)); +} + +// destructor +MainScene::~MainScene() {} + +unique_ptr MainScene::createHeading() const { + // title + auto title = make_unique(); + title->setBackgroundColor(Color(255, 255, 255)) + .setHeight(24.f) + .setWidthRatio(0.7f) + .setPadding(EdgeBottom, 20.f) + .setAlignment(AlignmentLeading); + + // text + Color textColor = Color(240, 240, 240); + auto textArea = make_unique( + std::move(title), + createText(Interval(0.7f, 1.f), textColor), + createText(Interval(0.7f, 1.f), textColor), + createText(Interval(0.3f, 0.7f), textColor), + make_unique()); + textArea->setWidthRatio(0.7f); + + // user icon + auto userIcon = make_unique(); + userIcon->setBackgroundColor(Color(255, 255, 255)) + .setSize(30.f, 30.f) + .setAlignment(AlignmentTop); + + // button + auto buttonBg = make_unique(); + buttonBg->setBackgroundColor(Color(255, 255, 255, 150)).setBlurSigma(20.f); auto button = make_unique