Skip to content

Commit

Permalink
feat: Align method
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Aug 1, 2022
1 parent 65c378a commit 29c03ca
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
6 changes: 6 additions & 0 deletions main.go
Expand Up @@ -147,3 +147,9 @@ func Width(text *C.char) int {
func Height(text *C.char) int {
return lipgloss.Height(str(text))
}

//export Align
func Align(fieldPtr *C.char, position float64) {
style := m[str(fieldPtr)]
style.Align(lipgloss.Position(position))
}
26 changes: 9 additions & 17 deletions playground.ts
Expand Up @@ -6,28 +6,20 @@ const style = blipgloss.NewStyle()
.Bold(true)
.Foreground("#FAFAFA")
.Background("#7D56F4")
.PaddingTop(2)
.PaddingBottom(2)
.PaddingLeft(4)
.Width(20)
// .PaddingTop(2)
// .PaddingBottom(2)
// .PaddingLeft(4)
.Width(30)
.Align(blipgloss.Position.Right)

console.log(style.Render("Hello, bun."))
// console.log(style.Render("Hello, bun."))

const style2 = style.Copy()
.Background({
Light: "#2B2D42",
Dark: "#F8F32B"
})
.Width(30)

console.log(style2.Render("Hello, bun clone."))

const test = blipgloss.JoinHorizontal(
blipgloss.Position.Top,
style.Render("Hello, bunz."),
style2.Render("Hello, bun clonez.")
)

console.log(blipgloss.Width(style2.Render("Hello, bun clone.")))
.Width(20)
.Align(blipgloss.Position.Top)

// style.FreeString()
console.log(style.Render("Hello, bun clone."))
8 changes: 6 additions & 2 deletions src/ffi.ts
Expand Up @@ -58,11 +58,11 @@ export const { symbols } = dlopen(location, {
returns: FFIType.void
},
JoinHorizontal: {
args: [FFIType.float, FFIType.ptr],
args: [FFIType.f64, FFIType.ptr],
returns: FFIType.ptr
},
JoinVertical: {
args: [FFIType.float, FFIType.ptr],
args: [FFIType.f64, FFIType.ptr],
returns: FFIType.ptr
},
Width: {
Expand All @@ -73,6 +73,10 @@ export const { symbols } = dlopen(location, {
args: [FFIType.ptr],
returns: FFIType.int
},
Align: {
args: [FFIType.float],
returns: FFIType.void
},
FreeString: {
args: [FFIType.ptr],
returns: FFIType.void
Expand Down
5 changes: 5 additions & 0 deletions src/lib.ts
Expand Up @@ -181,6 +181,11 @@ export class Style {
return this.SetBooleanValue('Reverse', val)
}

Align(position: Position | number) {
symbols.Align(this.#handle, position)
return this
}

Render(text: string) {
const textPtr = symbols.Render(this.#handle, ptr(encode(text)))
const textStr = new CString(textPtr)
Expand Down

0 comments on commit 29c03ca

Please sign in to comment.