跳到内容
CrossFly 是 100% 开源在 GitHub 关注我们
CrossFlyCrossFly
开始使用
全部示例
配方列表65 行 · 1 个文件

Reordering a list

The first row has no up arrow and the last has no down arrow — hidden, not removed, so the column does not jitter as rows move.

它展示了什么

A list whose order is the data: move rows, drop rows, read the order back.

在你的机器上运行

每个示例都是普通的 Window,启动器只需要它的名字。

gradlew lwjgl3:run --args="classname dev.cf.recipe.R08Reorder"
修改它

Java 是提前编译的,浏览器无法自行重建你的修改 —— 这里的代码在发布前已由 TeaVM 转成 JavaScript。把文件复制到项目里,它在四个平台上原样运行;上面那条命令就是全部准备工作。

正在此处运行CrossFly 0.1.32
正在启动应用…

由 TeaVM 编译为 JavaScript —— 是同一份代码,不是录像。 · 全部示例

它用到了什么

本示例触及的框架类型。带链接的有参考页。

ComponentGridLayoutLabelReorderableListScreenStylesUtilsWidgets

源码

完整无删减。这就是那个文件,不是片段。

原始
dev/cf/recipe/R08Reorder.java
package dev.cf.recipe;

import dev.cf.Tones;

import dev.crossfly.ui.*;
import dev.crossfly.ui.color.*;
import dev.crossfly.ui.graphics.*;
import dev.crossfly.ui.layout.*;
import dev.crossfly.ui.style.*;
import java.util.*;

import static dev.crossfly.ui.Widgets.*;

/**
 * A list whose order is the data: move rows, drop rows, read the order back.
 */
public class R08Reorder extends Recipe
{
   private ReorderableList lista;
   private Label ordem;

   public String title()
   {
      return "Reordering a list";
   }

   public String note()
   {
      return "The first row has no up arrow and the last has no down arrow — hidden, not removed,"
         + " so the column does not jitter as rows move.";
   }

   public void build(Component body) throws Exception
   {
      ordem = label("", 1.1f, true, Tones.accent(), Position.START);
      ordem.testTag("recipe.order");

      lista = new ReorderableList()
         .items(new ArrayList<>(Arrays.asList("Name", "City", "Phone", "E-mail")))
         .renderer((i, key) ->
         {
            Component linha = new Component();
            linha.setLayout(new GridLayout(Position.START, Position.CENTER));
            linha.add(LAY_AUTO, LAY_AUTO, Tones.tile(key.substring(0, 1), Tones.cycle(i)),
               outgap(label(key, 1.2f, true, Styles.textColor, Position.START), .6f, 0, 0, 0));
            return linha;
         })
         // Fires AFTER the list is consistent, so it is safe to save straight from here.
         .onChange(this::mostrar);
      lista.testTag("recipe.list");

      body.add(LAY_AUTO, lista);
      body.add(LAY_AUTO, outgap(ordem, 0, 1f, 0, 0));
      mostrar();
   }

   private void mostrar()
   {
      ordem.setText(lista.items()
         .isEmpty() ? "(empty)" : dev.crossfly.util.Utils.join(" > ", lista.items()));
      ordem.setValidLayout(false);
      Screen.repaint();
   }
}
给 AI 助手

本页的机器可读版本,让模型直接读取示例集,而不是猜测 API。

本示例(JSON)本示例(Markdown)
上一个Picking a date range下一个Making a screen testable