Improve visibility and update caching.

This commit is contained in:
James Grogan 2022-11-16 17:27:19 +00:00
parent 70891ce7b4
commit 722bda2801
8 changed files with 41 additions and 24 deletions

View file

@ -24,36 +24,34 @@ void MediaTool::initializeViews()
auto mainWindow = mDesktopManager->getWindowManager()->getMainWindow(); auto mainWindow = mDesktopManager->getWindowManager()->getMainWindow();
mainWindow->setSize(800, 600); mainWindow->setSize(800, 600);
/*
auto tabbedPanel = TabbedPanelWidget::Create(); auto tabbedPanel = TabbedPanelWidget::Create();
auto textEditor = TextEditorView::Create(); auto textEditor = TextEditorView::Create();
auto path = mMainApplication->GetCommandLineArgs()->getLaunchPath(); auto path = mMainApplication->getCommandLineArgs()->getLaunchPath();
path /= "out.txt"; path /= "out.txt";
textEditor->GetController()->SetSavePath(path); textEditor->GetController()->SetSavePath(path);
textEditor->GetController()->SetLoadPath(path); textEditor->GetController()->SetLoadPath(path);
textEditor->Initialize(); textEditor->Initialize();
tabbedPanel->AddPanel(std::move(textEditor), "Text Editor"); tabbedPanel->addPanel(std::move(textEditor), "Text Editor");
auto audioEditor = AudioEditorView::Create(); auto audioEditor = AudioEditorView::Create();
tabbedPanel->AddPanel(std::move(audioEditor), "Audio Editor"); tabbedPanel->addPanel(std::move(audioEditor), "Audio Editor");
auto imageEditor = ImageEditorView::Create(); auto imageEditor = ImageEditorView::Create();
tabbedPanel->AddPanel(std::move(imageEditor), "Image Editor"); tabbedPanel->addPanel(std::move(imageEditor), "Image Editor");
auto webClient = WebClientView::Create(); auto webClient = WebClientView::Create();
tabbedPanel->AddPanel(std::move(webClient), "Web Client"); tabbedPanel->addPanel(std::move(webClient), "Web Client");
auto topBar = TopBar::Create(); auto topBar = TopBar::Create();
auto statusBar = StatusBar::Create(); auto statusBar = StatusBar::Create();
auto horizontalSpace = HorizontalSpacer::Create(); auto horizontal_spacer = HorizontalSpacer::Create();
horizontalSpace->AddWidgetWithScale(std::move(topBar), 1); horizontal_spacer->addWidgetWithScale(std::move(topBar), 1);
horizontalSpace->AddWidgetWithScale(std::move(tabbedPanel), 20); horizontal_spacer->addWidgetWithScale(std::move(tabbedPanel), 20);
horizontalSpace->AddWidgetWithScale(std::move(statusBar), 1); horizontal_spacer->addWidgetWithScale(std::move(statusBar), 1);
*/
/*
auto button = Button::Create(); auto button = Button::Create();
button->setLabel("Click!"); button->setLabel("Click!");
button->setBounds(100, 200); button->setBounds(100, 200);
@ -66,6 +64,7 @@ void MediaTool::initializeViews()
auto horizontal_spacer = HorizontalSpacer::Create(); auto horizontal_spacer = HorizontalSpacer::Create();
horizontal_spacer->addWidgetWithScale(std::move(button), 1); horizontal_spacer->addWidgetWithScale(std::move(button), 1);
horizontal_spacer->addWidgetWithScale(std::move(background_widget), 1); horizontal_spacer->addWidgetWithScale(std::move(background_widget), 1);
*/
mainWindow->setWidget(std::move(horizontal_spacer)); mainWindow->setWidget(std::move(horizontal_spacer));
} }

View file

