1# Copyright (c) 2010-2011 Tim Baker
2
3namespace eval DemoGradients2 {}
4proc DemoGradients2::Init {T} {
5
6    #
7    # Configure the treectrl widget
8    #
9
10    $T configure \
11	-showbuttons no -showlines no -showroot no \
12	-xscrollincrement 20 -yscrollincrement 20 \
13	-xscrollsmoothing yes -yscrollsmoothing yes \
14
15    #
16    # Create columns
17    #
18
19    for {set i 0} {$i < 6} {incr i} {
20	$T column create -text "Column $i" -width 100 -tags C$i
21    }
22
23    set steps 25
24    set stops {{0.0 "light green"} {1.0 white}}
25
26    $T gradient create G_C0 -stops $stops -steps $steps -orient vertical
27    $T column configure C0 -itembackground G_C0
28
29    $T gradient create G_C1 -stops $stops -steps $steps -orient vertical
30    $T gradient configure G_C1 -top {0.0 area content} -bottom {1.0 area content}
31    $T column configure C1 -itembackground G_C1
32
33    $T gradient create G_C2 -stops $stops -steps $steps -orient vertical
34    $T gradient configure G_C2 -top {0.0 canvas} -bottom {1.0 canvas}
35    $T column configure C2 -itembackground G_C2
36
37    $T gradient create G_C3 -stops $stops -steps $steps -orient horizontal
38    $T gradient configure G_C3 -left {} -right {}
39    $T column configure C3 -itembackground G_C3
40
41    $T gradient create G_C4 -stops $stops -steps $steps -orient horizontal
42    $T gradient configure G_C4 -left {0.0 area content} -right {1.0 area content}
43    $T column configure C4 -itembackground G_C4
44
45    $T gradient create G_C5 -stops $stops -steps $steps -orient horizontal
46    $T gradient configure G_C5 -left {0.0 canvas} -right {1.0 canvas}
47    $T column configure C5 -itembackground G_C5
48
49    #
50    # Define new states
51    #
52
53    $T item state define openW
54    $T item state define openN
55
56    #
57    # Create elements
58    #
59
60    $T element create elemTextIntro text
61
62    $T element create elemBox rect -height 50 \
63	-outline gray -outlinewidth 1 -open {wn {openW openN} w openW n openN}
64
65    #
66    # Create styles using the elements
67    #
68
69    $T style create styleIntro
70    $T style elements styleIntro elemTextIntro
71    $T style layout styleIntro elemTextIntro -padx 4 -pady {3 0} -squeeze x
72
73    $T style create styleBox
74    $T style elements styleBox elemBox
75    $T style layout styleBox elemBox -iexpand x
76
77    #
78    # Create items and assign styles
79    #
80
81    set I [$T item create -parent root]
82    $T item style set $I C0 styleIntro
83    $T item span $I C0 6
84    $T item text $I C0 "This demonstrates column -itembackground colors with gradients.\n
85Column 0 has a vertical gradient with unspecified bounds, so the gradient\
86    is as tall as each item.\n    \
87    G_C0 -top { } -bottom { }\n
88Column 1 has a vertical gradient as tall as the content area.  The colors\
89    remain 'locked in place' as the list is scrolled up and down.\n    \
90    G_C1 -top {0.0 area content} -bottom {1.0 area content}\n
91Column 2 has a vertical gradient as tall as the canvas.  The first stop color\
92    begins at the top of the first item and the last stop color ends at the\
93    bottom of the last item.\n    \
94    G_C2 -top {0.0 canvas} -bottom {1.0 canvas}\n
95Column 3 has a horizontal gradient with unspecified bounds, so the gradient\
96    is as wide as the column.\n    \
97    G_C3 -left {} -right {}\n
98Column 4 has a horizontal gradient as wide as the content area.  The colors\
99    remain 'locked in place' as the list is scrolled left and right, and\
100    resizing the window changes the part of the gradient in that column.\n    \
101    G_C4 -left {0.0 area content} -right {1.0 area content}\n
102Column 5 has a horizontal gradient as wide as the canvas.  The first stop color\
103    begins at the left edge of the first column and the last stop color ends at the\
104    right edge of the last column.  If the window is wider than the items then\
105    the gradient ends at the window border.\n    \
106    G_C5 -left {0.0 canvas} -right {1.0 canvas}"
107
108
109    for {set i 0} {$i < 25} {incr i} {
110	set I [$T item create -parent root]
111	$T item state forcolumn $I {range 1 end} openW
112	$T item style set $I all styleBox
113    }
114
115    return
116}
117