Skip to content

Commit 2f68f5b

Browse files
committed
testing max width
1 parent 31d6b79 commit 2f68f5b

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/tui/App.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<script setup lang="ts">
2+
import { Boxes } from 'cli-boxes'
23
import { TuiBox as Box } from 'vue-termui'
34
45
const n = ref(0)
6+
const styles: Array<keyof Boxes> = [
7+
'arrow',
8+
'bold',
9+
'classic',
10+
'double',
11+
'doubleSingle',
12+
'round',
13+
'single',
14+
'singleDouble',
15+
]
516
onMounted(() => {
617
setInterval(() => {
718
n.value++
@@ -10,8 +21,15 @@ onMounted(() => {
1021
</script>
1122

1223
<template>
13-
<Box align-items="flex-end" justify="center" width="80" height="50">
14-
<span color="red"
24+
<Box
25+
:borderStyle="styles[n % styles.length]"
26+
:marginX="0"
27+
:paddingX="1"
28+
width="100%"
29+
:maxWidth="80"
30+
color="red"
31+
>
32+
<span
1533
>Counter: <span bold>{{ n }}</span
1634
>.
1735
<br />
@@ -21,8 +39,8 @@ onMounted(() => {
2139
{{ n % 2 == 0 ? 'No' : 'Yes' }}
2240
</span>
2341
</span>
24-
<!-- <br /> -->
25-
<!-- <Span inverse color="yellow">Hello</Span> -->
42+
<br />
43+
<Span color="yellow">Current style: {{ styles[n % styles.length] }}</Span>
2644
</span>
2745
</Box>
2846
</template>

src/tui/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import App from './App.vue'
2+
// import App from './demos/Borders.vue'
23
import { createApp } from 'vue-termui'
34

45
await createApp(App).mount()

src/tui/renderer/styles.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ export interface Styles {
127127
*/
128128
readonly minHeight?: number | string
129129

130+
/**
131+
* Sets a maximum width of the element.
132+
*/
133+
readonly maxWidth?: number | string
134+
135+
/**
136+
* Sets a maximum height of the element.
137+
*/
138+
readonly maxHeight?: number | string
139+
130140
/**
131141
* Set this property to `none` to hide the element.
132142
*/
@@ -294,6 +304,7 @@ const applyDimensionStyles = (node: YogaNode, style: Styles): void => {
294304
if ('width' in style) {
295305
if (typeof style.width === 'number') {
296306
node.setWidth(style.width)
307+
// TODO: handle strings with endsWith %
297308
} else if (typeof style.width === 'string') {
298309
node.setWidthPercent(Number.parseInt(style.width, 10))
299310
} else {
@@ -326,6 +337,15 @@ const applyDimensionStyles = (node: YogaNode, style: Styles): void => {
326337
node.setMinHeight(style.minHeight ?? 0)
327338
}
328339
}
340+
341+
if ('maxWidth' in style) {
342+
const { maxWidth } = style
343+
if (typeof maxWidth === 'string' && maxWidth.endsWith('%')) {
344+
node.setMaxHeightPercent(Number.parseInt(maxWidth, 10))
345+
} else {
346+
node.setMaxWidth(maxWidth ?? 0)
347+
}
348+
}
329349
}
330350

331351
const applyDisplayStyles = (node: YogaNode, style: Styles): void => {

0 commit comments

Comments
 (0)