mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 11:03:45 +01:00
UI: Apply GridLayout children's margins, drop the unused grid orientation
Grid children are given LinearLayoutParams almost everywhere, so their margins are taken from those as well as from GridLayoutParams, which gains margins. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7ddd0ce33b
commit
8b1ffb9b39
2 files changed
+23
-10
No files matched your search
+16
-5
@@ -1016,9 +1016,19 @@ void AnchorLayout::Layout() {
|
||||
}
|
||||
|
||||
GridLayout::GridLayout(GridLayoutSettings settings, LayoutParams *layoutParams)
|
||||
: ViewGroup(layoutParams), settings_(settings) {
|
||||
if (settings.orientation != ORIENT_HORIZONTAL)
|
||||
ERROR_LOG(Log::UI, "GridLayout: Vertical layouts not yet supported");
|
||||
: ViewGroup(layoutParams), settings_(settings) {}
|
||||
|
||||
// Grid children are mostly given LinearLayoutParams, so take the margins from those too.
|
||||
static Margins GetGridChildMargins(const View *view) {
|
||||
if (const GridLayoutParams *lp = view->GetLayoutParams()->As<GridLayoutParams>()) {
|
||||
return lp->margins;
|
||||
}
|
||||
if (const LinearLayoutParams *lp = view->GetLayoutParams()->As<LinearLayoutParams>()) {
|
||||
if (lp->HasMargins()) {
|
||||
return lp->margins;
|
||||
}
|
||||
}
|
||||
return Margins(0);
|
||||
}
|
||||
|
||||
void GridLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {
|
||||
@@ -1027,7 +1037,8 @@ void GridLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver
|
||||
int numItems = 0;
|
||||
for (size_t i = 0; i < views_.size(); i++) {
|
||||
if (views_[i]->GetVisibility() != V_GONE) {
|
||||
views_[i]->Measure(dc, MeasureSpec(measureType, settings_.columnWidth), MeasureSpec(measureType, settings_.rowHeight));
|
||||
const Margins margins = GetGridChildMargins(views_[i]);
|
||||
views_[i]->Measure(dc, MeasureSpec(measureType, settings_.columnWidth - margins.horiz()), MeasureSpec(measureType, settings_.rowHeight - margins.vert()));
|
||||
numItems++;
|
||||
}
|
||||
}
|
||||
@@ -1063,7 +1074,7 @@ void GridLayout::Layout() {
|
||||
itemBounds.w = settings_.columnWidth;
|
||||
itemBounds.h = settings_.rowHeight;
|
||||
|
||||
ApplyGravity(itemBounds, Margins(0.0f),
|
||||
ApplyGravity(itemBounds, GetGridChildMargins(views_[i]),
|
||||
views_[i]->GetMeasuredWidth(), views_[i]->GetMeasuredHeight(),
|
||||
grav, innerBounds);
|
||||
|
||||
|
||||
@@ -267,14 +267,12 @@ private:
|
||||
};
|
||||
|
||||
// GridLayout is a little different from the Android layout. This one has fixed size
|
||||
// rows and columns. Items are not allowed to deviate from the set sizes.
|
||||
// Initially, only horizontal layout is supported.
|
||||
// rows and columns, filled row by row. Items are not allowed to deviate from the set sizes.
|
||||
struct GridLayoutSettings {
|
||||
GridLayoutSettings() : orientation(ORIENT_HORIZONTAL), columnWidth(100), rowHeight(50), spacing(5), fillCells(false) {}
|
||||
GridLayoutSettings() : columnWidth(100), rowHeight(50), spacing(5), fillCells(false) {}
|
||||
GridLayoutSettings(int colW, int colH, int spac = 5)
|
||||
: orientation(ORIENT_HORIZONTAL), columnWidth(colW), rowHeight(colH), spacing(spac), fillCells(false) {}
|
||||
: columnWidth(colW), rowHeight(colH), spacing(spac), fillCells(false) {}
|
||||
|
||||
Orientation orientation;
|
||||
int columnWidth;
|
||||
int rowHeight;
|
||||
int spacing;
|
||||
@@ -288,8 +286,12 @@ public:
|
||||
explicit GridLayoutParams(Gravity grav)
|
||||
: LayoutParams(LP_GRID), gravity(grav) {
|
||||
}
|
||||
GridLayoutParams(Gravity grav, const Margins &mgn)
|
||||
: LayoutParams(LP_GRID), gravity(grav), margins(mgn) {
|
||||
}
|
||||
|
||||
Gravity gravity;
|
||||
Margins margins;
|
||||
|
||||
static LayoutParamsType StaticType() {
|
||||
return LP_GRID;
|
||||
|
||||
Reference in new issue
Block a user