glyphView. fontEditor. a few more host functions

master
Dustin Swan 5 days ago
parent cc33b9a015
commit a874101a3d
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -247,3 +247,17 @@ textInput = config \
}
}
};
glyphView = config \
defaults = { scale = 1, color = "#fff" };
c = { ...defaults, ...config };
_ = debug! "glyphView" c;
ui.stack {
children = map (pixel \
ui.positioned {
x = pixel.x * c.scale,
y = pixel.y * c.scale,
child = ui.rect { w = c.scale, h = c.scale, color = c.color }
}
) c.glyph.map
};

@ -1,8 +1,17 @@
fontEditor = config \
defaults = { };
defaults = {
path = "newFont"
};
c = { ...defaults, ...config };
size \ ui.stateful {
_ = debug! "here" c.path;
existing = eval! (c.path);
_ = debug! "here2" existing;
# return app
{
view = size \ ui.stateful {
focusable = True,
autoFocus = True,
@ -10,20 +19,12 @@ fontEditor = config \
init = existing
| Value v \ {
map = v.map,
pixelWidth = 5,
pixelHeight = 7,
cellSize = 30,
selectedRow = 0,
selectedCol = 0
glyphs = v.glyphs,
height = v.height
}
| _ \ {
map = [],
pixelWidth = 5,
pixelHeight = 7,
cellSize = 30,
selectedRow = 0,
selectedCol = 0
glyphs = [],
height = 7
},
update = state event \ event
@ -40,10 +41,6 @@ fontEditor = config \
| Key { key = "ArrowRight" } \ rightArrow state
| Key { key = "l" } \ rightArrow state
| UpdateWidth w \ (
newState = state.{ pixelWidth = (int w) };
{ state = newState, emit = saveGlyph newState })
| UpdateHeight h \ (
newState = state.{ pixelHeight = (int h) };
{ state = newState, emit = saveGlyph newState })
@ -51,5 +48,24 @@ fontEditor = config \
| _ \ { state = state, emit = [] },
view = state emit \
ui.text { content = "testing" }
tileSize = 50;
tileView = g \
glyph = g.value;
scale = max 1 (floor (min (tileSize / glyph.w) (tileSize / glyph.h)) - 2);
_ = debug! "scael" scale;
ui.clickable {
child = ui.stack {
children = [
ui.rect { w = tileSize, h = tileSize, strokeWidth = 1, strokeColor = "#fff" },
glyphView { glyph = glyph, scale = scale }
]
}
};
ui.column {
gap = 2,
children = map tileView (entries state.glyphs)
}
}
};

@ -35,7 +35,6 @@ pixelEditor = config \
newState = state.{ map = newMap };
{ state = newState, emit = saveGlyph newState });
_ = debug! "c.path" c.path;
existing = eval! (c.path);
_ = debug! "existing" existing;

@ -20,6 +20,8 @@ export const _rt = {
cat: (a: any) => (b: any) => Array.isArray(a) ? [...a, ...b] : a + b,
max: (a: number) => (b: number) => Math.max(a, b),
min: (a: number) => (b: number) => Math.min(a, b),
floor: (a: number) => Math.floor(a),
ceiling: (a: number) => Math.ceil(a),
eq: (a: any) => (b: any) => ({ _tag: deepEqual(a, b) ? 'True' : 'False' }),
neq: (a: any) => (b: any) => ({ _tag: deepEqual(a, b) ? 'False' : 'True' }),
@ -94,6 +96,11 @@ export const _rt = {
hasField: (field: string) => (obj: any) => ({
_tag: (typeof obj === 'object' && obj !== null && field in obj) ? 'True' : 'False'
}),
getfield: (field: string) => (obj: any) => obj[field] !== undefined
? { _tag: 'Some', _0: obj[field] }
: { _tag: 'None' },
entries: (obj: any) => Object.entries(obj).map(([k, v]) => ({ key: k, value: v })),
keys: (obj: any) => Object.keys(obj),
isFunction: (v: any) => ({ _tag: typeof v === 'function' ? 'True' : 'False' }),
storeSearch: (query: string) => {
return Object.keys(store)
@ -228,6 +235,9 @@ export const _rt = {
const compiled = compile(defs[0].body);
const fn = new Function('_rt', 'store', `return ${compiled}`);
const result = fn(_rt, store);
if (result === undefined) {
return { _tag: 'None' };
}
return { _tag: 'Value', _0: result };
} catch (e: any) {
return { _tag: 'Err', _0: e.message };

Loading…
Cancel
Save