我正在實現一個生活在屏幕上的視圖。根據以下配置參數,只要屏幕尺寸發生變化,視圖就會定位並調整大小。使用枚舉來使用按位參數組合的最佳做法?
enum DLViewLayout
{
DLViewLayoutSolo = 1,
DLViewLayoutDual = 2
};
enum DLViewFixedHorizontalProperty
{
DLViewFixedHorizontalPropertyWidth = 4, // View margins scale with the screen width.
DLViewFixedHorizontalPropertyMargin = 8 // View width scales with the screen width.
};
enum DLViewFixedVerticalProperty
{
DLViewFixedVerticalPropertyHeight = 16,
DLViewFixedVerticalPropertyMargin = 32
};
enum DLViewHorizonalAlignment
{
DLViewHorizonalAlignmentLeft = 64,
DLViewHorizonalAlignmentCenter = 128,
DLViewHorizonalAlignmentRight = 256
};
enum DLViewVerticalAlignment
{
DLViewVerticalAlignmentTop = 512,
DLViewVerticalAlignmentMiddle = 1024,
DLViewVerticalAlignmentBottom = 2048
};
我不知道在什麼情況下會是有意義的按位OR
結合枚舉值傳遞一個視圖狀態。
int viewState = DLViewLayoutSolo | DLViewFixedHorizontalPropertyWidth | DLViewFixedVerticalPropertyMargin | DLViewHorizonalAlignmentCenter | DLViewVerticalAlignmentMiddle;
// viewState = 1189
我希望類的用戶配置所有參數。我如何執行此操作?
在課堂上,我可以通過按位組合AND
來檢索各個設置。
if (viewState & DLViewLayoutSolo)
{
// Set up solo view layout.
}
else if (viewState & DLViewLayoutDual)
{
// Set up dual view layout.
}
哪種編程語言? – nos 2011-04-25 16:31:46
編程語言是C++。 – JJD 2011-04-25 16:38:46