<commit_before>import QtQuick 2.3
import Ableton.Cassowary 1.0
import "moreUtils.js" as MoreUtils

Item {
    id: root

    width: orientation == Qt.Horizontal ? vSize.value : root.otherSize
    height: orientation == Qt.Vertical ? vSize.value : root.otherSize
    x: orientation == Qt.Horizontal ? vPosition.value : 0
    y: orientation == Qt.Vertical ? vPosition.value : 0

    property int orientation
    property var wrapped
    property Solver solver
    property var prevHandle
    property var nextHandle

    property bool dragging
    property bool resizing
    property bool animate

    property real totalSize
    property real otherSize
    property real fixedSize
    property real handleSize

    readonly property alias vPosition: __vPosition
    readonly property alias vSize: __vSize
    readonly property alias eSize: __eSize
    readonly property alias cCollapse: __cCollapse
    readonly property bool fixed: cCollapse.when || cSnap.when

    readonly property real initialRatio: MoreUtils.optional(
        wrapped, 'initialRatio', .3)
    readonly property real minimumSize: MoreUtils.optional(
        wrapped, 'minimumSize', 40)
    readonly property real maximumSize: MoreUtils.optional(
        wrapped, 'maximumSize', Infinity)
    readonly property var snapTo: MoreUtils.optional(
        wrapped, 'snapTo')

    Solver {
        extend: root.solver
        Variable { id: __vPosition }
        Variable { id: __vSize }
        Edit {
            id: __eSize
            target: vSize
            when: false
        }
        Constraint { expr: geq(vSize, minimumSize) }
        Constraint { expr: leq(vSize, maximumSize) }
        Constraint {
            expr: eq(vPosition,
                   root.prevHandle
                   ? plus(root.prevHandle.vPosition, root.handleSize)
                   : 0)
        }
        Constraint {
            expr: eq(plus(vPosition, vSize),
                     root.nextHandle ? root.nextHandle.vPosition : vTotalSize)
        }
        Constraint {
            id: cSnap
            strength: Strength.Strong
            weight: 100
            when: !!snapTo && !root.dragging && vSize.value > 0
            function update() {
                expr = eq(vSize, MoreUtils.closest(snapTo, vSize.value))
            }
        }
        Constraint {
            id: __cCollapse
            strength: Strength.Strong
            weight: 1000
            when: false
            expr: eq(vSize, minimumSize)
        }
        Constraint {
            when: root.resizing
            strength: Strength.Strong
            weight: 2
            function update() {
                var ratio = root.totalSize == 0
                    ? root.initialRatio
                    : vSize.value / (root.totalSize - root.fixedSize)
                expr = eq(vSize, times(minus(
                    vTotalSize, root.fixedSize), ratio))
            }
        }
    }

    Item {
        id: wrapper
        anchors.fill: parent
        children: wrapped
        Binding {
            target: wrapped.anchors
            property: "fill"
            value: wrapper
        }
    }
<commit_msg>prototype: Properly enable ratio and snapping constraints in splitters<commit_after>import QtQuick 2.3
import Ableton.Cassowary 1.0
import "moreUtils.js" as MoreUtils

Item {
    id: root

    width: orientation == Qt.Horizontal ? vSize.value : root.otherSize
    height: orientation == Qt.Vertical ? vSize.value : root.otherSize
    x: orientation == Qt.Horizontal ? vPosition.value : 0
    y: orientation == Qt.Vertical ? vPosition.value : 0

    property int orientation
    property var wrapped
    property Solver solver
    property var prevHandle
    property var nextHandle

    property bool dragging
    property bool resizing
    property bool animate

    property real totalSize
    property real otherSize
    property real fixedSize
    property real handleSize

    readonly property alias vPosition: __vPosition
    readonly property alias vSize: __vSize
    readonly property alias eSize: __eSize
    readonly property alias cCollapse: __cCollapse
    readonly property bool fixed: cCollapse.when || cSnap.when

    readonly property real initialRatio: MoreUtils.optional(
        wrapped, 'initialRatio', .3)
    readonly property real minimumSize: MoreUtils.optional(
        wrapped, 'minimumSize', 40)
    readonly property real maximumSize: MoreUtils.optional(
        wrapped, 'maximumSize', Infinity)
    readonly property var snapTo: MoreUtils.optional(
        wrapped, 'snapTo')

    Solver {
        extend: root.solver
        Variable { id: __vPosition }
        Variable { id: __vSize }
        Edit {
            id: __eSize
            target: vSize
            when: false
        }
        Constraint { expr: geq(vSize, minimumSize) }
        Constraint { expr: leq(vSize, maximumSize) }
        Constraint {
            expr: eq(vPosition,
                   root.prevHandle
                   ? plus(root.prevHandle.vPosition, root.handleSize)
                   : 0)
        }
        Constraint {
            expr: eq(plus(vPosition, vSize),
                     root.nextHandle ? root.nextHandle.vPosition : vTotalSize)
        }
        Constraint {
            id: cSnap
            strength: Strength.Strong
            weight: 100
            when: !!snapTo && !root.dragging && vSize.value > 0
            onWhenChanged: update()
            Component.onCompleted: update()
            function update() {
                expr = eq(vSize, MoreUtils.closest(snapTo, vSize.value))
            }
        }
        Constraint {
            id: __cCollapse
            strength: Strength.Strong
            weight: 1000
            when: false
            expr: eq(vSize, minimumSize)
        }
        Constraint {
            when: root.resizing
            strength: Strength.Strong
            weight: 2
            onWhenChanged: update()
            Component.onCompleted: update()
            function update() {
                var ratio = root.totalSize == 0
                    ? root.initialRatio
                    : vSize.value / (root.totalSize - root.fixedSize)
                expr = eq(vSize, times(minus(
                    vTotalSize, root.fixedSize), ratio))
            }
        }
    }

    Item {
        id: wrapper
        anchors.fill: parent
        children: wrapped
        Binding {
            target: wrapped.anchors
            property: "fill"
            value: wrapper
        }
    }

{'fraction_non_alphanumeric': 0.07262398280362352, 'fraction_numerical': 0.006141563027790573, 'mean_word_length': 1.7566652560304696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4432758', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1645, 'n_words': 478}