<commit_before>//
// Triple Play - utilities for use in PlayN-based games
// Copyright (c) 2011-2013, Three Rings Design, Inc. - All rights reserved.
// http://github.com/threerings/tripleplay/blob/master/LICENSE

package tripleplay.ui;

import pythagoras.f.Dimension;
import pythagoras.f.IDimension;

/**
 * Defines the interface to layouts, which implement a particular layout policy.
 */
public abstract class Layout
{
    /** An abstract base class for all layout constraints. */
    public static abstract class Constraint {
        /** Called by an element when it is configured with a constraint. */
        public void setElement (Element<?> elem) {
            // nothing needed by default
        }

        /** Allows a layout constraint to adjust an element's x hint. */
        public float adjustHintX (float hintX) {
            return hintX; // no adjustments by default
        }

        /** Allows a layout constraint to adjust an element's y hint. */
        public float adjustHintY (float hintY) {
            return hintY; // no adjustments by default
        }

        /** Allows a layout constraint to adjust an element's preferred size. */
        public void adjustPreferredSize (Dimension psize, float hintX, float hintY) {
            // no adjustments by default
        }
    }

    /**
     * Computes and returns the size needed to arrange children of the supplied container according
     * to their preferred size, given the specified x and y size hints.
     */
    public Dimension computeSize (Container<?> elems, float hintX, float hintY)
    {
        if (elems instanceof Elements) {
            return computeSize((Elements<?>)elems, hintX, hintY);
        } else {
            // uh oh...
            return new Dimension(0, 0);
        }
    }

    /**
     * Computes and returns the size needed to arrange children of the supplied elements according
     * to their preferred size, given the specified x and y size hints.
     * <p>This is deprecated and will be removed. Subclasses should change to override the
     * Container overload instead.</p>
     */
    @Deprecated
    public Dimension computeSize (Elements<?> elems, float hintX, float hintY)
    {
        return new Dimension(0, 0);
    }

    /**
     * Lays out the supplied elements into a region of the specified dimensions.
     */
    public void layout (Container<?> elems, float left, float top,
                                 float width, float height) {
        if (elems instanceof Elements) {
            layout((Elements<?>)elems, left, top, width, height);
        } else {
            // uh oh...
        }
    }

    /**
     * Lays out the supplied elements into a region of the specified dimensions.
     * <p>This is deprecated and will be removed. Subclasses should change to override the
     * Container overload instead.</p>
     */
    @Deprecated
    public void layout (Elements<?> elems, float left, float top,
                                 float width, float height)
    {
    }

    // make Element.resolveStyle "visible" to custom layouts
    protected <V> V resolveStyle (Element<?> elem, Style<V> style) {
        return elem.resolveStyle(style);
    }

    // make Element.preferredSize "visible" to custom layouts
    protected IDimension preferredSize (Element<?> elem, float hintX, float hintY) {
        return elem.preferredSize(hintX, hintY);
    }

    protected void setBounds (Element<?> elem, float x, float y, float width, float height) {
        elem.setLocation(x, y);
        elem.setSize(width, height);
    }<commit_msg>Remove deprecated overloads and make the new and improved ones abstract<commit_after>//
// Triple Play - utilities for use in PlayN-based games
// Copyright (c) 2011-2013, Three Rings Design, Inc. - All rights reserved.
// http://github.com/threerings/tripleplay/blob/master/LICENSE

package tripleplay.ui;

import pythagoras.f.Dimension;
import pythagoras.f.IDimension;

/**
 * Defines the interface to layouts, which implement a particular layout policy.
 */
public abstract class Layout
{
    /** An abstract base class for all layout constraints. */
    public static abstract class Constraint {
        /** Called by an element when it is configured with a constraint. */
        public void setElement (Element<?> elem) {
            // nothing needed by default
        }

        /** Allows a layout constraint to adjust an element's x hint. */
        public float adjustHintX (float hintX) {
            return hintX; // no adjustments by default
        }

        /** Allows a layout constraint to adjust an element's y hint. */
        public float adjustHintY (float hintY) {
            return hintY; // no adjustments by default
        }

        /** Allows a layout constraint to adjust an element's preferred size. */
        public void adjustPreferredSize (Dimension psize, float hintX, float hintY) {
            // no adjustments by default
        }
    }

    /**
     * Computes and returns the size needed to arrange children of the supplied container according
     * to their preferred size, given the specified x and y size hints.
     */
    public abstract Dimension computeSize (Container<?> elems, float hintX, float hintY);

    /**
     * Lays out the supplied elements into a region of the specified dimensions.
     */
    public abstract void layout (Container<?> elems, float left, float top,
                                 float width, float height);

    // make Element.resolveStyle "visible" to custom layouts
    protected <V> V resolveStyle (Element<?> elem, Style<V> style) {
        return elem.resolveStyle(style);
    }

    // make Element.preferredSize "visible" to custom layouts
    protected IDimension preferredSize (Element<?> elem, float hintX, float hintY) {
        return elem.preferredSize(hintX, hintY);
    }

    protected void setBounds (Element<?> elem, float x, float y, float width, float height) {
        elem.setLocation(x, y);
        elem.setSize(width, height);
    }
{'fraction_non_alphanumeric': 0.08724498258417648, 'fraction_numerical': 0.003317299718029524, 'mean_word_length': 2.3819405496354458, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2879994', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1517, 'n_words': 637}