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

Switching skins

Shape, radius, padding and typeface all come from the skin. Nothing below knows which one is in force.

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

The same screen under Material 3, Fluent and iOS — with no per-skin code anywhere.

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

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

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

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

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

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

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

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

ButtonCardComponentDebugFluentSkinHorizontalLayoutIOSSkinMaterialSkinScreenSkinStylesSwitchTextFieldWidgets

सोर्स कोड

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

कच्चा
dev/cf/recipe/R03Skins.java
package dev.cf.recipe;

import dev.crossfly.ui.*;
import dev.crossfly.ui.graphics.*;
import dev.crossfly.ui.layout.*;
import dev.crossfly.ui.skin.*;
import dev.crossfly.ui.style.*;

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

/**
 * The same screen under Material 3, Fluent and iOS — with no per-skin code anywhere.
 */
public class R03Skins extends Recipe
{
   public String title()
   {
      return "Switching skins";
   }

   public String note()
   {
      return "Shape, radius, padding and typeface all come from the skin. Nothing below knows which"
         + " one is in force.";
   }

   public void build(Component body) throws Exception
   {
      Component linha = new Component();
      linha.setLayout(new HorizontalLayout(Position.START, Position.CENTER));
      // One per call: the add with several weights belongs to GridLayout (see R01Layouts).
      linha.add(LAY_AUTO, outgap(botao("Material", new MaterialSkin()), 0, 0, .5f, 0));
      linha.add(LAY_AUTO, outgap(botao("Fluent", new FluentSkin()), 0, 0, .5f, 0));
      linha.add(LAY_AUTO, botao("iOS", new IOSSkin()));
      body.add(LAY_AUTO, outgap(linha, 0, 0, 0, 1f));

      // Pieces whose shape comes entirely from the skin — that is where the switch shows.
      body.add(LAY_AUTO, outgap(new TextField().caption("A field"), 0, 0, 0, .6f));
      body.add(LAY_AUTO, outgap(new Button("A button"), 0, 0, 0, .6f));
      body.add(LAY_AUTO, outgap(new Switch("A switch"), 0, 0, 0, .6f));
      Card cartao = new Card();
      cartao.add(LAY_AUTO, label("A card", 1.2f, true, Styles.textColor, Position.START));
      body.add(LAY_AUTO, cartao);
   }

   /**
    * {@code apply(skin, onApplied)}, never {@code apply(skin)}.
    *
    * <p>On the web the font atlas of a skin the app did not start with is downloaded on demand, and
    * only the callback form waits for it. On native builds the callback runs before the method
    * returns, so this one line is right on every platform.</p>
    */
   private Button botao(String rotulo, Skin skin)
   {
      Button b = new Button(rotulo);
      b.onAction(c -> Skin.apply(skin, this::recriar));
      return b;
   }

   /** Switching skins is the app's decision, so the rebuild is here — never inside the rebuild itself. */
   private void recriar()
   {
      try
      {
         removeAll();
         onAdd(false);
         setValidLayout(false);
         Screen.repaint();
      }
      catch (Exception e)
      {
         dev.crossfly.util.Debug.handle(e);
      }
   }
}
एआई सहायक के लिए

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

यह उदाहरण, JSON मेंयह उदाहरण, Markdown में
पिछलाTheme tokensअगलाBottom sheet with a fixed footer