1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module pango.tabs;
7 
8 import pango.utils;
9 import pango.c.tabs;
10 
11 import glib;
12 import gobject;
13 
14 
15 /**
16  * PangoTabAlign:
17  * @PANGO_TAB_LEFT: the tab stop appears to the left of the text.
18  *
19  * A #PangoTabAlign specifies where a tab stop appears relative to the text.
20  */
21 enum TabAlign
22 {
23   Left = PangoTabAlign.PANGO_TAB_LEFT
24 
25   /* These are not supported now, but may be in the
26    * future.
27    *
28    *  PANGO_TAB_RIGHT,
29    *  PANGO_TAB_CENTER,
30    *  PANGO_TAB_NUMERIC
31    */
32 }
33 
34 struct Tab {
35     TabAlign alignment;
36     int location;
37 }
38 
39 
40 /**
41  * PANGO_TYPE_TAB_ARRAY:
42  *
43  * The #GObject type for #PangoTabArray.
44  */
45 class TabArray
46 {
47     mixin NativePtrHolder!(PangoTabArray, pango_tab_array_free);
48 
49     package this (PangoTabArray *ptr, Transfer transfer) {
50         initialize(ptr, transfer);
51     }
52 
53     this(int initialSize, bool positionsInPixels) {
54         this(pango_tab_array_new(initialSize, positionsInPixels), Transfer.Full);
55     }
56 
57     this(Args...)(int size, bool positionsInPixels, Args tabs) {
58         this(size, positionsInPixels);
59 
60         this.length = tabs.length;
61         foreach(i, t; tabs) {
62             setTab(i, t);
63         }
64     }
65 
66 
67     TabArray copy() {
68         return getDObject!TabArray(pango_tab_array_copy(nativePtr), Transfer.Full);
69     }
70 
71     @property int length() {
72         return pango_tab_array_get_size(nativePtr);
73     }
74 
75     @property length(int newSize) {
76         pango_tab_array_resize(nativePtr, newSize);
77     }
78 
79     Tab tab(int tabIndex) {
80         Tab res;
81         pango_tab_array_get_tab(nativePtr, tabIndex, cast(PangoTabAlign*)&res.alignment, &res.location);
82         return res;
83     }
84 
85     void setTab(int tabIndex, Tab tab) {
86         pango_tab_array_set_tab(nativePtr, tabIndex, cast(PangoTabAlign)tab.alignment, tab.location);
87     }
88 
89     @property Tab[] tabs() {
90         auto l = length;
91         if (!l) return [];
92 
93         PangoTabAlign *alignments;
94         int *locations;
95         pango_tab_array_get_tabs(nativePtr, &alignments, &locations);
96         scope(exit) {
97             g_free(alignments);
98             g_free(locations);
99         }
100 
101         Tab[] res;
102         foreach(i; 0 .. l) {
103             res ~= Tab(cast(TabAlign)alignments[i], locations[i]);
104         }
105         return res;
106     }
107 
108     @property bool positionsInPixels() {
109         return cast(bool)pango_tab_array_get_positions_in_pixels(nativePtr);
110     }
111 }
112