KScript 문서
KO

언어

영어에서 자동 번역되었습니다. 원문은 영어입니다.

데스크톱 앱

입력

bind: $name는 TextBox, CheckBox, Select 또는 Slider를 상태 변수에 연결해요. 사용자가 입력을 바꾸면 변수가 바뀌고 창이 다시 그려져요. on_change에서 $event.value는 새 값을 담아요:

<KScript.Window title="Settings">
  <let name="name" value="''" />
  <let name="dark" value="false" />
  <let name="size" value="14" />
  <let name="theme" value="'teal'" />

  <Column gap="8">
    <TextBox bind="$name" placeholder="Your name" />
    <CheckBox bind="$dark">Dark mode</CheckBox>
    <Slider bind="$size" min="10" max="24" step="1" />
    <Select bind="$theme" options="['teal', 'orange', 'purple']" />
  </Column>
</KScript.Window>
import KScript.UI

Window(title: 'Settings') {
  $name = ''
  $dark = false
  $size = 14
  $theme = 'teal'

  Column(gap: 8) {
    TextBox(bind: $name, placeholder: 'Your name')
    CheckBox(bind: $dark) "Dark mode"
    Slider(bind: $size, min: 10, max: 24, step: 1)
    Select(bind: $theme, options: ['teal', 'orange', 'purple'])
  }
}

Select는 options를 목록, { label, value } 맵의 목록, 또는 레이블에서 값으로 가는 맵으로 받아요.

A TextBox takes the same binding options as @bind on a page. on: is input (as you type, the default), change or blur (when focus leaves or Enter is pressed). trim: true trims spaces, and as: (string, int, number or bool) reads the value as that type and shows an error for one that isn't:

<KScript.Window title="Age">
  <let name="age" value="0" />

  <TextBox bind="$age" on="blur" trim="true" as="int" />
  <Text>Next year you'll be {$age + 1}</Text>
</KScript.Window>
import KScript.UI

Window(title: 'Age') {
  $age = 0

  TextBox(bind: $age, on: blur, trim: true, as: int)
  Text "Next year you'll be {$age + 1}"
}

multiline: true은 TextBox가 여러 줄을 담을 수 있게 하고, Enter 키를 누르면 on_enter가 실행돼요.

Edit this page on GitHub