mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-11 16:49:27 +01:00
Add centering mode to AnchorLayout.
This commit is contained in:
1 parent
13b8277bd3
commit
b059027359
3 files changed
+42
-16
No files matched your search
+5
-1
@@ -16,7 +16,11 @@ void UIScreen::update(InputState &input) {
|
||||
recreateViews_ = false;
|
||||
}
|
||||
|
||||
UpdateViewHierarchy(input, root_);
|
||||
if (root_) {
|
||||
UpdateViewHierarchy(input, root_);
|
||||
} else {
|
||||
ELOG("Tried to update without a view root");
|
||||
}
|
||||
}
|
||||
|
||||
void UIScreen::render() {
|
||||
|
||||
+32
-11
@@ -608,11 +608,13 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
|
||||
width = params->width;
|
||||
height = params->height;
|
||||
|
||||
if (params->left >= 0 && params->right >= 0) {
|
||||
width = measuredWidth_ - params->left - params->right;
|
||||
}
|
||||
if (params->top >= 0 && params->bottom >= 0) {
|
||||
height = measuredHeight_ - params->top - params->bottom;
|
||||
if (!params->center) {
|
||||
if (params->left >= 0 && params->right >= 0) {
|
||||
width = measuredWidth_ - params->left - params->right;
|
||||
}
|
||||
if (params->top >= 0 && params->bottom >= 0) {
|
||||
height = measuredHeight_ - params->top - params->bottom;
|
||||
}
|
||||
}
|
||||
specW = width < 0 ? MeasureSpec(UNSPECIFIED) : MeasureSpec(EXACTLY, width);
|
||||
specH = height < 0 ? MeasureSpec(UNSPECIFIED) : MeasureSpec(EXACTLY, height);
|
||||
@@ -631,24 +633,35 @@ void AnchorLayout::Layout() {
|
||||
vBounds.w = views_[i]->GetMeasuredWidth();
|
||||
vBounds.h = views_[i]->GetMeasuredHeight();
|
||||
|
||||
float left = 0, top = 0, right = 0, bottom = 0;
|
||||
|
||||
float left = 0, top = 0, right = 0, bottom = 0, center = false;
|
||||
if (params) {
|
||||
left = params->left;
|
||||
top = params->top;
|
||||
right = params->right;
|
||||
bottom = params->bottom;
|
||||
center = params->center;
|
||||
}
|
||||
|
||||
if (left >= 0)
|
||||
if (left >= 0) {
|
||||
vBounds.x = bounds_.x + left;
|
||||
else if (right >= 0)
|
||||
if (center)
|
||||
vBounds.x -= vBounds.w * 0.5f;
|
||||
} else if (right >= 0) {
|
||||
vBounds.x = bounds_.x2() - right - vBounds.w;
|
||||
if (center) {
|
||||
vBounds.x += vBounds.w * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (top >= 0)
|
||||
if (top >= 0) {
|
||||
vBounds.y = bounds_.y + top;
|
||||
else if (bottom >= 0)
|
||||
if (center)
|
||||
vBounds.y -= vBounds.h * 0.5f;
|
||||
} else if (bottom >= 0) {
|
||||
vBounds.y = bounds_.y2() - bottom - vBounds.h;
|
||||
if (center)
|
||||
vBounds.y += vBounds.h * 0.5f;
|
||||
}
|
||||
|
||||
views_[i]->SetBounds(vBounds);
|
||||
views_[i]->Layout();
|
||||
@@ -796,6 +809,10 @@ bool StringVectorListAdaptor::AddEventCallback(View *view, std::function<EventRe
|
||||
}
|
||||
|
||||
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root) {
|
||||
if (!root) {
|
||||
ELOG("Tried to layout a view hierarchy from a zero pointer root");
|
||||
return;
|
||||
}
|
||||
Bounds rootBounds;
|
||||
rootBounds.x = 0;
|
||||
rootBounds.y = 0;
|
||||
@@ -813,6 +830,10 @@ void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root) {
|
||||
}
|
||||
|
||||
void UpdateViewHierarchy(const InputState &input_state, ViewGroup *root) {
|
||||
if (!root) {
|
||||
ELOG("Tried to update a view hierarchy from a zero pointer root");
|
||||
return;
|
||||
}
|
||||
if (input_state.pad_buttons_down & (PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT | PAD_BUTTON_UP | PAD_BUTTON_DOWN)) {
|
||||
EnableFocusMovement(true);
|
||||
if (!GetFocusedView()) {
|
||||
|
||||
+5
-4
@@ -76,17 +76,18 @@ enum {
|
||||
|
||||
class AnchorLayoutParams : public LayoutParams {
|
||||
public:
|
||||
AnchorLayoutParams(Size w, Size h, float l, float t, float r, float b)
|
||||
: LayoutParams(w, h, LP_ANCHOR), left(l), top(t), right(r), bottom(b) {
|
||||
AnchorLayoutParams(Size w, Size h, float l, float t, float r, float b, bool c = false)
|
||||
: LayoutParams(w, h, LP_ANCHOR), left(l), top(t), right(r), bottom(b), center(c) {
|
||||
|
||||
}
|
||||
|
||||
AnchorLayoutParams(float l, float t, float r, float b)
|
||||
: LayoutParams(WRAP_CONTENT, WRAP_CONTENT, LP_ANCHOR), left(l), top(t), right(r), bottom(b) {}
|
||||
AnchorLayoutParams(float l, float t, float r, float b, bool c = false)
|
||||
: LayoutParams(WRAP_CONTENT, WRAP_CONTENT, LP_ANCHOR), left(l), top(t), right(r), bottom(b), center(c) {}
|
||||
|
||||
// These are not bounds, but distances from the container edges.
|
||||
// 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.
|
||||
};
|
||||
|
||||
class AnchorLayout : public ViewGroup {
|
||||
|
||||
Reference in new issue
Block a user