Skip to content

Commit

Permalink
feat: add PlaceVertical and PlaceHorizontal whitespace methods
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Sep 18, 2023
1 parent b918733 commit 71b0f2f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
28 changes: 28 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,31 @@ func Place(width, height int, hPos, vPos float64, strPtr, whitespaceOptionPtr *C
joined := lipgloss.Place(width, height, lipgloss.Position(hPos), lipgloss.Position(vPos), str(strPtr), convertedOptions...)
return ch(joined)
}

//export PlaceHorizontal
func PlaceHorizontal(width int, pos float64, strPtr, whitespaceOptionPtr *C.char) *C.char {
whitespaceOption := strings.Split(str(whitespaceOptionPtr), ",")
var convertedOptions []lipgloss.WhitespaceOption

// Loop through the array and convert the whitespace options
for _, optionStr := range whitespaceOption {
convertedOptions = append(convertedOptions, whitespaceMap[optionStr])
}

joined := lipgloss.PlaceHorizontal(width, lipgloss.Position(pos), str(strPtr), convertedOptions...)
return ch(joined)
}

//export PlaceVertical
func PlaceVertical(height int, pos float64, strPtr, whitespaceOptionPtr *C.char) *C.char {
whitespaceOption := strings.Split(str(whitespaceOptionPtr), ",")
var convertedOptions []lipgloss.WhitespaceOption

// Loop through the array and convert the whitespace options
for _, optionStr := range whitespaceOption {
convertedOptions = append(convertedOptions, whitespaceMap[optionStr])
}

joined := lipgloss.PlaceVertical(height, lipgloss.Position(pos), str(strPtr), convertedOptions...)
return ch(joined)
}
18 changes: 18 additions & 0 deletions src/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ export const { symbols } = dlopen(location, {
],
returns: FFIType.ptr,
},
PlaceVertical: {
args: [
FFIType.int,
FFIType.f64,
FFIType.ptr,
FFIType.ptr,
],
returns: FFIType.ptr,
},
PlaceHorizontal: {
args: [
FFIType.int,
FFIType.f64,
FFIType.ptr,
FFIType.ptr,
],
returns: FFIType.ptr,
},
SetString: {
args: [FFIType.ptr, FFIType.ptr],
returns: FFIType.void,
Expand Down
32 changes: 32 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,35 @@ export function Place(
);
return getStringAndFreePtr(textPtr);
}

export function PlaceHorizontal(
width: number,
pos: number,
str: string,
...whitespaceOptions: string[]
) {
const combinedOptions = whitespaceOptions.join(',');
const textPtr = symbols.PlaceHorizontal(
width,
pos,
ptr(encode(str)),
ptr(encode(combinedOptions)),
);
return getStringAndFreePtr(textPtr);
}

export function PlaceVertical(
height: number,
pos: number,
str: string,
...whitespaceOptions: string[]
) {
const combinedOptions = whitespaceOptions.join(',');
const textPtr = symbols.PlaceVertical(
height,
pos,
ptr(encode(str)),
ptr(encode(combinedOptions)),
);
return getStringAndFreePtr(textPtr);
}

0 comments on commit 71b0f2f

Please sign in to comment.