mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-22 10:49:05 +02:00
Prettify fake RTTI for layout params.
Better not to make the RTTI/non-RTTI thing a problem in lots of places.
This commit is contained in:
1 parent
e7f70ff8d0
commit
85ad28d4cd
3 files changed
+36
-22
No files matched your search
@@ -292,6 +292,26 @@ public:
|
||||
// Fake RTTI
|
||||
bool Is(LayoutParamsType type) const { return type_ == type; }
|
||||
|
||||
template <typename T>
|
||||
T *As() {
|
||||
if (Is(T::StaticType())) {
|
||||
return static_cast<T *>(this);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T *As() const {
|
||||
if (Is(T::StaticType())) {
|
||||
return static_cast<const T *>(this);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static LayoutParamsType StaticType() {
|
||||
return LP_PLAIN;
|
||||
}
|
||||
|
||||
private:
|
||||
LayoutParamsType type_;
|
||||
};
|
||||
|
||||
@@ -395,9 +395,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
|
||||
continue;
|
||||
numVisible++;
|
||||
|
||||
const LayoutParams *layoutParams = views_[i]->GetLayoutParams();
|
||||
const LinearLayoutParams *linLayoutParams = static_cast<const LinearLayoutParams *>(layoutParams);
|
||||
if (!linLayoutParams->Is(LP_LINEAR)) linLayoutParams = 0;
|
||||
const LinearLayoutParams *linLayoutParams = views_[i]->GetLayoutParams()->As<LinearLayoutParams>();
|
||||
|
||||
Margins margins = defaultMargins_;
|
||||
|
||||
@@ -459,9 +457,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
|
||||
for (size_t i = 0; i < views_.size(); i++) {
|
||||
if (views_[i]->GetVisibility() == V_GONE)
|
||||
continue;
|
||||
const LayoutParams *layoutParams = views_[i]->GetLayoutParams();
|
||||
const LinearLayoutParams *linLayoutParams = static_cast<const LinearLayoutParams *>(layoutParams);
|
||||
if (!linLayoutParams->Is(LP_LINEAR)) linLayoutParams = 0;
|
||||
const LinearLayoutParams *linLayoutParams = views_[i]->GetLayoutParams()->As<LinearLayoutParams>();
|
||||
|
||||
if (linLayoutParams && linLayoutParams->weight > 0.0f) {
|
||||
Margins margins = defaultMargins_;
|
||||
@@ -500,9 +496,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
|
||||
for (size_t i = 0; i < views_.size(); i++) {
|
||||
if (views_[i]->GetVisibility() == V_GONE)
|
||||
continue;
|
||||
const LayoutParams *layoutParams = views_[i]->GetLayoutParams();
|
||||
const LinearLayoutParams *linLayoutParams = static_cast<const LinearLayoutParams *>(layoutParams);
|
||||
if (!linLayoutParams->Is(LP_LINEAR)) linLayoutParams = 0;
|
||||
const LinearLayoutParams *linLayoutParams = views_[i]->GetLayoutParams()->As<LinearLayoutParams>();
|
||||
|
||||
if (linLayoutParams && linLayoutParams->weight > 0.0f) {
|
||||
Margins margins = defaultMargins_;
|
||||
@@ -548,9 +542,7 @@ void LinearLayout::Layout() {
|
||||
if (views_[i]->GetVisibility() == V_GONE)
|
||||
continue;
|
||||
|
||||
const LayoutParams *layoutParams = views_[i]->GetLayoutParams();
|
||||
const LinearLayoutParams *linLayoutParams = static_cast<const LinearLayoutParams *>(layoutParams);
|
||||
if (!linLayoutParams->Is(LP_LINEAR)) linLayoutParams = 0;
|
||||
const LinearLayoutParams *linLayoutParams = views_[i]->GetLayoutParams()->As<LinearLayoutParams>();
|
||||
|
||||
Gravity gravity = G_TOPLEFT;
|
||||
Margins margins = defaultMargins_;
|
||||
@@ -615,10 +607,7 @@ void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver
|
||||
// Respect margins
|
||||
Margins margins;
|
||||
if (views_.size()) {
|
||||
const LinearLayoutParams *linLayoutParams = static_cast<const LinearLayoutParams*>(views_[0]->GetLayoutParams());
|
||||
if (!linLayoutParams->Is(LP_LINEAR)) {
|
||||
linLayoutParams = 0;
|
||||
}
|
||||
const LinearLayoutParams *linLayoutParams = views_[0]->GetLayoutParams()->As<LinearLayoutParams>();
|
||||
if (linLayoutParams) {
|
||||
margins = linLayoutParams->margins;
|
||||
}
|
||||
@@ -657,8 +646,7 @@ void ScrollView::Layout() {
|
||||
|
||||
// Respect margins
|
||||
Margins margins;
|
||||
const LinearLayoutParams *linLayoutParams = static_cast<const LinearLayoutParams*>(views_[0]->GetLayoutParams());
|
||||
if (!linLayoutParams->Is(LP_LINEAR)) linLayoutParams = 0;
|
||||
const LinearLayoutParams *linLayoutParams = views_[0]->GetLayoutParams()->As<LinearLayoutParams>();
|
||||
if (linLayoutParams) {
|
||||
margins = linLayoutParams->margins;
|
||||
}
|
||||
@@ -909,8 +897,7 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
|
||||
}
|
||||
}
|
||||
|
||||
const AnchorLayoutParams *params = static_cast<const AnchorLayoutParams *>(views_[i]->GetLayoutParams());
|
||||
if (!params->Is(LP_ANCHOR)) params = 0;
|
||||
const AnchorLayoutParams *params = views_[i]->GetLayoutParams()->As<AnchorLayoutParams>();
|
||||
if (params) {
|
||||
width = params->width;
|
||||
height = params->height;
|
||||
@@ -937,8 +924,7 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
|
||||
|
||||
void AnchorLayout::Layout() {
|
||||
for (size_t i = 0; i < views_.size(); i++) {
|
||||
const AnchorLayoutParams *params = static_cast<const AnchorLayoutParams *>(views_[i]->GetLayoutParams());
|
||||
if (!params->Is(LP_ANCHOR)) params = 0;
|
||||
const AnchorLayoutParams *params = views_[i]->GetLayoutParams()->As<AnchorLayoutParams>();
|
||||
|
||||
Bounds vBounds;
|
||||
vBounds.w = views_[i]->GetMeasuredWidth();
|
||||
|
||||
@@ -111,6 +111,10 @@ public:
|
||||
// Set to NONE to not attach this edge to the container.
|
||||
float left, top, right, bottom;
|
||||
bool center; // If set, only two "sides" can be set, and they refer to the center, not the edge, of the view being layouted.
|
||||
|
||||
static LayoutParamsType StaticType() {
|
||||
return LP_ANCHOR;
|
||||
}
|
||||
};
|
||||
|
||||
class AnchorLayout : public ViewGroup {
|
||||
@@ -152,6 +156,10 @@ public:
|
||||
|
||||
bool HasMargins() const { return hasMargins_; }
|
||||
|
||||
static LayoutParamsType StaticType() {
|
||||
return LP_LINEAR;
|
||||
}
|
||||
|
||||
private:
|
||||
bool hasMargins_;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user