Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/inline-region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function box(msg: string, fg: number, border: number): Op[] {
height: grow(),
direction: "ttb",
padding: { left: 1 },
alignY: 2,
alignY: "center",
},
border: {
color: border,
Expand Down
14 changes: 7 additions & 7 deletions demo/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function key(ops: Op[], k: KeyDef, ctx: AppContext): void {
width: fixed(w),
height: grow(),
padding: { left: 1, right: 1 },
alignX: 2,
alignY: 2,
alignX: "center",
alignY: "center",
},
bg,
border: hover
Expand Down Expand Up @@ -435,8 +435,8 @@ function keyboard(ctx: AppContext): Op[] {
width: grow(),
height: grow(),
direction: "ttb",
alignX: 2,
alignY: 2,
alignX: "center",
alignY: "center",
padding: { left: 2, top: 1 },
},
}),
Expand All @@ -453,7 +453,7 @@ function keyboard(ctx: AppContext): Op[] {
layout: {
width: grow(),
direction: "ltr",
alignY: 0,
alignY: "top",
padding: { bottom: 1 },
},
}),
Expand Down Expand Up @@ -504,7 +504,7 @@ function keyboard(ctx: AppContext): Op[] {

// config panel (right)
ops.push(
open("", { layout: { width: grow(), direction: "ltr", alignX: 1 } }),
open("", { layout: { width: grow(), direction: "ltr", alignX: "right" } }),
);
configPanel(ops, ctx);
ops.push(close());
Expand All @@ -518,7 +518,7 @@ function keyboard(ctx: AppContext): Op[] {
layout: {
direction: "ltr",
gap: 3,
alignY: 1,
alignY: "bottom",
padding: { left: 1, right: 1, top: 1, bottom: 1 },
},
border: { color: kbColor, left: 1, right: 1, top: 1, bottom: 1 },
Expand Down
14 changes: 11 additions & 3 deletions ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ export function pack(
);
o += 4;

view.setUint32(o, (l.alignX ?? 0) | ((l.alignY ?? 0) << 8), true);
let alignX = l.alignX === "right" ? 1 : l.alignX === "center" ? 2 : 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, think we might benefit from a more generalized approach to string > enum conversion? like a typed resolveInt(property, value) util?


let alignY = l.alignY === "bottom"
? 1
: l.alignY === "center"
? 2
: 0;

view.setUint32(o, alignX | (alignY << 8), true);
o += 4;
}

Expand Down Expand Up @@ -248,8 +256,8 @@ export interface OpenElement {
padding?: { left?: number; right?: number; top?: number; bottom?: number };
gap?: number;
direction?: "ltr" | "ttb";
alignX?: number;
alignY?: number;
alignX?: "left" | "center" | "right";
alignY?: "top" | "center" | "bottom";
};
bg?: number;
cornerRadius?: { tl?: number; tr?: number; bl?: number; br?: number };
Expand Down
16 changes: 14 additions & 2 deletions validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,20 @@ const Layout = Type.Object({
direction: Type.Optional(
Type.Union([Type.Literal("ltr"), Type.Literal("ttb")]),
),
alignX: Type.Optional(u8),
alignY: Type.Optional(u8),
alignX: Type.Optional(
Type.Union([
Type.Literal("left"),
Type.Literal("center"),
Type.Literal("right"),
]),
),
alignY: Type.Optional(
Type.Union([
Type.Literal("top"),
Type.Literal("center"),
Type.Literal("bottom"),
]),
),
});

const CornerRadius = Type.Object({
Expand Down
Loading