Make a separate function for getting minimum size based on layout

This commit is contained in:
Vitor Kiguchi 2020-01-21 18:44:04 -03:00
parent 0dcb886ef2
commit 157f82141d
4 changed files with 54 additions and 32 deletions

View File

@ -147,49 +147,35 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) {
Layout::FramebufferLayout layout; Layout::FramebufferLayout layout;
unsigned int min_width, min_height; Settings::LayoutOption layout_option = Settings::values.layout_option;
std::pair<unsigned, unsigned> min_size =
Layout::GetMinimumSizeFromLayout(layout_option, Settings::values.upright_screen);
if (Settings::values.custom_layout == true) { if (Settings::values.custom_layout == true) {
layout = Layout::CustomFrameLayout(width, height); layout = Layout::CustomFrameLayout(width, height);
} else { } else {
switch (Settings::values.layout_option) { width = std::max(width, min_size.first);
height = std::max(height, min_size.second);
switch (layout_option) {
case Settings::LayoutOption::SingleScreen: case Settings::LayoutOption::SingleScreen:
min_width = layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen,
Settings::values.swap_screen ? Core::kScreenBottomWidth : Core::kScreenTopWidth; Settings::values.upright_screen);
min_height = Core::kScreenBottomHeight;
layout = Layout::SingleFrameLayout(
std::max(width, min_width), std::max(height, min_height),
Settings::values.swap_screen, Settings::values.upright_screen);
break; break;
case Settings::LayoutOption::LargeScreen: case Settings::LayoutOption::LargeScreen:
min_width = Settings::values.swap_screen layout = Layout::LargeFrameLayout(width, height, Settings::values.swap_screen,
? Core::kScreenTopWidth / 4 + Core::kScreenBottomWidth Settings::values.upright_screen);
: Core::kScreenTopWidth + Core::kScreenBottomWidth / 4;
min_height = Core::kScreenBottomHeight;
layout = Layout::LargeFrameLayout(
std::max(width, min_width), std::max(height, min_height),
Settings::values.swap_screen, Settings::values.upright_screen);
break; break;
case Settings::LayoutOption::SideScreen: case Settings::LayoutOption::SideScreen:
min_width = Core::kScreenTopWidth + Core::kScreenBottomWidth; layout = Layout::SideFrameLayout(width, height, Settings::values.swap_screen,
min_height = Core::kScreenBottomHeight; Settings::values.upright_screen);
layout = Layout::SideFrameLayout(
std::max(width, min_width), std::max(height, min_height),
Settings::values.swap_screen, Settings::values.upright_screen);
break; break;
case Settings::LayoutOption::Default: case Settings::LayoutOption::Default:
default: default:
min_width = Core::kScreenTopWidth; layout = Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen,
min_height = Core::kScreenTopHeight + Core::kScreenBottomHeight; Settings::values.upright_screen);
layout = Layout::DefaultFrameLayout(
std::max(width, min_width), std::max(height, min_height),
Settings::values.swap_screen, Settings::values.upright_screen);
break; break;
} }
if (Settings::values.upright_screen) { UpdateMinimumWindowSize(min_size);
UpdateMinimumWindowSize(min_height, min_width);
} else {
UpdateMinimumWindowSize(min_width, min_height);
}
} }
NotifyFramebufferLayoutChanged(layout); NotifyFramebufferLayoutChanged(layout);
} }

View File

@ -216,9 +216,9 @@ private:
*/ */
std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y) const; std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y) const;
void UpdateMinimumWindowSize(unsigned int min_width, unsigned int min_height) { void UpdateMinimumWindowSize(std::pair<unsigned, unsigned> min_size) {
WindowConfig new_config = config; WindowConfig new_config = config;
new_config.min_client_area_size = std::make_pair(min_width, min_height); new_config.min_client_area_size = min_size;
SetConfig(new_config); SetConfig(new_config);
ProcessConfigurationChanges(); ProcessConfigurationChanges();
} }

View File

@ -363,4 +363,36 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale) {
return layout; return layout;
} }
std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
bool upright_screen) {
unsigned min_width, min_height;
switch (layout) {
case Settings::LayoutOption::SingleScreen:
min_width = Settings::values.swap_screen ? Core::kScreenBottomWidth : Core::kScreenTopWidth;
min_height = Core::kScreenBottomHeight;
break;
case Settings::LayoutOption::LargeScreen:
min_width = Settings::values.swap_screen
? Core::kScreenTopWidth / 4 + Core::kScreenBottomWidth
: Core::kScreenTopWidth + Core::kScreenBottomWidth / 4;
min_height = Core::kScreenBottomHeight;
break;
case Settings::LayoutOption::SideScreen:
min_width = Core::kScreenTopWidth + Core::kScreenBottomWidth;
min_height = Core::kScreenBottomHeight;
break;
case Settings::LayoutOption::Default:
default:
min_width = Core::kScreenTopWidth;
min_height = Core::kScreenTopHeight + Core::kScreenBottomHeight;
break;
}
if (upright_screen) {
return std::make_pair(min_height, min_width);
} else {
return std::make_pair(min_width, min_height);
}
}
} // namespace Layout } // namespace Layout

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include "common/math_util.h" #include "common/math_util.h"
#include "core/settings.h"
namespace Layout { namespace Layout {
@ -80,4 +81,7 @@ FramebufferLayout CustomFrameLayout(u32 width, u32 height);
*/ */
FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale); FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale);
std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
bool upright_screen);
} // namespace Layout } // namespace Layout