forked from revery-ui/revery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextExample.re
146 lines (136 loc) · 4.1 KB
/
TextExample.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
open Revery;
open Revery.UI;
open Revery.UI.Components;
let containerStyle =
Style.[
position(`Absolute),
top(0),
bottom(0),
left(0),
right(0),
alignItems(`Center),
justifyContent(`SpaceAround),
flexDirection(`Column),
];
let slidersViewStyle = Style.[height(300)];
let textStyle =
Style.[
color(Colors.white),
width(100),
fontFamily("Roboto-Regular.ttf"),
fontSize(16),
margin(14),
textWrap(TextWrapping.NoWrap),
];
let controlsStyle =
Style.[
margin(10),
flexDirection(`Row),
justifyContent(`Center),
alignItems(`Center),
];
let overflowStyles = (style, textFontSize, textWidth) =>
Style.[
color(Colors.white),
fontFamily("Roboto-Regular.ttf"),
fontSize(textFontSize),
width(textWidth),
textOverflow(style),
lineHeight(1.5),
border(~color=Colors.blueViolet, ~width=1),
backgroundColor(Colors.black),
];
module SampleText = {
let component = React.component("Example");
let createElement = (~children as _, ()) =>
component(hooks => {
let (fontSizeSliderVal, setFontSize, hooks) = Hooks.state(20., hooks);
let (widthSliderVal, setWidth, hooks) = Hooks.state(200., hooks);
let (gammaVal, setGamma, hooks) = Hooks.state(2.2, hooks);
let textContent = "All work and no play makes Jack a dull boy";
let maxFontSize = 40.;
let maxWidth = 400.;
let textFontSize = int_of_float(fontSizeSliderVal);
let textWidth = int_of_float(widthSliderVal);
(
hooks,
<View style=containerStyle>
<View>
<View style=Style.[height(40), marginBottom(8)]>
<Text
style={overflowStyles(`Ellipsis, textFontSize, textWidth)}
gamma=gammaVal
text={textContent ++ " " ++ textContent}
/>
</View>
<View style=Style.[height(40), marginBottom(8)]>
<Text
style={overflowStyles(
`UserDefined("£"),
textFontSize,
textWidth,
)}
gamma=gammaVal
text={textContent ++ " " ++ textContent}
/>
</View>
<View style=Style.[height(80)]>
<Text
style=Style.[
color(Colors.white),
fontFamily("Roboto-Regular.ttf"),
fontSize(textFontSize),
lineHeight(1.5),
textWrap(TextWrapping.WhitespaceWrap),
width(int_of_float(widthSliderVal)),
border(~color=Colors.blueViolet, ~width=1),
backgroundColor(Colors.black),
]
text=textContent
/>
</View>
</View>
<View>
<View style=controlsStyle>
<Text style=textStyle text="Font size: " />
<Slider
onValueChanged=setFontSize
value=fontSizeSliderVal
maximumValue=maxFontSize
/>
<Text
style=textStyle
text={"Value: " ++ (fontSizeSliderVal |> string_of_float)}
/>
</View>
<View style=controlsStyle>
<Text style=textStyle text="Width: " />
<Slider
onValueChanged=setWidth
value=widthSliderVal
maximumValue=maxWidth
/>
<Text
style=textStyle
text={"Value: " ++ (widthSliderVal |> string_of_float)}
/>
</View>
<View style=controlsStyle>
<Text style=textStyle text="Gamma:" />
<Slider
onValueChanged=setGamma
value=gammaVal
minimumValue=1.0
maximumValue=3.0
/>
<Text
style=textStyle
text={"Value: " ++ (gammaVal |> string_of_float)}
/>
</View>
</View>
</View>,
);
});
};
let render = () => <SampleText />;