Saltar al contenido
CrossFly es 100% open sourceSíguenos en GitHub
CrossFlyCrossFly
Empezar
Todos los ejemplos
RecetasNavegaciónSuperposiciones71 líneas · 1 archivos

Bottom sheet with a fixed footer

BottomSheet already gives you the header, the grabber, the close button and a footer that floats over the scroll. You only fill body().

Qué muestra esto

A bottom sheet with a header and a footer that stay put while the middle scrolls.

Ejecutarlo en tu máquina

Cada ejemplo es una Window normal, así que el lanzador solo necesita su nombre.

gradlew lwjgl3:run --args="classname dev.cf.recipe.R04Sheet"
Editarlo

Java se compila antes de ejecutarse, así que el navegador no puede reconstruir una edición por su cuenta: el código que ves aquí se convirtió en JavaScript con TeaVM antes de publicarse. Copia el archivo a un proyecto y funciona sin cambios en las cuatro plataformas; el comando de arriba es toda la preparación.

Ejecutándose aquíCrossFly 0.1.32
Iniciando la aplicación…

Compilado a JavaScript por TeaVM: es el mismo código, no un vídeo de él. · Todos los ejemplos

Qué usa

Tipos del framework que toca este ejemplo. Los enlazados tienen página de referencia.

BottomSheetButtonComponentDebugGridLayoutStylesWidgets

El código

Completo, sin recortes. Es el archivo, no un fragmento.

Crudo
dev/cf/recipe/R04Sheet.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 static dev.crossfly.ui.Widgets.*;

/**
 * A bottom sheet with a header and a footer that stay put while the middle scrolls.
 */
public class R04Sheet extends Recipe
{
   public String title()
   {
      return "Bottom sheet with a fixed footer";
   }

   public String note()
   {
      return "BottomSheet already gives you the header, the grabber, the close button and a footer"
         + " that floats over the scroll. You only fill body().";
   }

   public void build(Component body) throws Exception
   {
      Button abrir = Tones.action("Open the sheet");
      abrir.testTag("recipe.open");
      abrir.onAction(c -> abrirSheet());
      body.add(LAY_AUTO, abrir);
   }

   private void abrirSheet()
   {
      try
      {
         // The kicker is the small upper-case label above the title.
         final BottomSheet sheet = new BottomSheet("FILTER", "Choose a segment");
         sheet.maxHeightRatio(.7f);

         for (int i = 1; i <= 20; i++)
         {
            // A tonal pill per segment: twenty identical grey lines is a list nobody can aim at.
            Component linha = new Component();
            linha.setLayout(new GridLayout(Position.START, Position.CENTER));
            linha.add(LAY_AUTO, LAY_AUTO, Tones.tile(0xE574, Tones.cycle(i)),
               outgap(label("Segment " + i, 1f, false, Styles.textColor, Position.START),
                  .6f, 0, 0, 0));
            sheet.body()
               .add(LAY_AUTO, outgap(linha, 0, .3f, 0, .3f));
         }

         // The footer does NOT go into the body: it floats over the scroll and stays reachable with
         // the list at its end — which is why it has an API of its own.
         Button aplicar = Tones.action("Apply");
         aplicar.onAction(c -> sheet.hide());
         sheet.footer(aplicar);

         sheet.show();
      }
      catch (Exception e)
      {
         dev.crossfly.util.Debug.handle(e);
      }
   }
}
Para una IA

Versiones de esta página legibles por máquina, para que un modelo lea el estante en vez de adivinar la API.

Este ejemplo, en JSONEste ejemplo, en Markdown
AnteriorSwitching skinsSiguienteListing: cards or table