<commit_before>function MtkBox (settings) {
    MtkContainer.call (this, settings);
    this.InitFromXaml (this.XamlInitSource || "<Canvas/>");

    //
    // Properties
    //

    this.Spacing = 0;

    //
    // Collection Logic
    //

    this.PackStart = function (widget, expand) {
        widget.Settings.MtkBoxExpand = expand;
        this.Add (widget);
    };

    //
    // Sizing and Allocation/Generic Layout
    //
    //   VBox: Static = Width/Left,  Variable = Height/Top
    //   HBox: Static = Height/Left, Variable = Width/Left
    //
    //   The static dimension is dictated by child size requests,
    //   and the variable dimension by the parent allocation in
    //   the respective dimension
    //

    this.Override ("OnSizeRequest", function () {
        var request = {};
        request[this.VariableDimension] = 2 * this.TotalPadding + this.ChildCount * this.Spacing;
        request[this.StaticDimension] = 0;
        this.Children.forEach (function (child) {
            var sr = child.SizeRequest[this.StaticDimension];
            request[this.StaticDimension] = Math.max (sr, request[this.StaticDimension]);
        }, this);
        request[this.StaticDimension] += 2 * this.TotalPadding;
        return request;
    });

    this.Override ("OnSizeAllocate", function () {
        if (!this.IsRealized) {
            return;
        }

        // Avoid calling this.$OnSizeAllocate$ (MtkContainer)
        // since it handles child allocations as well. We
        // need this call to have ourself allocated first.
        this.MtkWidget_OnSizeAllocate ();

        var variable_offset = this.TotalPadding;
        var static_offset = this.TotalPadding;

        var static_space = 0;
        var flex_space = 0;
        var flex_count = 0;

        this.Children.forEach (function (child) {
            static_space += child.Settings.MtkBoxExpand ? 0 : child.SizeRequest[this.VariableDimension];
            flex_count += child.Settings.MtkBoxExpand ? 1 : 0;
        }, this);

        flex_space = this.Allocation[this.VariableDimension] - static_space - 
            (this.ChildCount - 1) * this.Spacing - 2 * this.TotalPadding;
        if (flex_space < 0) {
            flex_space = 0;
        }
        
        this.Children.forEach (function (child) {
            child.Allocation[this.VariableOffset] = variable_offset;
            child.Allocation[this.StaticOffset] = static_offset;

            if (child.Settings.MtkBoxExpand && flex_count > 0) {
                var size = flex_space / flex_count--;
                flex_space -= size;
                if (flex_count == 0) {
                    size += flex_space;
                }
                
                child.Allocation[this.VariableDimension] = size;
            } else {
                child.Allocation[this.VariableDimension] = child.SizeRequest[this.VariableDimension];
            }

            child.Allocation[this.StaticDimension] = this.Allocation[this.StaticDimension] - 2 * this.TotalPadding;

            variable_offset += child.Allocation[this.VariableDimension] + this.Spacing;

            child.IsRealized = true;
            child.OnSizeAllocate ();
        }, this);
    });

    this.AfterConstructed ();
} 

function MtkHBox (settings) {
    MtkBox.call (this, settings);
    this.StaticDimension = "Height";
    this.VariableDimension = "Width";
    this.StaticOffset = "Top";
    this.VariableOffset = "Left";
    this.AfterConstructed ();
}

function MtkVBox (settings) {
    MtkBox.call (this, settings);
    this.StaticDimension = "Width";<commit_msg>Call .Realize instead of setting .IsRealized, fixed bug in computing size request for the variable dimension<commit_after>function MtkBox (settings) {
    MtkContainer.call (this, settings);
    this.InitFromXaml (this.XamlInitSource || "<Canvas/>");

    //
    // Properties
    //

    this.Spacing = 0;

    //
    // Collection Logic
    //

    this.PackStart = function (widget, expand) {
        widget.Settings.MtkBoxExpand = expand;
        this.Add (widget);
    };

    //
    // Sizing and Allocation/Generic Layout
    //
    //   VBox: Static = Width/Left,  Variable = Height/Top
    //   HBox: Static = Height/Left, Variable = Width/Left
    //
    //   The static dimension is dictated by child size requests,
    //   and the variable dimension by the parent allocation in
    //   the respective dimension
    //

    this.Override ("OnSizeRequest", function () {
        var request = { Width: 0, Height: 0 };
        this.Children.forEach (function (child) {
            var sr = child.SizeRequest;
            request[this.StaticDimension] = Math.max (request[this.StaticDimension], sr[this.StaticDimension]);
            request[this.VariableDimension] += sr[this.VariableDimension];
        }, this);
        request[this.StaticDimension] += 2 * this.TotalPadding;
        request[this.VariableDimension] += 2 * this.TotalPadding + this.ChildCount * this.Spacing;
        return request;
    });

    this.Override ("OnSizeAllocate", function () {
        if (!this.IsRealized) {
            return;
        }

        // Avoid calling this.$OnSizeAllocate$ (MtkContainer)
        // since it handles child allocations as well. We
        // need this call to have ourself allocated first.
        this.MtkWidget_OnSizeAllocate ();

        var variable_offset = this.TotalPadding;
        var static_offset = this.TotalPadding;

        var static_space = 0;
        var flex_space = 0;
        var flex_count = 0;

        this.Children.forEach (function (child) {
            static_space += child.Settings.MtkBoxExpand ? 0 : child.SizeRequest[this.VariableDimension];
            flex_count += child.Settings.MtkBoxExpand ? 1 : 0;
        }, this);

        flex_space = this.Allocation[this.VariableDimension] - static_space - 
            (this.ChildCount - 1) * this.Spacing - 2 * this.TotalPadding;
        if (flex_space < 0) {
            flex_space = 0;
        }
        
        this.Children.forEach (function (child) {
            child.Allocation[this.VariableOffset] = variable_offset;
            child.Allocation[this.StaticOffset] = static_offset;

            if (child.Settings.MtkBoxExpand && flex_count > 0) {
                var size = flex_space / flex_count--;
                flex_space -= size;
                if (flex_count == 0) {
                    size += flex_space;
                }
                
                child.Allocation[this.VariableDimension] = size;
            } else {
                child.Allocation[this.VariableDimension] = child.SizeRequest[this.VariableDimension];
            }

            child.Allocation[this.StaticDimension] = this.Allocation[this.StaticDimension] - 2 * this.TotalPadding;

            variable_offset += child.Allocation[this.VariableDimension] + this.Spacing;

            child.Realize ();
            child.OnSizeAllocate ();
        }, this);
    });

    this.AfterConstructed ();
} 

function MtkHBox (settings) {
    MtkBox.call (this, settings);
    this.StaticDimension = "Height";
    this.VariableDimension = "Width";
    this.StaticOffset = "Top";
    this.VariableOffset = "Left";
    this.AfterConstructed ();
}

function MtkVBox (settings) {
    MtkBox.call (this, settings);
    this.StaticDimension = "Width";
{'fraction_non_alphanumeric': 0.11108078602620088, 'fraction_numerical': 0.004776200873362445, 'mean_word_length': 2.0858947368421052, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7021739', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2014, 'n_words': 445}