@ -27,25 +27,27 @@ std::unique_ptr<TabbedPanelWidget> TabbedPanelWidget::Create()
return std::make_unique<TabbedPanelWidget>(); return std::make_unique<TabbedPanelWidget>();
} }
StackWidget* TabbedPanelWidget::GetStack() const StackWidget* TabbedPanelWidget::getStack() const
{ {
return mStack; return mStack;
} }
void TabbedPanelWidget::AddPanel(WidgetUPtr panel, const std::string& label) void TabbedPanelWidget::addPanel(WidgetUPtr panel, const std::string& label)
{ {
auto button = Button::Create(); auto button = Button::Create();
button->setLabel(label); button->setLabel(label);
button->setBackgroundColor(Color(156, 156, 156)); button->setBackgroundColor(Color(156, 156, 156));
button->setMargin({1, 0, 0, 1}); button->setMargin({1, 0, 0, 1});
auto rawPanel = panel.get(); auto rawPanel = panel.get();
auto onClick = [this, rawPanel](Widget*){ auto onClick = [this, rawPanel](Widget*){
if(this && rawPanel) if(this && rawPanel)
{ {
this->GetStack()->ShowChild(rawPanel); this->getStack()->showChild(rawPanel);
} }
}; };
button->setOnClickFunction(onClick); button->setOnClickFunction(onClick);
mStack->addWidget(std::move(panel)); mStack->addWidget(std::move(panel));
mNavPanel->addWidget(std::move(button)); mNavPanel->addWidget(std::move(button));
} }

View file

@ -6,18 +6,19 @@
class TabbedPanelWidget : public Widget class TabbedPanelWidget : public Widget
{ {
Widget* mNavPanel;
StackWidget* mStack;
public: public:
TabbedPanelWidget(); TabbedPanelWidget();
static std::unique_ptr<TabbedPanelWidget> Create(); static std::unique_ptr<TabbedPanelWidget> Create();
void AddPanel(WidgetUPtr panel, const std::string& label); void addPanel(WidgetUPtr panel, const std::string& label);
StackWidget* GetStack() const; StackWidget* getStack() const;
private:
Widget* mNavPanel;
StackWidget* mStack;
}; };
using TabbedPanelWidgetUPtr = std::unique_ptr<TabbedPanelWidget>; using TabbedPanelWidgetUPtr = std::unique_ptr<TabbedPanelWidget>;

View file

@ -10,7 +10,7 @@ std::unique_ptr<StackWidget> StackWidget::Create()
return std::make_unique<StackWidget>(); return std::make_unique<StackWidget>();
} }
void StackWidget::ShowChild(Widget* target) void StackWidget::showChild(Widget* target)
{ {
for(auto& child : mChildren) for(auto& child : mChildren)
{ {

View file

@ -9,7 +9,7 @@ public:
static std::unique_ptr<StackWidget> Create(); static std::unique_ptr<StackWidget> Create();
void ShowChild(Widget* child); void showChild(Widget* child);
}; };
using StackWidgetUPtr = std::unique_ptr<StackWidget>; using StackWidgetUPtr = std::unique_ptr<StackWidget>;

View file

@ -132,6 +132,11 @@ void Widget::setVisible(bool visible)
mVisibilityDirty = true; mVisibilityDirty = true;
} }
mVisible = visible; mVisible = visible;
for (auto& child : mChildren)
{
child->setVisible(mVisible);
}
} }
bool Widget::isDirty() const bool Widget::isDirty() const
@ -198,6 +203,7 @@ void Widget::updateChildLocations()
{ {
child->setBounds(mSize.mWidth, mSize.mHeight); child->setBounds(mSize.mWidth, mSize.mHeight);
child->setLocation(mLocation); child->setLocation(mLocation);
child->setVisible(mVisible);
} }
} }
@ -259,7 +265,7 @@ bool Widget::onMouseEvent(const MouseEvent* event)
} }
if(!inChild) if(!inChild)
{ {
if(contains(event->GetClientLocation())) if(mVisible && contains(event->GetClientLocation()))
{ {
onMyMouseEvent(event); onMyMouseEvent(event);
return true; return true;

View file

@ -72,6 +72,11 @@ public:
return mName; return mName;
} }
bool getIsVisible() const
{
return mIsVisible;
}
protected: protected:
DiscretePoint mLocation; DiscretePoint mLocation;
std::unique_ptr<SceneItem> mSceneItem; std::unique_ptr<SceneItem> mSceneItem;

View file

@ -14,15 +14,19 @@ Scene::Scene()
void Scene::update(FontsManager* fontsManager) void Scene::update(FontsManager* fontsManager)
{ {
mSceneItems.clear();
updateNode(mRootNode.get(), fontsManager); updateNode(mRootNode.get(), fontsManager);
} }
void Scene::updateNode(AbstractVisualNode* node, FontsManager* fontsManager) void Scene::updateNode(AbstractVisualNode* node, FontsManager* fontsManager)
{ {
for (auto child : node->getChildren()) for (auto child : node->getChildren())
{
if (child->getIsVisible())
{ {
updateNode(child, fontsManager); updateNode(child, fontsManager);
} }
}
node->update(fontsManager); node->update(fontsManager);