iOS: Fix can't see input widget text in dark mode, implement proper fullscreen support, improve view background switching color to use launcher theme background instead of just blue (Thanks Pear)

This commit is contained in:
UnknownShadow200 2022-06-30 20:51:40 +10:00
parent 7d793da679
commit f2978e2368

View File

@ -15,8 +15,8 @@
#include "Funcs.h" #include "Funcs.h"
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <UIKit/UIPasteboard.h>
#include <UIKit/UIKit.h> #include <UIKit/UIKit.h>
#include <UIKit/UIPasteboard.h>
#include <OpenGLES/ES2/gl.h> #include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h> #include <OpenGLES/ES2/glext.h>
#include <CoreText/CoreText.h> #include <CoreText/CoreText.h>
@ -63,6 +63,12 @@ static UIInterfaceOrientationMask SupportedOrientations(void) {
return UIInterfaceOrientationMaskAll; return UIInterfaceOrientationMaskAll;
} }
static cc_bool fullscreen = true;
static CGRect GetViewFrame(void) {
UIScreen* screen = UIScreen.mainScreen;
return fullscreen ? screen.bounds : screen.applicationFrame;
}
@implementation CCWindow @implementation CCWindow
//- (void)drawRect:(CGRect)dirty { DoDrawFramebuffer(dirty); } //- (void)drawRect:(CGRect)dirty { DoDrawFramebuffer(dirty); }
@ -154,9 +160,9 @@ static UITextField* kb_widget;
} completion:nil]; } completion:nil];
} }
/*- (BOOL)prefersStatusBarHidden { - (BOOL)prefersStatusBarHidden {
return fullscreen;
}*/ }
@end @end
@implementation CCAppDelegate @implementation CCAppDelegate
@ -312,13 +318,20 @@ void Window_Init(void) {
DisplayInfo.ScaleY = 1; // TODO dpi scale DisplayInfo.ScaleY = 1; // TODO dpi scale
} }
static UIColor* CalcBackgroundColor(void) {
// default to purple if no themed background color yet
if (!Launcher_Theme.BackgroundColor)
return UIColor.purpleColor;
return ToUIColor(Launcher_Theme.BackgroundColor, 1.0f);
}
static CGRect DoCreateWindow(void) { static CGRect DoCreateWindow(void) {
CGRect bounds = UIScreen.mainScreen.bounds; CGRect bounds = GetViewFrame();
cc_controller = [CCViewController alloc]; cc_controller = [CCViewController alloc];
win_handle = [[CCWindow alloc] initWithFrame:bounds]; win_handle = [[CCWindow alloc] initWithFrame:bounds];
win_handle.rootViewController = cc_controller; win_handle.rootViewController = cc_controller;
win_handle.backgroundColor = UIColor.blueColor; win_handle.backgroundColor = CalcBackgroundColor();
WindowInfo.Exists = true; WindowInfo.Exists = true;
WindowInfo.Width = bounds.size.width; WindowInfo.Width = bounds.size.width;
WindowInfo.Height = bounds.size.height; WindowInfo.Height = bounds.size.height;
@ -421,9 +434,22 @@ void Window_CloseKeyboard(void) {
[text_input resignFirstResponder]; [text_input resignFirstResponder];
} }
int Window_GetWindowState(void) { return WINDOW_STATE_NORMAL; } int Window_GetWindowState(void) {
cc_result Window_EnterFullscreen(void) { return ERR_NOT_SUPPORTED; } return fullscreen ? WINDOW_STATE_FULLSCREEN : WINDOW_STATE_NORMAL;
cc_result Window_ExitFullscreen(void) { return ERR_NOT_SUPPORTED; } }
static void ToggleFullscreen(cc_bool isFullscreen) {
fullscreen = isFullscreen;
[cc_controller setNeedsStatusBarAppearanceUpdate];
view_handle.frame = GetViewFrame();
}
cc_result Window_EnterFullscreen(void) {
ToggleFullscreen(true); return 0;
}
cc_result Window_ExitFullscreen(void) {
ToggleFullscreen(false); return 0;
}
int Window_IsObscured(void) { return 0; } int Window_IsObscured(void) { return 0; }
void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); } void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); }
@ -670,8 +696,6 @@ void GetDeviceUUID(cc_string* str) {
*-----------------------------------------------------Font handling-------------------------------------------------------* *-----------------------------------------------------Font handling-------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
#ifndef CC_BUILD_FREETYPE #ifndef CC_BUILD_FREETYPE
#include "ExtMath.h"
void interop_GetFontNames(struct StringsBuffer* buffer) { void interop_GetFontNames(struct StringsBuffer* buffer) {
NSArray<NSString*>* families = UIFont.familyNames; NSArray<NSString*>* families = UIFont.familyNames;
NSLog(@"Families: %@", families); NSLog(@"Families: %@", families);
@ -688,6 +712,7 @@ void interop_GetFontNames(struct StringsBuffer* buffer) {
StringsBuffer_Sort(buffer); StringsBuffer_Sort(buffer);
} }
#include "ExtMath.h"
static void InitFont(struct FontDesc* desc, UIFont* font) { static void InitFont(struct FontDesc* desc, UIFont* font) {
desc->handle = CFBridgingRetain(font); desc->handle = CFBridgingRetain(font);
desc->height = Math_Ceil(Math_AbsF(font.ascender) + Math_AbsF(font.descender)); desc->height = Math_Ceil(Math_AbsF(font.ascender) + Math_AbsF(font.descender));
@ -1102,6 +1127,7 @@ static UIView* LBackend_InputShow(struct LInput* w) {
fld.frame = CGRectMake(0, 0, w->_textHeight, LINPUT_HEIGHT); fld.frame = CGRectMake(0, 0, w->_textHeight, LINPUT_HEIGHT);
fld.borderStyle = UITextBorderStyleBezel; fld.borderStyle = UITextBorderStyleBezel;
fld.backgroundColor = UIColor.whiteColor; fld.backgroundColor = UIColor.whiteColor;
fld.textColor = UIColor.blackColor;
fld.delegate = ui_controller; fld.delegate = ui_controller;
[fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged]; [fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];