forked from onivim/oni2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuItem.re
107 lines (93 loc) · 2.37 KB
/
MenuItem.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
open Revery;
open Revery.UI;
open Oni_Core;
open Oni_Model;
module FontAwesome = Oni_Components.FontAwesome;
module FontIcon = Oni_Components.FontIcon;
module Colors = Feature_Theme.Colors;
module Constants = {
let iconSize = 20.;
};
module Styles = {
let bg = (~isFocused) =>
isFocused ? Colors.List.focusBackground : Colors.Menu.background;
let text = (~theme, ~font: UiFont.t, ~isFocused) =>
Style.[
fontFamily(font.fontFile),
fontSize(font.fontSize),
color(Colors.Menu.foreground.from(theme)),
backgroundColor(bg(~isFocused).from(theme)),
];
let container = (~theme, ~isFocused) =>
Style.[
padding(10),
flexDirection(`Row),
backgroundColor(bg(~isFocused).from(theme)),
];
let icon = fg =>
Style.[
fontFamily("seti.ttf"),
fontSize(Constants.iconSize),
color(fg),
width(int_of_float(Constants.iconSize *. 0.75)),
height(int_of_float(Constants.iconSize *. 0.85)),
textWrap(TextWrapping.NoWrap),
marginRight(10),
];
let label = (~font: UiFont.t, ~theme, ~isFocused, ~custom) =>
Style.(
merge(
~source=
Style.[
fontFamily(font.fontFile),
textOverflow(`Ellipsis),
fontSize(12.),
color(Colors.Menu.foreground.from(theme)),
backgroundColor(bg(~isFocused).from(theme)),
],
~target=custom,
)
);
let clickable = Style.[cursor(Revery.MouseCursors.pointer)];
};
let noop = () => ();
let make =
(
~style=[],
~icon=None,
~font,
~label,
~isFocused,
~theme,
~onClick=noop,
~onMouseOver=noop,
(),
) => {
let iconView =
switch (icon) {
| Some(v) =>
IconTheme.IconDefinition.(
<Text
style={Styles.icon(v.fontColor)}
text={FontIcon.codeToIcon(v.fontCharacter)}
/>
)
| None =>
<Text style={Styles.icon(Revery.Colors.transparentWhite)} text="" />
};
let labelView =
switch (label) {
| `Text(text) =>
let style = Styles.label(~font, ~theme, ~isFocused, ~custom=style);
<Text style text />;
| `Custom(view) => view
};
<Sneakable style=Styles.clickable onClick>
<View
onMouseOver={_ => onMouseOver()}
style={Styles.container(~theme, ~isFocused)}>
iconView
labelView
</View>
</Sneakable>;
};