More font crap. fixing getField typo.

master
Dustin Swan 3 days ago
parent c0a8d29119
commit 414fc5d79c
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -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
};

@ -114,7 +114,6 @@ os =
}, },
# title # title
# ui.positioned { x = 8, y = 8, child = ui.text { content = window.title, color = "white" } },
ui.positioned { x = 8, y = 8, child = renderText { content = window.title, color = "white" } }, ui.positioned { x = 8, y = 8, child = renderText { content = window.title, color = "white" } },
] ]
} }
@ -194,7 +193,7 @@ os =
| Value v \ (hasField "view" v | Value v \ (hasField "view" v
| True \ openOrFocus input v.view (appWidth v) | True \ openOrFocus input v.view (appWidth v)
| False \ (getSource input == "" | False \ (getSource input == ""
| True \ openOrFocus input (_ \ ui.text { content = show v, color = "white" }) dw | True \ openOrFocus input (_ \ renderText { content = show v, color = "white" }) dw
| False \ ( | False \ (
app = inspector { name = input }; app = inspector { name = input };
openOrFocus input app.view (appWidth app)))) openOrFocus input app.view (appWidth app))))

@ -96,7 +96,7 @@ export const _rt = {
hasField: (field: string) => (obj: any) => ({ hasField: (field: string) => (obj: any) => ({
_tag: (typeof obj === 'object' && obj !== null && field in obj) ? 'True' : 'False' _tag: (typeof obj === 'object' && obj !== null && field in obj) ? 'True' : 'False'
}), }),
getfield: (field: string) => (obj: any) => obj[field] !== undefined getField: (field: string) => (obj: any) => obj[field] !== undefined
? { _tag: 'Some', _0: obj[field] } ? { _tag: 'Some', _0: obj[field] }
: { _tag: 'None' }, : { _tag: 'None' },
entries: (obj: any) => Object.entries(obj).map(([k, v]) => ({ key: k, value: v })), entries: (obj: any) => Object.entries(obj).map(([k, v]) => ({ key: k, value: v })),

Loading…
Cancel
Save