diff --git a/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXButtonSkin.java b/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXButtonSkin.java index 9ead857f..6ecd2fe3 100644 --- a/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXButtonSkin.java +++ b/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXButtonSkin.java @@ -52,6 +52,9 @@ public class MFXButtonSkin, B extends MFXButtonBehavi //================================================================================ protected final MaterialSurface surface; + // Specs + protected static double MIN_HEIGHT = 40.0; + //================================================================================ // Constructors //================================================================================ @@ -131,6 +134,11 @@ protected void initBehavior(B behavior) { ); } + @Override + public double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { + return Math.max(MIN_HEIGHT, super.computeMinHeight(width, topInset, rightInset, bottomInset, leftInset)); + } + @Override public double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { T button = getSkinnable(); diff --git a/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXFabSkin.java b/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXFabSkin.java index 42be4900..a5576d59 100644 --- a/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXFabSkin.java +++ b/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXFabSkin.java @@ -61,7 +61,6 @@ public class MFXFabSkin extends MFXButtonSkin - {@link FABVariants#SMALL} -> {@link #MIN_SIZE_SMALL} + *

- {@link FABVariants#LARGE} -> {@link #MIN_SIZE_LARGE} + *

- Standard -> {@link #MIN_WIDTH} + *

+ * Little note: since this skin is for any FAB implementation starting from {@link MFXFabBase}, and because variants + * are only managed by the default implementation {@link MFXFab}, this will also check if the {@link #getSkinnable()} + * instance is the default implementation to use {@link WithVariants#isVariantApplied(Variant)}. + * Otherwise always returns {@link #MIN_WIDTH}. + */ + protected double getSpecsMinWidth() { + MFXFabBase base = getSkinnable(); + if (base instanceof MFXFab) { + MFXFab fab = (MFXFab) base; + return fab.isVariantApplied(FABVariants.SMALL) ? MIN_SIZE_SMALL : + fab.isVariantApplied(FABVariants.LARGE) ? MIN_SIZE_LARGE : + MIN_WIDTH; + } + return MIN_WIDTH; + } + //================================================================================ // Overridden Methods //================================================================================ @@ -277,15 +308,16 @@ public double computeMinWidth(double height, double topInset, double rightInset, MFXFontIcon icon = fab.getIcon(); double iW = (icon != null) ? LayoutUtils.getWidth(icon) + leftInset + rightInset : 0.0; double iH = (icon != null) ? LayoutUtils.getHeight(icon) + topInset + bottomInset : 0.0; - return Math.max(Math.max(iW, iH), 56.0); + double minW = getSpecsMinWidth(); + return Math.max(Math.max(iW, iH), minW); } - return 80.0; + return MIN_WIDTH_EXTENDED; } @Override public double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { MFXFabBase fab = getSkinnable(); - return !fab.isExtended() ? computeMinWidth(-1) : 56.0; + return !fab.isExtended() ? computeMinWidth(-1) : MIN_HEIGHT; } @Override diff --git a/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXSegmentedButtonSkin.java b/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXSegmentedButtonSkin.java index 8bd28f71..d2085b7d 100644 --- a/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXSegmentedButtonSkin.java +++ b/modules/components/src/main/java/io/github/palexdev/mfxcomponents/skins/MFXSegmentedButtonSkin.java @@ -48,6 +48,10 @@ public class MFXSegmentedButtonSkin extends MFXSkinBase first; protected WeakReference last; + // Specs + protected static double MIN_SEGMENT_WIDTH = 48.0; + protected static double MIN_HEIGHT = 40.0; + //================================================================================ // Constructors //================================================================================ @@ -119,6 +123,14 @@ protected void updateFirstLast() { @Override protected void initBehavior(MFXSegmentedButtonBehavior behavior) {} + @Override + public double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { + MFXSegmentedButton button = getSkinnable(); + int density = button.getDensity(); + double minH = MIN_HEIGHT - (4.0 * density); + return Math.max(minH, super.computeMinHeight(width, topInset, rightInset, bottomInset, leftInset)); + } + @Override public double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { ObservableList segments = getSkinnable().getSegments(); @@ -240,7 +252,7 @@ public void setIcon(MFXFontIcon icon) { /** * Default skin used by {@link MFXSegment} and simple extension of {@link MFXButtonSkin}. *

- * What changes is the layout strategy. According to MD3 guidelines a segment's label (text + icon) is always centered. + * What changes is the layout strategy. According to MD3 guidelines, a segment's label (text + icon) is always centered. */ public static class MFXSegmentSkin extends MFXButtonSkin> { @@ -251,6 +263,11 @@ public MFXSegmentSkin(MFXSegment button) { @Override protected void addListeners() {} + @Override + public double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { + return Math.max(MIN_SEGMENT_WIDTH, super.computeMinWidth(height, topInset, rightInset, bottomInset, leftInset)); + } + @Override public double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { MFXSegment segment = getSkinnable();