This commit is contained in:
IlyaShurupov 2024-10-08 14:23:49 +03:00 committed by Ilya Shurupov
parent 279cf58dff
commit 4b6e7da994
18 changed files with 592 additions and 203 deletions

View file

@ -2,6 +2,20 @@
using namespace tp;
WidgetManagerInterface* Widget::getRoot() {
Widget* iter = mParent;
while (iter && iter->mParent) {
iter = iter->mParent;
}
return dynamic_cast<WidgetManagerInterface*>(iter);
}
void Widget::triggerWidgetUpdate() {
if (auto root = getRoot()) {
root->updateWidget(this);
}
}
Widget::Widget() {
mArea.setTargetRect({ 10, 10, 100, 40, });
mArea.endAnimation();
@ -9,10 +23,10 @@ Widget::Widget() {
void Widget::setArea(const RectF& area) {
mArea.setTargetRect(area);
}
void Widget::draw(Canvas& canvas) {
canvas.rect(mArea.getCurrentRect(), RGBA(1.f), 10);
if (!mArea.shouldEndTransition()) {
triggerWidgetUpdate();
}
}
RectF Widget::getArea() const {
@ -23,28 +37,47 @@ RectF Widget::getRelativeArea() const {
return { {}, mArea.getCurrentRect().size };
}
void Widget::setActive(bool active) {
mIsActive = active;
}
void Widget::addChild(Widget* widget) {
if (widget->mParent) {
widget->mParent->removeChild(widget);
}
mChildWidgets.pushBack(widget);
widget->mParent = this;
}
void Widget::removeChild(Widget* widget) {
auto node = mChildWidgets.find(widget);
node->data->mParent = nullptr;
mChildWidgets.removeNode(node);
}
bool Widget::needUpdate() const {
return !mArea.checkAnimationShouldEnd();
}
void Widget::finishAnimations() {
void Widget::endAnimations() {
mArea.endAnimation();
}
bool Widget::processesEvents() const {
return true;
}
void Widget::updateAnimations() {
mArea.updateCurrentRect();
}
bool Widget::needsNextFrame() const {
return !mArea.shouldEndTransition() || mInFocus;
}
void Widget::adjustRect() {
if (mChildren.empty()) return;
auto area = (*mChildren.begin())->getArea();
for (auto widget : mChildren) {
area.expand(widget->getArea());
}
}
void Widget::adjustChildrenRect() {
auto area = RectF({}, getArea().size);
for (auto widget : mChildren) {
widget->setArea(area);
}
}
void Widget::mouseEnter() {
mInFocus = true;
triggerWidgetUpdate();
}
void Widget::mouseLeave() {
mInFocus = false;
}
bool Widget::propagateEventsToChildren() const {
return true;
}