Improve inset handling

This commit is contained in:
Henrik Rydgård committed 2025-10-28 14:54:28 +01:00
1 parent b660dcee2b
commit 42a44e4243
11 files changed
+27 -17

No files matched your search

+6 -3
View File
@@ -137,13 +137,16 @@ Bounds UIContext::GetScissorBounds() {
return bounds_;
}
Bounds UIContext::GetLayoutBounds() const {
Bounds UIContext::GetLayoutBounds(bool ignoreBottomInset) const {
Bounds bounds = GetBounds();
float left = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);
float right = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_RIGHT);
float top = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_TOP);
// float bottom = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM);
float bottom = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_BOTTOM);
if (ignoreBottomInset) {
bottom = 0.0f;
}
// Note that we ignore bottom here, to let lists etc. extend to the bottom of the screen.
// However, we will add the same space to the bottom of scrolled lists, so that you don't have to
@@ -153,7 +156,7 @@ Bounds UIContext::GetLayoutBounds() const {
bounds.x += left;
bounds.w -= (left + right);
bounds.y += top;
bounds.h -= top;
bounds.h -= (top + bottom);
return bounds;
}
+1 -3
View File
@@ -113,7 +113,7 @@ public:
// in dps, like dp_xres and dp_yres
void SetBounds(const Bounds &b) { bounds_ = b; }
const Bounds &GetBounds() const { return bounds_; }
Bounds GetLayoutBounds() const;
Bounds GetLayoutBounds(bool ignoreBottomInset = false) const;
Draw::DrawContext *GetDrawContext() { return draw_; }
const UI::Theme &GetTheme() const {
return *theme;
@@ -130,8 +130,6 @@ public:
atlasInvalid_ = true; // will cause it to be reloaded on the next frame.
}
private:
void GenerateUIAtlas();
Draw::DrawContext *draw_ = nullptr;
Bounds bounds_;
+2 -2
View File
@@ -100,8 +100,8 @@ bool IsFocusMovementEnabled() {
return focusMovementEnabled;
}
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets) {
Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds();
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset) {
Bounds rootBounds = ignoreInsets ? dc.GetBounds() : dc.GetLayoutBounds(ignoreBottomInset);
MeasureSpec horiz(EXACTLY, rootBounds.w);
MeasureSpec vert(EXACTLY, rootBounds.h);
+1 -1
View File
@@ -22,7 +22,7 @@ DialogResult DispatchEvents();
class ViewGroup;
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets);
void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root, bool ignoreInsets, bool ignoreBottomInset);
DialogResult UpdateViewHierarchy(ViewGroup *root);
enum class KeyEventResult {
+1 -1
View File
@@ -58,7 +58,7 @@ TabHolder::TabHolder(Orientation orientation, float stripSize, TabHolderFlags fl
void TabHolder::AddBack(UIScreen *parent) {
if (tabContainer_) {
auto di = GetI18NCategory(I18NCat::DIALOG);
tabContainer_->Add(new Choice(di->T("Back"), "", false, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 0.0f, Margins(0, 0, 10, 10))))->OnClick.Handle<UIScreen>(parent, &UIScreen::OnBack);
tabContainer_->Add(new Choice(di->T("Back"), ImageID("I_NAVIGATE_BACK"), new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 0.0f, Margins(0, 0, 10, 10))))->OnClick.Handle<UIScreen>(parent, &UIScreen::OnBack);
}
}
+2 -2
View File
@@ -56,7 +56,7 @@ void UIScreen::DoRecreateViews() {
// Update layout and refocus so things scroll into view.
// This is for resizing down, when focused on something now offscreen.
UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_, ignoreInsets_);
UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_, ignoreInsets_, ignoreBottomInset_);
UI::View *focused = UI::GetFocusedView();
if (focused) {
root_->SubviewFocused(focused);
@@ -229,7 +229,7 @@ ScreenRenderFlags UIScreen::render(ScreenRenderMode mode) {
UIContext &uiContext = *screenManager()->getUIContext();
if (root_) {
UI::LayoutViewHierarchy(uiContext, root_, ignoreInsets_);
UI::LayoutViewHierarchy(uiContext, root_, ignoreInsets_, ignoreBottomInset_);
}
uiContext.PushTransform({translation_, scale_, alpha_});
+1
View File
@@ -68,6 +68,7 @@ protected:
Vec3 scale_ = Vec3(1.0f);
float alpha_ = 1.0f;
bool ignoreInsets_ = false;
bool ignoreBottomInset_ = false;
bool ignoreInput_ = false;
protected:
+1 -1
View File
@@ -1941,7 +1941,7 @@ void EmuScreen::renderUI() {
thin3d->SetViewport(viewport);
if (root_) {
UI::LayoutViewHierarchy(*ctx, root_, false);
UI::LayoutViewHierarchy(*ctx, root_, false, false);
root_->Draw(*ctx);
}
+6 -3
View File
@@ -795,7 +795,7 @@ void GameBrowser::Refresh() {
topBar->Add(new Choice(ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick);
#else
if ((browseFlags_ & BrowseFlags::BROWSE) && System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) {
// Collapse the button title on very small screens (Retroid Pocket).
// Collapse the button title on very small screens (Retroid Pocket) or portrait mode.
std::string_view browseTitle = g_display.pixel_xres <= 640 ? "" : mm->T("Browse");
topBar->Add(new Choice(browseTitle, ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick);
}
@@ -1069,6 +1069,7 @@ void GameBrowser::OnHomebrewStore(UI::EventParams &e) {
MainScreen::MainScreen() {
g_BackgroundAudio.SetGame(Path());
ignoreBottomInset_ = true;
}
MainScreen::~MainScreen() {
@@ -1090,9 +1091,11 @@ void MainScreen::CreateRecentTab() {
ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
scrollRecentGames->SetTag("MainScreenRecentGames");
GameBrowser *tabRecentGames = new GameBrowser(GetRequesterToken(),
Path("!RECENT"), BrowseFlags::NONE, &g_Config.bGridView1, screenManager(), "", "",
new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
scrollRecentGames->Add(tabRecentGames);
gameBrowsers_.push_back(tabRecentGames);
@@ -1111,7 +1114,7 @@ GameBrowser *MainScreen::CreateBrowserTab(const Path &path, std::string_view tit
GameBrowser *gameBrowser = new GameBrowser(GetRequesterToken(), path, browseFlags, bGridView, screenManager(),
mm->T(howToTitle), howToUri,
new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
scrollView->Add(gameBrowser);
gameBrowsers_.push_back(gameBrowser);
+3
View File
@@ -937,6 +937,9 @@ private:
void CreditsScreen::CreateViews() {
using namespace UI;
ignoreBottomInset_ = false;
auto di = GetI18NCategory(I18NCat::DIALOG);
auto cr = GetI18NCategory(I18NCat::PSPCREDITS);
auto mm = GetI18NCategory(I18NCat::MAINMENU);
+3 -1
View File
@@ -20,7 +20,9 @@ ENUM_CLASS_BITOPS(TabFlags);
class TabbedUIDialogScreenWithGameBackground : public UIDialogScreenWithGameBackground {
public:
TabbedUIDialogScreenWithGameBackground(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
TabbedUIDialogScreenWithGameBackground(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {
ignoreBottomInset_ = true;
}
void AddTab(const char *tag, std::string_view title, std::function<void(UI::LinearLayout *)> createCallback, TabFlags flags = TabFlags::Default);
void CreateViews() override;