Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(environment): macOS version #1030

Merged
merged 4 commits into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Environment: add isX functions for OS's
  • Loading branch information
zbaylin committed Dec 25, 2020
commit e9afcb2ad9157a33986896ccbc479686d663f9fe
21 changes: 21 additions & 0 deletions src/Core/Environment.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 41,27 @@ let osString =
| Unknown => "Unknown"
};

let isMac =
switch (os) {
| Mac(_) => true
| _ => false
};
let isIOS = {
os == IOS;
};
let isWindows = {
os == Windows;
};
let isAndroid = {
os == Android;
};
let isLinux = {
os == Linux;
};
let isBrowser = {
os == Browser;
};

module Internal = {
let addTrailingSlash = dir => {
let len = String.length(dir);
Expand Down
7 changes: 7 additions & 0 deletions src/Core/Environment.rei
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 58,13 @@ type os =
let os: os;
let osString: string;

let isMac: bool;
let isIOS: bool;
let isWindows: bool;
let isAndroid: bool;
let isLinux: bool;
let isBrowser: bool;

/**
[getUserLocale] returns the current user locale. Note that on some platforms
(including macOS) the locale can change during runtime
Expand Down
7 changes: 1 addition & 6 deletions src/UI_Components/Input.re
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 320,6 @@ let%component make =
onKeyDown(event);

let code = event.keycode;
let mac =
switch (Environment.os) {
| Mac(_) => true
| _ => false
};
let super = Sdl2.Keymod.isGuiDown(event.keymod);
let ctrl = Sdl2.Keymod.isControlDown(event.keymod);

Expand All @@ -345,7 340,7 @@ let%component make =
} else if (code == Keycode.escape) {
Focus.loseFocus();
} else if (code == Keycode.v) {
if (mac && super || !mac && ctrl) {
if (Environment.isMac && super || !Environment.isMac && ctrl) {
paste(value, cursorPosition);
};
};
Expand Down
9 changes: 2 additions & 7 deletions src/UI_Components/ScrollView.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 13,6 @@ let empty = React.empty;

let scrollTrackColor = Color.rgba(0.0, 0.0, 0.0, 0.4);
let scrollThumbColor = Color.rgba(0.5, 0.5, 0.5, 0.4);
let isMac =
switch (Environment.os) {
| Mac(_) => true
| _ => false
};

type action =
| ScrollUpdated(int);
Expand Down Expand Up @@ -102,7 97,7 @@ let%component make =
~style,
~scrollLeft=0,
~scrollTop=0,
~bounce=isMac,
~bounce=Environment.isMac,
~children=React.empty,
(),
) => {
Expand Down Expand Up @@ -230,7 225,7 @@ let%component make =

if (horizontalScroll) {
if (isHorizontalScrollBarVisible) {
let horizontalScrollMultiplier = isMac ? (-1.) : 1.;
let horizontalScrollMultiplier = Environment.isMac ? (-1.) : 1.;
handeScroll(
~deltaValue=
abs_float(wheelEvent.deltaX) > 0.
Expand Down