mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Add horizontal orientation to TabHolder. Don't draw things outside current scissor rect.
This commit is contained in:
parent
3a51252fb9
commit
cf7ccddf1e
@ -30,6 +30,11 @@ struct Bounds {
|
||||
bool Contains(float px, float py) const {
|
||||
return (px >= x && py >= y && px < x + w && py < y + h);
|
||||
}
|
||||
|
||||
bool Intersects(const Bounds &other) const {
|
||||
return !(x > other.x2() || x2() < other.x || y > other.y2() || y2() < other.y);
|
||||
}
|
||||
|
||||
float x2() const { return x + w; }
|
||||
float y2() const { return y + h; }
|
||||
float centerX() const { return x + w * 0.5f; }
|
||||
|
@ -77,6 +77,14 @@ void UIContext::PopScissor() {
|
||||
ActivateTopScissor();
|
||||
}
|
||||
|
||||
Bounds UIContext::GetScissorBounds() {
|
||||
if (!scissorStack_.empty())
|
||||
return scissorStack_.back();
|
||||
else
|
||||
return Bounds(0, 0, dp_xres, dp_yres);
|
||||
}
|
||||
|
||||
|
||||
void UIContext::ActivateTopScissor() {
|
||||
if (scissorStack_.size()) {
|
||||
const Bounds &bounds = scissorStack_.back();
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
// TODO: Support transformed bounds using stencil
|
||||
void PushScissor(const Bounds &bounds);
|
||||
void PopScissor();
|
||||
Bounds GetScissorBounds();
|
||||
|
||||
void ActivateTopScissor();
|
||||
|
||||
|
@ -42,7 +42,7 @@ void MeasureBySpec(Size sz, float contentWidth, MeasureSpec spec, float *measure
|
||||
*measured = spec.size;
|
||||
} else if (sz == FILL_PARENT) {
|
||||
if (spec.type == UNSPECIFIED)
|
||||
*measured = 0.0; // We have no value to set
|
||||
*measured = contentWidth; // We have no value to set
|
||||
else
|
||||
*measured = spec.size;
|
||||
} else if (spec.type == EXACTLY || (spec.type == AT_MOST && *measured > spec.size)) {
|
||||
@ -180,6 +180,10 @@ void ClickableItem::Draw(UIContext &dc) {
|
||||
dc.FillRect(style.background, bounds_);
|
||||
}
|
||||
|
||||
void Choice::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
|
||||
dc.Draw()->MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h);
|
||||
}
|
||||
|
||||
void Choice::Draw(UIContext &dc) {
|
||||
ClickableItem::Draw(dc);
|
||||
|
||||
|
@ -133,6 +133,10 @@ enum Orientation {
|
||||
ORIENT_VERTICAL,
|
||||
};
|
||||
|
||||
inline Orientation Opposite(Orientation o) {
|
||||
if (o == ORIENT_HORIZONTAL) return ORIENT_VERTICAL; else return ORIENT_HORIZONTAL;
|
||||
}
|
||||
|
||||
enum MeasureSpecType {
|
||||
UNSPECIFIED,
|
||||
EXACTLY,
|
||||
@ -167,7 +171,7 @@ class View;
|
||||
struct EventParams {
|
||||
View *v;
|
||||
uint32_t a, b, x, y;
|
||||
const char *c;
|
||||
std::string s;
|
||||
};
|
||||
|
||||
struct HandlerRegistration {
|
||||
@ -416,6 +420,7 @@ public:
|
||||
Choice(const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0)
|
||||
: ClickableItem(layoutParams), text_(text), smallText_(smallText) {}
|
||||
|
||||
virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const;
|
||||
virtual void Draw(UIContext &dc);
|
||||
|
||||
private:
|
||||
|
@ -47,8 +47,11 @@ void ViewGroup::Touch(const TouchInput &input) {
|
||||
void ViewGroup::Draw(UIContext &dc) {
|
||||
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
|
||||
// TODO: If there is a transformation active, transform input coordinates accordingly.
|
||||
if ((*iter)->GetVisibility() == V_VISIBLE)
|
||||
(*iter)->Draw(dc);
|
||||
if ((*iter)->GetVisibility() == V_VISIBLE) {
|
||||
// Check if bounds are in current scissor rectangle.
|
||||
if (dc.GetScissorBounds().Intersects((*iter)->GetBounds()))
|
||||
(*iter)->Draw(dc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -530,6 +533,7 @@ void GridLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver
|
||||
|
||||
// Okay, got the width we are supposed to adjust to. Now we can calculate the number of columns.
|
||||
int numColumns = (measuredWidth_ - settings_.spacing) / (settings_.columnWidth + settings_.spacing);
|
||||
if (!numColumns) numColumns = 1;
|
||||
int numRows = (int)(views_.size() + (numColumns - 1)) / numColumns;
|
||||
|
||||
float estimatedHeight = settings_.rowHeight * numRows;
|
||||
@ -620,7 +624,7 @@ void GridLayout::Layout() {
|
||||
views_[i]->Layout();
|
||||
|
||||
x += itemBounds.w;
|
||||
if (x >= bounds_.w) {
|
||||
if (x + itemBounds.w >= bounds_.w) {
|
||||
x = 0;
|
||||
y += itemBounds.h + settings_.spacing;
|
||||
} else {
|
||||
|
@ -197,9 +197,9 @@ public:
|
||||
class TabHolder : public LinearLayout {
|
||||
public:
|
||||
TabHolder(Orientation orientation, float stripSize, LayoutParams *layoutParams = 0)
|
||||
: LinearLayout(ORIENT_HORIZONTAL, layoutParams),
|
||||
: LinearLayout(Opposite(orientation), layoutParams),
|
||||
orientation_(orientation), stripSize_(stripSize), currentTab_(0) {
|
||||
tabStrip_ = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(stripSize, WRAP_CONTENT));
|
||||
tabStrip_ = new LinearLayout(orientation, new LinearLayoutParams(stripSize, WRAP_CONTENT));
|
||||
Add(tabStrip_);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user