मुख्य सामग्री पर जाएँ
CrossFly 100% ओपन सोर्सGitHub पर फ़ॉलो करें
CrossFlyCrossFly
शुरू करें
सभी उदाहरण
रेसिपीइनपुट84 पंक्तियाँ · 1 फ़ाइलें

Pickers

show(answer -> …) on all of them, and answer is null when the user backed out. The ones needing hardware live in R21, and the system file picker in R31 — those can be refused.

यह क्या दिखाता है

The pickers, and the callback shape they all share.

Every picker is a Window that answers: show(answer -> …), where answer is null when the user cancelled. One shape for date, time, colour, file, photo, barcode and location — so learning one is learning all of them.

Handle the null. Cancelling is not an error and not an edge case; it is the most common outcome of opening a picker by mistake, and a callback that assumes an answer throws on a path every user takes.

For a date inside a form, do not open a picker by hand at all — a TextField in EditMode.DATE opens it for you and writes the answer back. See R10Form.

अपनी मशीन पर चलाएँ

हर उदाहरण एक साधारण Window है, इसलिए लॉन्चर को सिर्फ़ उसका नाम चाहिए।

gradlew lwjgl3:run --args="classname dev.cf.recipe.R20Pickers"
इसे बदलना

Java पहले से संकलित होता है, इसलिए ब्राउज़र आपके बदलाव को खुद दोबारा नहीं बना सकता — यहाँ दिखा कोड प्रकाशित होने से पहले TeaVM द्वारा JavaScript में बदला गया था। फ़ाइल को किसी प्रोजेक्ट में कॉपी कीजिए और वह चारों प्लेटफ़ॉर्म पर बिना बदलाव चलती है; ऊपर दी गई कमांड ही पूरी तैयारी है।

यहीं चल रहा हैCrossFly 0.1.32
ऐप शुरू हो रहा है…

TeaVM ने इसे JavaScript में संकलित किया — यह वही कोड है, उसका वीडियो नहीं। · सभी उदाहरण

यह क्या इस्तेमाल करता है

इस उदाहरण में छुए गए फ़्रेमवर्क टाइप। जिनमें लिंक है उनका संदर्भ पृष्ठ मौजूद है।

CardColorPickerComponentDatePickerDateRangePickerGapGridLayoutLabelScreenStylesTimePickerWidgets

सोर्स कोड

पूरा, बिना कटौती के। यह वही फ़ाइल है, उसका अंश नहीं।

कच्चा
dev/cf/recipe/R20Pickers.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.picker.*;
import dev.crossfly.ui.style.*;

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

/**
 * The pickers, and the callback shape they all share.
 *
 * <p>Every picker is a {@link dev.crossfly.ui.Window} that answers:
 * {@code show(answer -> …)}, where {@code answer} is {@code null} when the user cancelled. One
 * shape for date, time, colour, file, photo, barcode and location — so learning one is learning
 * all of them.</p>
 *
 * <p><b>Handle the null.</b> Cancelling is not an error and not an edge case; it is the most common
 * outcome of opening a picker by mistake, and a callback that assumes an answer throws on a path
 * every user takes.</p>
 *
 * <p>For a date <i>inside a form</i>, do not open a picker by hand at all — a {@code TextField} in
 * {@code EditMode.DATE} opens it for you and writes the answer back. See {@link R10Form}.</p>
 */
public class R20Pickers extends Recipe
{
   private Label answer;

   public String title()
   {
      return "Pickers";
   }

   public String note()
   {
      return "show(answer -> …) on all of them, and answer is null when the user backed out. The"
         + " ones needing hardware live in R21, and the system file picker in R31 — those can be"
         + " refused.";
   }

   public void build(Component body) throws Exception
   {
      answer = label("Nothing picked yet.", 1f, false, Styles.captionColor, Position.START);
      answer.testTag("pickers.answer");
      // Pinned below the scrolling body, so the answer stays in view (see Recipe.pin).
      pin(answer);

      open(body, 0xE878, "Date", () -> new DatePicker().show(a -> said("Date", a)));
      open(body, 0xE8B5, "Time", () -> new TimePicker().show(a -> said("Time", a)));
      open(body, 0xE916, "Date range", () -> new DateRangePicker().show(a -> said("Range", a)));
      open(body, 0xE40A, "Colour", () -> new ColorPicker(Styles.primaryColor.color())
         .show(a -> said("Colour", a)));
   }

   /** A row per picker: its glyph on a tonal tile, its name, and the whole card opens it. */
   private void open(Component body, int icone, String name, Runnable go) throws Exception
   {
      Card c = new Card();
      c.setLayout(new GridLayout(Position.START, Position.CENTER));
      c.getStyle()
         .outgap(Gap.ofFont(0, 0, 0, .5f))
         .pressable();
      c.testTag("pickers." + name.toLowerCase()
         .replace(' ', '.'));
      c.onAction(e -> go.run());
      c.add(0f, 1f, 0f, Tones.tile(icone, Tones.accent()),
         outgap(label(name, 1.2f, true, Styles.textColor, Position.START), .6f, 0, 0, 0),
         matglyph(0xE5CC, tertiary(), 1f));   // chevron_right
      body.add(LAY_AUTO, c);
   }

   /** One place that handles the answer, including the null every picker can return. */
   private void said(String what, Object a)
   {
      answer.setText(a == null ? what + ": cancelled" : what + ": " + a);
      answer.invalidateMeasure(); // the pinned band must grow with it (see Recipe.pin)
      Screen.repaint();
   }
}
एआई सहायक के लिए

इस पृष्ठ के मशीन-पठनीय रूप, ताकि मॉडल API का अनुमान लगाने के बजाय उदाहरण पढ़ सके।

यह उदाहरण, JSON मेंयह उदाहरण, Markdown में
पिछलाCapturing a signatureअगलाCamera, barcode and GPS