📄 layout.cpp
字号:
case wxPercentOf:
{
int edgePos = GetEdge(otherEdge, win, otherWin);
if (edgePos != -1)
{
value = (int)(edgePos*(((float)percent)*0.01));
done = true;
return true;
}
else
return false;
}
case wxAsIs:
{
if (win)
{
int w;
wxGetAsIs(win, &w, &value);
done = true;
return true;
}
else return false;
}
case wxUnconstrained:
{
// We know the height if we know the top edge and the bottom edge, OR
// if we know the top edge and the centre, OR
// if we know the bottom edge and the centre
if (constraints->top.GetDone() && constraints->bottom.GetDone())
{
value = constraints->bottom.GetValue() - constraints->top.GetValue();
done = true;
return true;
}
else if (constraints->top.GetDone() && constraints->centreY.GetDone())
{
value = (int)(2*(constraints->centreY.GetValue() - constraints->top.GetValue()));
done = true;
return true;
}
else if (constraints->bottom.GetDone() && constraints->centreY.GetDone())
{
value = (int)(2*(constraints->bottom.GetValue() - constraints->centreY.GetValue()));
done = true;
return true;
}
else
return false;
}
default:
break;
}
break;
}
default:
break;
}
return false;
}
// Get the value of this edge or dimension, or if this is not determinable, -1.
int wxIndividualLayoutConstraint::GetEdge(wxEdge which,
wxWindowBase *thisWin,
wxWindowBase *other) const
{
// If the edge or dimension belongs to the parent, then we know the
// dimension is obtainable immediately. E.g. a wxExpandSizer may contain a
// button (but the button's true parent is a panel, not the sizer)
if (other->GetChildren().Find((wxWindow*)thisWin))
{
switch (which)
{
case wxLeft:
{
return 0;
}
case wxTop:
{
return 0;
}
case wxRight:
{
int w, h;
other->GetClientSizeConstraint(&w, &h);
return w;
}
case wxBottom:
{
int w, h;
other->GetClientSizeConstraint(&w, &h);
return h;
}
case wxWidth:
{
int w, h;
other->GetClientSizeConstraint(&w, &h);
return w;
}
case wxHeight:
{
int w, h;
other->GetClientSizeConstraint(&w, &h);
return h;
}
case wxCentreX:
case wxCentreY:
{
int w, h;
other->GetClientSizeConstraint(&w, &h);
if (which == wxCentreX)
return (int)(w/2);
else
return (int)(h/2);
}
default:
return -1;
}
}
switch (which)
{
case wxLeft:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->left.GetDone())
return constr->left.GetValue();
else
return -1;
}
else
{
int x, y;
other->GetPosition(&x, &y);
return x;
}
}
case wxTop:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->top.GetDone())
return constr->top.GetValue();
else
return -1;
}
else
{
int x, y;
other->GetPosition(&x, &y);
return y;
}
}
case wxRight:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->right.GetDone())
return constr->right.GetValue();
else
return -1;
}
else
{
int x, y, w, h;
other->GetPosition(&x, &y);
other->GetSize(&w, &h);
return (int)(x + w);
}
}
case wxBottom:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->bottom.GetDone())
return constr->bottom.GetValue();
else
return -1;
}
else
{
int x, y, w, h;
other->GetPosition(&x, &y);
other->GetSize(&w, &h);
return (int)(y + h);
}
}
case wxWidth:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->width.GetDone())
return constr->width.GetValue();
else
return -1;
}
else
{
int w, h;
other->GetSize(&w, &h);
return w;
}
}
case wxHeight:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->height.GetDone())
return constr->height.GetValue();
else
return -1;
}
else
{
int w, h;
other->GetSize(&w, &h);
return h;
}
}
case wxCentreX:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->centreX.GetDone())
return constr->centreX.GetValue();
else
return -1;
}
else
{
int x, y, w, h;
other->GetPosition(&x, &y);
other->GetSize(&w, &h);
return (int)(x + (w/2));
}
}
case wxCentreY:
{
wxLayoutConstraints *constr = other->GetConstraints();
// If no constraints, it means the window is not dependent
// on anything, and therefore we know its value immediately
if (constr)
{
if (constr->centreY.GetDone())
return constr->centreY.GetValue();
else
return -1;
}
else
{
int x, y, w, h;
other->GetPosition(&x, &y);
other->GetSize(&w, &h);
return (int)(y + (h/2));
}
}
default:
break;
}
return -1;
}
wxLayoutConstraints::wxLayoutConstraints()
{
left.SetEdge(wxLeft);
top.SetEdge(wxTop);
right.SetEdge(wxRight);
bottom.SetEdge(wxBottom);
centreX.SetEdge(wxCentreX);
centreY.SetEdge(wxCentreY);
width.SetEdge(wxWidth);
height.SetEdge(wxHeight);
}
bool wxLayoutConstraints::SatisfyConstraints(wxWindowBase *win, int *nChanges)
{
int noChanges = 0;
bool done = width.GetDone();
bool newDone = (done ? true : width.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
done = height.GetDone();
newDone = (done ? true : height.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
done = left.GetDone();
newDone = (done ? true : left.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
done = top.GetDone();
newDone = (done ? true : top.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
done = right.GetDone();
newDone = (done ? true : right.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
done = bottom.GetDone();
newDone = (done ? true : bottom.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
done = centreX.GetDone();
newDone = (done ? true : centreX.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
done = centreY.GetDone();
newDone = (done ? true : centreY.SatisfyConstraint(this, win));
if (newDone != done)
noChanges ++;
*nChanges = noChanges;
return AreSatisfied();
}
#endif // wxUSE_CONSTRAINTS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -