mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-13 10:24:39 +00:00
Layout changes for popup views
This commit is contained in:
parent
44c239ef18
commit
0c8692bc44
@ -71,7 +71,9 @@ void PopupScreen::CreateViews() {
|
|||||||
using namespace UI;
|
using namespace UI;
|
||||||
|
|
||||||
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
|
||||||
LinearLayout *box = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(30, 30, 30, 30));
|
|
||||||
|
LinearLayout *box = new LinearLayout(ORIENT_VERTICAL,
|
||||||
|
new AnchorLayoutParams(450, FillVertical() ? dp_yres - 30 : WRAP_CONTENT, dp_xres / 2, dp_yres / 2, NONE, NONE, true));
|
||||||
|
|
||||||
root_->Add(box);
|
root_->Add(box);
|
||||||
box->SetBG(UI::Drawable(0xFF303030));
|
box->SetBG(UI::Drawable(0xFF303030));
|
||||||
@ -83,7 +85,7 @@ void PopupScreen::CreateViews() {
|
|||||||
CreatePopupContents(box);
|
CreatePopupContents(box);
|
||||||
|
|
||||||
// And the two buttons at the bottom.
|
// And the two buttons at the bottom.
|
||||||
ViewGroup *buttonRow = new LinearLayout(ORIENT_HORIZONTAL);
|
ViewGroup *buttonRow = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(200, WRAP_CONTENT));
|
||||||
buttonRow->Add(new Button("OK", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK);
|
buttonRow->Add(new Button("OK", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK);
|
||||||
buttonRow->Add(new Button("Cancel", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel);
|
buttonRow->Add(new Button("Cancel", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel);
|
||||||
box->Add(buttonRow);
|
box->Add(buttonRow);
|
||||||
@ -100,7 +102,6 @@ UI::EventReturn PopupScreen::OnCancel(UI::EventParams &e) {
|
|||||||
return UI::EVENT_DONE;
|
return UI::EVENT_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ListPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
void ListPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
||||||
using namespace UI;
|
using namespace UI;
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ void ListPopupScreen::OnCompleted() {
|
|||||||
|
|
||||||
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
||||||
using namespace UI;
|
using namespace UI;
|
||||||
slider_ = parent->Add(new Slider(value_, minValue_, maxValue_));
|
slider_ = parent->Add(new Slider(value_, minValue_, maxValue_, new LinearLayoutParams(UI::Margins(10, 5))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SliderFloatPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
void SliderFloatPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
virtual bool isTransparent() { return true; }
|
virtual bool isTransparent() { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool FillVertical() { return false; }
|
||||||
virtual void OnCompleted() {}
|
virtual void OnCompleted() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -57,6 +58,7 @@ public:
|
|||||||
UI::Event OnChoice;
|
UI::Event OnChoice;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool FillVertical() { return true; }
|
||||||
virtual void OnCompleted();
|
virtual void OnCompleted();
|
||||||
void CreatePopupContents(UI::ViewGroup *parent);
|
void CreatePopupContents(UI::ViewGroup *parent);
|
||||||
UI::StringVectorListAdaptor adaptor_;
|
UI::StringVectorListAdaptor adaptor_;
|
||||||
|
@ -323,6 +323,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
|
|||||||
views_[i]->Measure(dc, MeasureSpec(EXACTLY, unit * linLayoutParams->weight), MeasureSpec(EXACTLY, measuredHeight_));
|
views_[i]->Measure(dc, MeasureSpec(EXACTLY, unit * linLayoutParams->weight), MeasureSpec(EXACTLY, measuredHeight_));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//MeasureBySpec(layoutParams_->height, vert.type == UNSPECIFIED ? sum : weightZeroSum, vert, &measuredHeight_);
|
||||||
MeasureBySpec(layoutParams_->height, weightZeroSum, vert, &measuredHeight_);
|
MeasureBySpec(layoutParams_->height, weightZeroSum, vert, &measuredHeight_);
|
||||||
MeasureBySpec(layoutParams_->width, maxOther, horiz, &measuredWidth_);
|
MeasureBySpec(layoutParams_->width, maxOther, horiz, &measuredWidth_);
|
||||||
|
|
||||||
@ -431,7 +432,7 @@ void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver
|
|||||||
margins = linLayoutParams->margins;
|
margins = linLayoutParams->margins;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The scroll view itself simply obeys its parent.
|
// The scroll view itself simply obeys its parent - but also tries to fit the child if possible.
|
||||||
MeasureBySpec(layoutParams_->width, 0.0f, horiz, &measuredWidth_);
|
MeasureBySpec(layoutParams_->width, 0.0f, horiz, &measuredWidth_);
|
||||||
MeasureBySpec(layoutParams_->height, 0.0f, vert, &measuredHeight_);
|
MeasureBySpec(layoutParams_->height, 0.0f, vert, &measuredHeight_);
|
||||||
|
|
||||||
@ -440,6 +441,8 @@ void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver
|
|||||||
} else {
|
} else {
|
||||||
views_[0]->Measure(dc, MeasureSpec(AT_MOST, measuredWidth_ - (margins.left + margins.right)), MeasureSpec(UNSPECIFIED));
|
views_[0]->Measure(dc, MeasureSpec(AT_MOST, measuredWidth_ - (margins.left + margins.right)), MeasureSpec(UNSPECIFIED));
|
||||||
}
|
}
|
||||||
|
if (orientation_ == ORIENT_VERTICAL && vert.type != EXACTLY && measuredHeight_ < views_[0]->GetBounds().h)
|
||||||
|
measuredHeight_ = views_[0]->GetBounds().h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollView::Layout() {
|
void ScrollView::Layout() {
|
||||||
@ -489,21 +492,26 @@ void ScrollView::Touch(const TouchInput &input) {
|
|||||||
scrollStart_ = scrollPos_;
|
scrollStart_ = scrollPos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
TouchInput input2 = gesture_.Update(input, bounds_);
|
TouchInput input2;
|
||||||
|
if (CanScroll()) {
|
||||||
|
input2 = gesture_.Update(input, bounds_);
|
||||||
|
if (gesture_.IsGestureActive(GESTURE_DRAG_VERTICAL)) {
|
||||||
|
float info[4];
|
||||||
|
gesture_.GetGestureInfo(GESTURE_DRAG_VERTICAL, info);
|
||||||
|
|
||||||
if (gesture_.IsGestureActive(GESTURE_DRAG_VERTICAL)) {
|
float pos = scrollStart_ - info[0];
|
||||||
float info[4];
|
ClampScrollPos(pos);
|
||||||
gesture_.GetGestureInfo(GESTURE_DRAG_VERTICAL, info);
|
scrollPos_ = pos;
|
||||||
|
scrollTarget_ = pos;
|
||||||
float pos = scrollStart_ - info[0];
|
scrollToTarget_ = false;
|
||||||
ClampScrollPos(pos);
|
}
|
||||||
scrollPos_ = pos;
|
} else {
|
||||||
scrollTarget_ = pos;
|
input2 = input;
|
||||||
scrollToTarget_ = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(input.flags & TOUCH_DOWN) || bounds_.Contains(input.x, input.y))
|
if (!(input.flags & TOUCH_DOWN) || bounds_.Contains(input.x, input.y)) {
|
||||||
ViewGroup::Touch(input2);
|
ViewGroup::Touch(input2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollView::Draw(UIContext &dc) {
|
void ScrollView::Draw(UIContext &dc) {
|
||||||
@ -578,6 +586,9 @@ void ScrollView::ClampScrollPos(float &pos) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScrollView::CanScroll() const {
|
||||||
|
return views_[0]->GetBounds().h > bounds_.h;
|
||||||
|
}
|
||||||
|
|
||||||
void ScrollView::Update(const InputState &input_state) {
|
void ScrollView::Update(const InputState &input_state) {
|
||||||
ViewGroup::Update(input_state);
|
ViewGroup::Update(input_state);
|
||||||
@ -633,6 +644,10 @@ void AnchorLayout::Layout() {
|
|||||||
vBounds.w = views_[i]->GetMeasuredWidth();
|
vBounds.w = views_[i]->GetMeasuredWidth();
|
||||||
vBounds.h = views_[i]->GetMeasuredHeight();
|
vBounds.h = views_[i]->GetMeasuredHeight();
|
||||||
|
|
||||||
|
// Clamp width/height to our own
|
||||||
|
if (vBounds.w > bounds_.w) vBounds.w = bounds_.w;
|
||||||
|
if (vBounds.h > bounds_.h) vBounds.h = bounds_.h;
|
||||||
|
|
||||||
float left = 0, top = 0, right = 0, bottom = 0, center = false;
|
float left = 0, top = 0, right = 0, bottom = 0, center = false;
|
||||||
if (params) {
|
if (params) {
|
||||||
left = params->left;
|
left = params->left;
|
||||||
|
@ -80,7 +80,9 @@ public:
|
|||||||
: LayoutParams(w, h, LP_ANCHOR), left(l), top(t), right(r), bottom(b), center(c) {
|
: LayoutParams(w, h, LP_ANCHOR), left(l), top(t), right(r), bottom(b), center(c) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
AnchorLayoutParams(Size w, Size h, bool c = false)
|
||||||
|
: LayoutParams(w, h, LP_ANCHOR), left(0), top(0), right(NONE), bottom(NONE), center(c) {
|
||||||
|
}
|
||||||
AnchorLayoutParams(float l, float t, float r, float b, bool c = false)
|
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) {}
|
: LayoutParams(WRAP_CONTENT, WRAP_CONTENT, LP_ANCHOR), left(l), top(t), right(r), bottom(b), center(c) {}
|
||||||
|
|
||||||
@ -191,6 +193,7 @@ public:
|
|||||||
|
|
||||||
void ScrollTo(float newScrollPos);
|
void ScrollTo(float newScrollPos);
|
||||||
void ScrollRelative(float distance);
|
void ScrollRelative(float distance);
|
||||||
|
bool CanScroll() const;
|
||||||
void Update(const InputState &input_state);
|
void Update(const InputState &input_state);
|
||||||
|
|
||||||
// Override so that we can scroll to the active one after moving the focus.
|
// Override so that we can scroll to the active one after moving the focus.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user