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

Telling the user something

Interrupt in proportion to what you need back. A confirmation on something reversible teaches people to dismiss confirmations — including the one that mattered.

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

Four ways to tell the user something, and the question that picks between them.

The question is what do you need from them: nothing, a decision, a choice from a few, or nothing but they must not miss it. Getting this wrong is why apps end up asking "OK?" about things that were never in doubt — and why the one destructive action arrives as a toast nobody reads.

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

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

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

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

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

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

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

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

ActionSheetAlertButtonCardComponentHintPalColorStylesWidgets

सोर्स कोड

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

कच्चा
dev/cf/recipe/R11Telling.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.*;

/**
 * Four ways to tell the user something, and the question that picks between them.
 *
 * <p>The question is <b>what do you need from them</b>: nothing, a decision, a choice from a few,
 * or nothing but they must not miss it. Getting this wrong is why apps end up asking "OK?" about
 * things that were never in doubt — and why the one destructive action arrives as a toast nobody
 * reads.</p>
 */
public class R11Telling extends Recipe
{
   private static final int IC_HINT = 0xE7F4, IC_ALERT = 0xE002, IC_SHEET = 0xE5D2,
      IC_INLINE = 0xE000;

   public String title()
   {
      return "Telling the user something";
   }

   public String note()
   {
      return "Interrupt in proportion to what you need back. A confirmation on something reversible"
         + " teaches people to dismiss confirmations — including the one that mattered.";
   }

   public void build(Component body) throws Exception
   {
      // The tones climb with the interruption: the one that needs nothing back wears the quiet
      // supporting tone, the one that stops the user and the one they must fix wear the error
      // tone. Four identical grey cards said the opposite of what the screen is about.
      row(body, IC_HINT, Tones.support(), "Hint — nothing needed", "It happened. A toast that"
         + " fades, over the screen the user is already looking at.",
         () -> Hint.show("Saved", 2000));

      row(body, IC_SHEET, Tones.highlight(), "ActionSheet — one of a few", "Three or four actions"
         + " on one object. Cheaper than a screen, clearer than a long-press nobody discovers.",
         this::sheet);

      row(body, IC_ALERT, Tones.danger(), "Alert — a decision", "Two ways forward and the app"
         + " cannot pick. Name the thing in the question: \"Delete this?\" is not answerable.",
         this::alert);

      row(body, IC_INLINE, Tones.danger(), "Inline — they must fix it", "A validation message"
         + " belongs next to the field, not in a dialog they have to dismiss before they can act"
         + " on it.", null);
   }

   private void alert()
   {
      Alert a = new Alert("Discard this draft?", "It has not been sent, and this cannot be undone.",
         "Keep editing", "Discard");
      // Index 1 is the second button. The destructive one goes LAST: the safe choice is where the
      // thumb rests, and the dangerous one costs a deliberate reach.
      a.buttonAction(1, c -> Hint.show("Discarded", 1500));
      a.show();
   }

   private void sheet()
   {
      ActionSheet s = new ActionSheet("Cancel", "Share", "Duplicate", "Export");
      for (int i = 0; i < 3; i++)
      {
         final int idx = i;
         s.buttonAction(idx, c -> Hint.show(new String[] { "Shared", "Duplicated", "Exported" }[idx],
            1500));
      }
      s.show();
   }

   private void row(Component body, int icone, PalColor tom, String title, String why,
      Runnable demo) throws Exception
   {
      Card c = Tones.card(tom);
      c.add(LAY_AUTO, outgap(Tones.head(icone, title, tom), 0, 0, 0, 0));
      c.add(LAY_AUTO, outgap(label(why, 1f, false, Styles.captionColor, Position.START), 0, .2f, 0,
         demo == null ? 0 : .5f));
      if (demo != null)
      {
         Button b = Tones.action("Show it", tom);
         b.onAction(e -> demo.run());
         c.add(LAY_AUTO, b);
      }
      body.add(LAY_AUTO, outgap(c, 0, 0, 0, .6f));
   }
}
एआई सहायक के लिए

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

यह उदाहरण, JSON मेंयह उदाहरण, Markdown में
पिछलाA form that fights backअगलाBottom nav that becomes a rail