package com.imyeyu.fx.ui.components;

import com.imyeyu.java.ref.Ref;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.skin.SliderSkin;
import javafx.scene.layout.StackPane;

/**
 * 填充轨道滑动条皮肤
 *
 * @author 夜雨
 * @since 2026-07-25
 */
class FilledSliderSkin extends SliderSkin {

	/**
	 * 构造皮肤
	 *
	 * @param control 控件
	 */
	FilledSliderSkin(FilledSlider control) {
		super(control);
		try {
			StackPane track = Ref.getFieldValue(this, "track", StackPane.class);
			ProgressBar pb = new ProgressBar();
			pb.progressProperty().bind(control.valueProperty().subtract(control.minProperty()).divide(control.maxProperty().subtract(control.minProperty())));
			pb.prefWidthProperty().bind(track.widthProperty());
			pb.setMouseTransparent(true);
			track.getChildren().addFirst(pb);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}
}
