KScript ドキュメント
JA

言語

英語から自動翻訳されています。原文は英語です。

デスクトップアプリ

入力

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が実行されます。