Skip to content

Commit

Permalink
feat: support for disabling scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-fu committed Nov 24, 2023
1 parent b780eb7 commit c31fffe
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/src/screen_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class ScreenUtil {
static const Size defaultSize = Size(360, 690);
static ScreenUtil _instance = ScreenUtil._();

static bool Function() _enableScaleWH = () => true;
static bool Function() _enableScaleText = () => true;


/// UI设计中手机尺寸 , dp
/// Size of the phone in UI Design , dp
late Size _uiSize;
Expand All @@ -31,6 +35,16 @@ class ScreenUtil {

factory ScreenUtil() => _instance;

/// Enable scale
///
/// if the enableWH return false, the width and the height scale ratio will be 1
/// if the enableText return false, the text scale ratio will be 1
///
static void enableScale({bool Function()? enableWH, bool Function()? enableText}) {
_enableScaleWH = enableWH ?? () => true;
_enableScaleText = enableText ?? () => true;
}

/// Manually wait for window size to be initialized
///
/// `Recommended` to use before you need access window size
Expand Down Expand Up @@ -197,15 +211,15 @@ class ScreenUtil {

/// 实际尺寸与UI设计的比例
/// The ratio of actual width to UI design
double get scaleWidth => screenWidth / _uiSize.width;
double get scaleWidth => !_enableScaleWH() ? 1 : screenWidth / _uiSize.width;

/// The ratio of actual height to UI design
double get scaleHeight =>
(_splitScreenMode ? max(screenHeight, 700) : screenHeight) /
!_enableScaleWH() ? 1 : (_splitScreenMode ? max(screenHeight, 700) : screenHeight) /
_uiSize.height;

double get scaleText =>
_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth;
!_enableScaleText() ? 1 : (_minTextAdapt ? min(scaleWidth, scaleHeight) : scaleWidth);

/// 根据UI设计的设备宽度适配
/// 高度也可以根据这个来做适配可以保证不变形,比如你想要一个正方形的时候.
Expand Down

0 comments on commit c31fffe

Please sign in to comment.