File: TestScales.d

package info (click to toggle)
gtk-d 3.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,152 kB
  • sloc: javascript: 565; sh: 71; makefile: 25
file content (171 lines) | stat: -rw-r--r-- 4,766 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 * This file is part of gtkD.
 *
 * gtkD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * gtkD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with gtkD; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 */

module TestScales;

private import gtk.Table;

private import gtk.VScale;
private import gtk.HScale;
private import gtk.MenuItem;
private import gtk.Menu;
private import gtk.CheckButton;
private import gtk.ComboBox;
private import gtk.ComboBoxText;
private import gtk.Box;
private import gtk.Button;
private import gtk.Scrollbar;
private import gtk.Separator;
private import gtk.Label;
private import gtk.Scale;
private import gtk.Adjustment;
private import gtk.VBox;
private import gtk.HBox;
private import gtk.HScrollbar;
private import gtk.Range;

debug import std.stdio;

/**
 * This tests the gtkD scales and scrollbar widgets
 */

class TestScales : Table //, MenuItemListener
{
	VScale vscale;
	HScale hscale;

	this()
	{

		debug(1)
		{
			writeln("instantiating TestScales");
		}

		super(1,1,0);

		createRangeControls();
	}

	void createRangeControls()
	{
			Box box1,box2,box3;
			Button button;
			Scrollbar scrollbar;
			Separator separator;
			ComboBoxText positionSelection;

			Label label;
			Scale scale;
			Adjustment adj1, adj2;

			box1 = new VBox(false,0);
			add(box1);

			box2 = new HBox(false,0);
			box2.setBorderWidth(10);
			box1.packStart(box2, true,true,0);

			/* value, lower, upper, step_increment, page_increment, page_size */
			/* Note that the page_size value only makes a difference for
			 * scrollbar widgets, and the highest value you'll get is actually
			 * (upper - page_size). */
			adj1 = new Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0);

			vscale = new VScale(adj1);
			//scale_set_default_values (GTK_SCALE (vscale));
			box2.packStart(vscale, true, true, 0);

			box3 = new VBox(false,10);
			box2.packStart(box3,true,true,0);

			/* Reuse the same adjustment */
			hscale = new HScale(adj1);
			hscale.setSizeRequest(200,-1);
			//scale_set_default_values (GTK_SCALE (hscale));
			box3.packStart(hscale,true,true,0);

			/* Reuse the same adjustment again */
			scrollbar = new HScrollbar(adj1);
			/* Notice how this causes the scales to always be updated
			 * continuously when the scrollbar is moved */
			box3.packStart(scrollbar,true,true,0);

			box2 = new HBox(false,10);
			box2.setBorderWidth(10);
			box1.packStart(box2,true,true,0);

			/* A checkbutton to control whether the value is displayed or not */
			CheckButton cButton = new CheckButton("Display value on scale widgets");
			cButton.setActive(true);
			cButton.addOnClicked(&displayValues);
			box2.packStart(cButton,true,true,0);

			box2 = new HBox(false,10);
			box2.setBorderWidth(10);

			/* An option menu to change the position of the value */
			label = new Label("Scale Value Position:");
			box2.packStart(label,false,false,0);

			positionSelection = new ComboBoxText();
			positionSelection.appendText("Top");
			positionSelection.appendText("Bottom");
			positionSelection.appendText("Left");
			positionSelection.appendText("Right");
			positionSelection.addOnChanged(&onPositionSelectionChanged);
			positionSelection.setActive(0);

			box2.packStart(positionSelection,false,false,0);

			box1.packStart(box2,false,false,0);
	}

	void onPositionSelectionChanged(ComboBoxText comboBoxText)
	{
		switch ( comboBoxText.getActiveText() )
		{
			case "Top":
				vscale.setValuePos(PositionType.TOP);
				hscale.setValuePos(PositionType.TOP);
				break;
			case "Bottom":
				vscale.setValuePos(PositionType.BOTTOM);
				hscale.setValuePos(PositionType.BOTTOM);
				break;
			case "Left":
				vscale.setValuePos(PositionType.LEFT);
				hscale.setValuePos(PositionType.LEFT);
				break;
			case "Right":
				vscale.setValuePos(PositionType.RIGHT);
				hscale.setValuePos(PositionType.RIGHT);
				break;
			default:
				break;

		}
	}

	void displayValues(Button checkButton)
	{
		vscale.setDrawValue((cast(CheckButton)checkButton).getActive());
		hscale.setDrawValue((cast(CheckButton)checkButton).getActive());
	}
}