|
|
|
@ -14,11 +14,13 @@ center = parentW parentH child \
|
|
|
|
|
|
|
|
|
|
|
|
# button : Record -> ui
|
|
|
|
# button : Record -> ui
|
|
|
|
button = config \
|
|
|
|
button = config \
|
|
|
|
textSize = ui.measureText config.label;
|
|
|
|
label = renderText { content = config.label };
|
|
|
|
|
|
|
|
labelSize = ui.measure label;
|
|
|
|
|
|
|
|
labelWidth = labelSize.width;
|
|
|
|
|
|
|
|
|
|
|
|
defaults = {
|
|
|
|
defaults = {
|
|
|
|
h = 30,
|
|
|
|
h = 30,
|
|
|
|
w = textSize + 20,
|
|
|
|
w = labelWidth + 20,
|
|
|
|
strokeWidth = 1,
|
|
|
|
strokeWidth = 1,
|
|
|
|
strokeColor = "#fff",
|
|
|
|
strokeColor = "#fff",
|
|
|
|
textColor = "#fff",
|
|
|
|
textColor = "#fff",
|
|
|
|
@ -204,7 +206,8 @@ textInput = config \
|
|
|
|
|
|
|
|
|
|
|
|
calcScrollOffset = text cursorPos scrollOffset inputWidth \
|
|
|
|
calcScrollOffset = text cursorPos scrollOffset inputWidth \
|
|
|
|
textBeforeCursor = slice text 0 cursorPos;
|
|
|
|
textBeforeCursor = slice text 0 cursorPos;
|
|
|
|
cursorX = ui.measureText textBeforeCursor;
|
|
|
|
# cursorX = ui.measureText textBeforeCursor;
|
|
|
|
|
|
|
|
cursorX = (measureText { content = textBeforeCursor, scale = 2 }).width;
|
|
|
|
(cursorX < scrollOffset
|
|
|
|
(cursorX < scrollOffset
|
|
|
|
| True \ max 0 (cursorX - 20)
|
|
|
|
| True \ max 0 (cursorX - 20)
|
|
|
|
| False \
|
|
|
|
| False \
|
|
|
|
@ -216,8 +219,10 @@ textInput = config \
|
|
|
|
(index >= len text)
|
|
|
|
(index >= len text)
|
|
|
|
| True \ len text
|
|
|
|
| True \ len text
|
|
|
|
| False \ (
|
|
|
|
| False \ (
|
|
|
|
widthSoFar = ui.measureText (slice text 0 index);
|
|
|
|
# widthSoFar = ui.measureText (slice text 0 index);
|
|
|
|
widthNext = ui.measureText (slice text 0 (index + 1));
|
|
|
|
widthSoFar = (measureText { content = (slice text 0 index), scale = 2 }).width;
|
|
|
|
|
|
|
|
# widthNext = ui.measureText (slice text 0 (index + 1));
|
|
|
|
|
|
|
|
widthNext = (measureText { content = (slice text 0 (index + 1)), scale = 2 }).width;
|
|
|
|
midpoint = (widthSoFar + widthNext) / 2;
|
|
|
|
midpoint = (widthSoFar + widthNext) / 2;
|
|
|
|
(targetX < midpoint
|
|
|
|
(targetX < midpoint
|
|
|
|
| True \ index
|
|
|
|
| True \ index
|
|
|
|
@ -294,7 +299,8 @@ textInput = config \
|
|
|
|
text = (hasField "value" c | True \ c.value | False \ state.text);
|
|
|
|
text = (hasField "value" c | True \ c.value | False \ state.text);
|
|
|
|
cursorPos = (text == state.text | True \ state.cursorPos | False \ len text);
|
|
|
|
cursorPos = (text == state.text | True \ state.cursorPos | False \ len text);
|
|
|
|
textBeforeCursor = slice text 0 cursorPos;
|
|
|
|
textBeforeCursor = slice text 0 cursorPos;
|
|
|
|
cursorX = ui.measureText textBeforeCursor;
|
|
|
|
# cursorX = ui.measureText textBeforeCursor;
|
|
|
|
|
|
|
|
cursorX = (measureText { content = textBeforeCursor, scale = 2 }).width;
|
|
|
|
padding = 8;
|
|
|
|
padding = 8;
|
|
|
|
|
|
|
|
|
|
|
|
ui.clip {
|
|
|
|
ui.clip {
|
|
|
|
@ -307,7 +313,8 @@ textInput = config \
|
|
|
|
ui.positioned {
|
|
|
|
ui.positioned {
|
|
|
|
x = 8 - state.scrollOffset,
|
|
|
|
x = 8 - state.scrollOffset,
|
|
|
|
y = 0,
|
|
|
|
y = 0,
|
|
|
|
child = ui.positioned { x = 0, y = 12, child = ui.text { content = text, color = c.color } }
|
|
|
|
# child = ui.positioned { x = 0, y = 12, child = ui.text { content = text, color = c.color } }
|
|
|
|
|
|
|
|
child = ui.positioned { x = 0, y = 12, child = renderText { content = text, color = c.color } }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
(state.focused
|
|
|
|
(state.focused
|
|
|
|
@ -340,25 +347,33 @@ glyphView = config \
|
|
|
|
|
|
|
|
|
|
|
|
# renderText : TextConfig \ UI
|
|
|
|
# renderText : TextConfig \ UI
|
|
|
|
renderText = config \
|
|
|
|
renderText = config \
|
|
|
|
# get these from system theme at some point
|
|
|
|
defaults = { content = "", scale = 2, color = "#fff", font = "myFont2" };
|
|
|
|
defaults = { content = "", scale = 2, color = "#fff" };
|
|
|
|
|
|
|
|
c = { ...defaults, ...config };
|
|
|
|
c = { ...defaults, ...config };
|
|
|
|
|
|
|
|
font = getAt [c.font] | Some f \ f | None \ { glyphs = {} };
|
|
|
|
|
|
|
|
charW = font.charWidth;
|
|
|
|
|
|
|
|
gap = c.scale;
|
|
|
|
chars = split "" c.content;
|
|
|
|
chars = split "" c.content;
|
|
|
|
_ = debug! "chars" chars;
|
|
|
|
|
|
|
|
ui.row {
|
|
|
|
ui.row {
|
|
|
|
children = map (char \
|
|
|
|
children = map (char \
|
|
|
|
# _ = debug! "here. char" char;
|
|
|
|
getField char font.glyphs
|
|
|
|
getAt ["myFontBackup", "glyphs", char]
|
|
|
|
|
|
|
|
| Some g \ glyphView { glyph = g, scale = c.scale }
|
|
|
|
| Some g \ glyphView { glyph = g, scale = c.scale }
|
|
|
|
| None \ ui.rect { w = 0, h = 0 }
|
|
|
|
| None \ ui.rect { w = charW * c.scale, h = 12 * c.scale }
|
|
|
|
) chars,
|
|
|
|
) chars,
|
|
|
|
gap = 4
|
|
|
|
gap = gap
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# fold (acc c \
|
|
|
|
|
|
|
|
# { pos = acc.pos + 8,
|
|
|
|
|
|
|
|
# ui = [...ui, ui.positioned { x }]
|
|
|
|
|
|
|
|
# }) { pos = 0, ui = [] } chars;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# text : String \ UI
|
|
|
|
# text : String \ UI
|
|
|
|
text = content \ renderText { content = content };
|
|
|
|
text = content \ renderText { content = content };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
measureText = config \
|
|
|
|
|
|
|
|
defaults = { content = "", scale = 2, font = "myFont2" };
|
|
|
|
|
|
|
|
c = { ...defaults, ...config };
|
|
|
|
|
|
|
|
font = getAt [c.font] | Some f \ f | None \ { charWidth = 5 };
|
|
|
|
|
|
|
|
charW = font.charWidth;
|
|
|
|
|
|
|
|
gap = c.scale;
|
|
|
|
|
|
|
|
strLen = len config.content;
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
width = strLen * charW * c.scale + max 0 (strLen - 1) * gap,
|
|
|
|
|
|
|
|
height = 12 * c.scale
|
|
|
|
|
|
|
|
};
|
|
|
|
|