Search Unity

GUILayout margin confusion

Discussion in 'Immediate Mode GUI (IMGUI)' started by Marc, Jun 17, 2008.

  1. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Greetings.

    Im trying to calculate the excact size of some button styles layed out in a horizontal group using GUILayout, but i cant seem to make sense of how the margins works.

    From what i got now it seems that the GUILayout only adds the margin between the buttons and not at the left or right most edge buttons which is ok cause i dont have a need for margin if there is nothing next to it, but! i dont get how the margin between the buttons work.

    Example: left margin (L) set to 5 and right margin set to 10 (R) on the button (B) style.

    ----------------
    |B|R|B|R|B|
    ----------------

    It seems to use the largest margin set on the style and ignore the small one is that correct? Why is it not additive?

    What i expected:

    ------------------
    |B|LR|B|LR|B|
    ------------------
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    The margin between two elements are the Max of the elements' facing margins. (like you described above like CSS)

    IF you have elements (e.g. Buttons) inside a container (e.g. BeginHorizontal), two things can happen:
    * If you pass in a GUIStyle to BeginHorizontal, the distance from the container element to the Buttons is the Max of the container style's padding the buttons' margins
    * If you don't pass in a style, the lowest margin of all elements are propagated "up" to the container element.
     
  3. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Ok thanks. There wouldn't happen to be a CalcSize that account for this? :D