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;
|
||||
|
||||
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);
|
||||
box->SetBG(UI::Drawable(0xFF303030));
|
||||
@ -83,7 +85,7 @@ void PopupScreen::CreateViews() {
|
||||
CreatePopupContents(box);
|
||||
|
||||
// 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("Cancel", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel);
|
||||
box->Add(buttonRow);
|
||||
@ -100,7 +102,6 @@ UI::EventReturn PopupScreen::OnCancel(UI::EventParams &e) {
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
|
||||
void ListPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
||||
using namespace UI;
|
||||
|
||||
@ -120,7 +121,7 @@ void ListPopupScreen::OnCompleted() {
|
||||
|
||||
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
|
||||
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) {
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
virtual bool isTransparent() { return true; }
|
||||
|
||||
protected:
|
||||
virtual bool FillVertical() { return false; }
|
||||
virtual void OnCompleted() {}
|
||||
|
||||
private:
|
||||
@ -57,6 +58,7 @@ public:
|
||||
UI::Event OnChoice;
|
||||
|
||||
protected:
|
||||
virtual bool FillVertical() { return true; }
|
||||
virtual void OnCompleted();
|
||||
void CreatePopupContents(UI::ViewGroup *parent);
|
||||
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_));
|
||||
}
|
||||
} else {
|
||||
//MeasureBySpec(layoutParams_->height, vert.type == UNSPECIFIED ? sum : weightZeroSum, vert, &measuredHeight_);
|
||||
MeasureBySpec(layoutParams_->height, weightZeroSum, vert, &measuredHeight_);
|
||||
MeasureBySpec(layoutParams_->width, maxOther, horiz, &measuredWidth_);
|
||||
|
||||
@ -431,7 +432,7 @@ void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver
|
||||
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_->height, 0.0f, vert, &measuredHeight_);
|
||||
|
||||
@ -440,6 +441,8 @@ void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver
|
||||
} else {
|
||||
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() {
|
||||
@ -489,21 +492,26 @@ void ScrollView::Touch(const TouchInput &input) {
|
||||
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 info[4];
|
||||
gesture_.GetGestureInfo(GESTURE_DRAG_VERTICAL, info);
|
||||
|
||||
float pos = scrollStart_ - info[0];
|
||||
ClampScrollPos(pos);
|
||||
scrollPos_ = pos;
|
||||
scrollTarget_ = pos;
|
||||
scrollToTarget_ = false;
|
||||
float pos = scrollStart_ - info[0];
|
||||
ClampScrollPos(pos);
|
||||
scrollPos_ = pos;
|
||||
scrollTarget_ = pos;
|
||||
scrollToTarget_ = false;
|
||||
}
|
||||
} else {
|
||||
input2 = input;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
ViewGroup::Update(input_state);
|
||||
@ -633,6 +644,10 @@ void AnchorLayout::Layout() {
|
||||
vBounds.w = views_[i]->GetMeasuredWidth();
|
||||
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;
|
||||
if (params) {
|
||||
left = params->left;
|
||||
|
@ -80,7 +80,9 @@ public:
|
||||
: 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)
|
||||
: 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 ScrollRelative(float distance);
|
||||
bool CanScroll() const;
|
||||
void Update(const InputState &input_state);
|
||||
|
||||
// Override so that we can scroll to the active one after moving the focus.
|
||||
|
Loading…
x
Reference in New Issue
Block a user