<commit_before>// Copyright 2015 Endless Mobile, Inc.

/* exported TiledGrid */

const Gtk = imports.gi.Gtk;

const Arrangement = imports.app.interfaces.arrangement;
const Module = imports.app.interfaces.module;

const TiledGrid = new Module.Class({
    Name: 'Arrangement.TiledGrid',
    Extends: Gtk.Grid,
    Implements: [Arrangement.Arrangement],

    _init: function (props={}) {
        this.parent(props);
    },

    // Arrangement override
    fade_card_in: function (card) {
        card.show_all();
    },

    // Arrangement override
    pack_card: function () {
        // FIXME: For now we're always showing two rows of cards.
        // An alternative would be to show 1 row for 4 cards, and 2 rows otherwise
        this.get_children().forEach(this.remove, this);
        // The card to be packed is already in this array:
        let cards = this.get_cards();

        let columns = Math.ceil(this.get_card_count() / 2);
        let i = 0;
        for (let card of cards) {
            let col = i % columns;
            let row = Math.floor(i / columns);
            this.attach(card, col, row, 1, 1);
            i++;
        }
    },
});
<commit_msg>Arrangement.TiledGrid shows one row in case of two cards<commit_after>// Copyright 2015 Endless Mobile, Inc.

/* exported TiledGrid */

const Gtk = imports.gi.Gtk;

const Arrangement = imports.app.interfaces.arrangement;
const Module = imports.app.interfaces.module;

const TiledGrid = new Module.Class({
    Name: 'Arrangement.TiledGrid',
    Extends: Gtk.Grid,
    Implements: [Arrangement.Arrangement],

    _init: function (props={}) {
        this.parent(props);
    },

    // Arrangement override
    fade_card_in: function (card) {
        card.show_all();
    },

    // Arrangement override
    pack_card: function () {
        // FIXME: For now we're always showing two rows of cards.
        // An alternative would be to show 1 row for 4 cards, and 2 rows otherwise
        this.get_children().forEach(this.remove, this);
        // The card to be packed is already in this array:
        let cards = this.get_cards();
        let count = this.get_card_count();
        let columns = count < 4 ? count : Math.ceil(count / 2);
        let i = 0;
        for (let card of cards) {
            let col = i % columns;
            let row = Math.floor(i / columns);
            this.attach(card, col, row, 1, 1);
            i++;
        }
    },
});

{'fraction_non_alphanumeric': 0.11609715932482503, 'fraction_numerical': 0.009468917249897077, 'mean_word_length': 2.218543046357616, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '5511998', 'n_tokens_mistral': 763, 'n_tokens_neox': 730, 'n_words': 228}