문제
JMP에서 사용자 인터페이스를 생성할 때 일부 배경색 또는 전경색을 디스플레이에 추가할 수 있습니다. 그러나 macOS 다크 모드 및 Windows 고대비 모드에 대한 JMP 15의 새로운 지원으로 콘텐츠를 읽을 수 있도록 사용자가 어두운 모드인지 밝은 모드인지 감지할 수 있는 방법이 필요합니다. 예를 들어 밝은 색을 배경색으로 설정하거나 어두운 모드에서 전경색을 어둡게 설정하면 읽기 어렵습니다.
해결책
사용자가 어두운 모드인지 밝은 모드인지 감지하기 위해 배경색 기본 설정을 확인할 수 있습니다. 배경색의 휘도를 계산하면 일반적으로 현재 OS가 어두운 모양 모드에서 실행되고 있는지 파악할 수 있습니다.
/* Function: getCurrentAppearance
Returns the current appearance based on the background
color for reports, either 'Light' or 'Dark'.
*/
getCurrentAppearance = Function({},
{backgroundColor, hue, luminance, saturation},
backgroundColor = Arg( Arg( Get Preference( BackgroundColor ), 1 ), 1 );
{hue, luminance, saturation} = Color To HLS( backgroundColor );
If( luminance < 0.5, "Dark", "Light" );
);
실제로 스크립트의 시작 부분에서 이 함수를 호출(또는 매번 호출)하고 필요할 때 사용할 수 있습니다.
isLightMode = getCurrentAppearance() == "Light";
New Window("Appearance Mode",
Text Box("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
<<BACKGROUND color=""></BACKGROUND>