From bda80a6d065c1eff4a64497a2a7f457fde87b7eb Mon Sep 17 00:00:00 2001 From: mkpaz Date: Sat, 11 Feb 2023 10:31:45 +0400 Subject: [PATCH] Remove toggle switch left padding when text is empty --- CHANGELOG.md | 1 + .../main/java/atlantafx/base/controls/ToggleSwitchSkin.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bba9c3..53925d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ This is a bugfix/maintenance release that also contains a few style improvements - (CSS) Fix `Tooltip` text not showing for circular buttons. - (CSS) Prevent context menu from inheriting text input font properties. - (CSS) Fix invalid `DatePicker` cell size. +- (Base) Remove `ToggleSwitch` left padding when text is empty. - (Base) Fix `PasswordTextFormatter` garbled input. ## [1.1.0] - 2022-10-10 diff --git a/base/src/main/java/atlantafx/base/controls/ToggleSwitchSkin.java b/base/src/main/java/atlantafx/base/controls/ToggleSwitchSkin.java index 7224ca2..fc07539 100755 --- a/base/src/main/java/atlantafx/base/controls/ToggleSwitchSkin.java +++ b/base/src/main/java/atlantafx/base/controls/ToggleSwitchSkin.java @@ -144,12 +144,14 @@ public class ToggleSwitchSkin extends SkinBase { double thumbAreaWidth = snapSizeX(thumbArea.prefWidth(-1)); double thumbAreaHeight = snapSizeX(thumbArea.prefHeight(-1)); double thumbAreaY = snapPositionX(contentY + (contentHeight / 2) - (thumbAreaHeight / 2)); + double labelContainerWidth = label.getText() != null && !label.getText().isEmpty() + ? contentWidth - thumbAreaWidth : 0; thumbArea.resize(thumbAreaWidth, thumbAreaHeight); - thumbArea.setLayoutX(contentWidth - thumbAreaWidth); + thumbArea.setLayoutX(labelContainerWidth); thumbArea.setLayoutY(thumbAreaY); - labelContainer.resize(contentWidth - thumbAreaWidth, thumbAreaHeight); + labelContainer.resize(labelContainerWidth, thumbAreaHeight); labelContainer.setLayoutY(thumbAreaY); // layout the thumb on the "unselected" position