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

View file

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

View file

@ -6,18 +6,19 @@
class TabbedPanelWidget : public Widget
{
Widget* mNavPanel;
StackWidget* mStack;
public:
TabbedPanelWidget();
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>;

View file

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

View file

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

View file

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

View file

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

View file

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