Don't call layout() for each mouse move to preview Workspace drop area

This commit is contained in:
David Capello 2015-03-27 18:45:36 -03:00
parent 47948ee888
commit 43f992bf8d
2 changed files with 68 additions and 34 deletions

View File

@ -30,7 +30,7 @@ Workspace::Workspace()
: Widget(kGenericWidget) : Widget(kGenericWidget)
, m_tabsBar(nullptr) , m_tabsBar(nullptr)
, m_activeView(nullptr) , m_activeView(nullptr)
, m_dropPreview(false) , m_dropArea(0)
{ {
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
setBgColor(theme->colors.workspace()); setBgColor(theme->colors.workspace());
@ -105,54 +105,86 @@ void Workspace::onResize(ui::ResizeEvent& ev)
{ {
setBoundsQuietly(ev.getBounds()); setBoundsQuietly(ev.getBounds());
gfx::Rect cpos = getChildrenBounds(); gfx::Rect rc = getChildrenBounds();
// Preview to drop tabs in workspace // Preview to drop tabs in workspace
if (m_dropPreview && cpos.contains(m_dropPos)) { int threshold = getDropThreshold();
int left = ABS(cpos.x - m_dropPos.x); switch (m_dropArea) {
int top = ABS(cpos.y - m_dropPos.y); case JI_LEFT:
int right = ABS(cpos.x + cpos.w - m_dropPos.x); rc.x += threshold;
int bottom = ABS(cpos.y + cpos.h - m_dropPos.y); rc.w -= threshold;
int threshold = 32*guiscale(); break;
if (threshold > cpos.w/2) threshold = cpos.w/2; case JI_TOP:
if (threshold > cpos.h/2) threshold = cpos.h/2; rc.y += threshold;
rc.h -= threshold;
if (left < threshold && left < right && left < top && left < bottom) { break;
cpos.x += threshold; case JI_RIGHT:
cpos.w -= threshold; rc.w -= threshold;
} break;
else if (top < threshold && top < left && top < right && top < bottom) { case JI_BOTTOM:
cpos.y += threshold; rc.h -= threshold;
cpos.h -= threshold; break;
}
else if (right < threshold && right < left && right < top && right < bottom) {
cpos.w -= threshold;
}
else if (bottom < threshold && bottom < left && bottom < top && bottom < right) {
cpos.h -= threshold;
}
} }
for (Widget* child : getChildren()) for (Widget* child : getChildren())
child->setBounds(cpos); child->setBounds(rc);
} }
void Workspace::setDropViewPreview(const gfx::Point& pos) void Workspace::setDropViewPreview(const gfx::Point& pos)
{ {
m_dropPos = pos; int newDropArea = calculateDropArea(pos);
m_dropPreview = true; if (newDropArea != m_dropArea) {
m_dropArea = newDropArea;
layout(); layout();
}
} }
void Workspace::removeDropViewPreview(const gfx::Point& pos) void Workspace::removeDropViewPreview(const gfx::Point& pos)
{ {
m_dropPreview = false; if (m_dropArea) {
m_dropArea = 0;
layout(); layout();
}
} }
void Workspace::dropViewAt(const gfx::Point& pos, WorkspaceView* view) void Workspace::dropViewAt(const gfx::Point& pos, WorkspaceView* view)
{ {
} }
int Workspace::calculateDropArea(const gfx::Point& pos) const
{
gfx::Rect rc = getChildrenBounds();
if (rc.contains(pos)) {
int left = ABS(rc.x - pos.x);
int top = ABS(rc.y - pos.y);
int right = ABS(rc.x + rc.w - pos.x);
int bottom = ABS(rc.y + rc.h - pos.y);
int threshold = getDropThreshold();
if (left < threshold && left < right && left < top && left < bottom) {
return JI_LEFT;
}
else if (top < threshold && top < left && top < right && top < bottom) {
return JI_TOP;
}
else if (right < threshold && right < left && right < top && right < bottom) {
return JI_RIGHT;
}
else if (bottom < threshold && bottom < left && bottom < top && bottom < right) {
return JI_BOTTOM;
}
}
return 0;
}
int Workspace::getDropThreshold() const
{
gfx::Rect cpos = getChildrenBounds();
int threshold = 32*guiscale();
if (threshold > cpos.w/2) threshold = cpos.w/2;
if (threshold > cpos.h/2) threshold = cpos.h/2;
return threshold;
}
} // namespace app } // namespace app

View File

@ -52,11 +52,13 @@ namespace app {
void onResize(ui::ResizeEvent& ev) override; void onResize(ui::ResizeEvent& ev) override;
private: private:
int calculateDropArea(const gfx::Point& pos) const;
int getDropThreshold() const;
Tabs* m_tabsBar; Tabs* m_tabsBar;
WorkspaceViews m_views; WorkspaceViews m_views;
WorkspaceView* m_activeView; WorkspaceView* m_activeView;
bool m_dropPreview; int m_dropArea;
gfx::Point m_dropPos;
}; };
} // namespace app } // namespace app