2
// ScrollWindowSample.cs
5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2011 Xamarin Inc
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
public class ScrollWindowSample: VBox
34
public ScrollWindowSample ()
36
ScrollView v1 = new ScrollView ();
37
VBox b1 = new VBox ();
38
for (int n=0; n<30; n++)
39
b1.PackStart (new Label ("Line " + n), BoxMode.None);
40
Button u = new Button ("Click to remove");
41
u.Clicked += delegate {
47
v1.VerticalScrollPolicy = ScrollPolicy.Always;
48
v1.BorderVisible = false;
49
PackStart (v1, BoxMode.FillAndExpand);
51
ScrollView v2 = new ScrollView ();
52
VBox b2 = new VBox ();
53
for (int n=0; n<10; n++)
54
b2.PackStart (new Label ("Line " + n), BoxMode.None);
56
v2.VerticalScrollPolicy = ScrollPolicy.Never;
57
PackStart (v2, BoxMode.FillAndExpand);
59
ScrollView v3 = new ScrollView ();
60
VBox b3 = new VBox ();
61
Button b = new Button ("Click to add items");
62
b.Clicked += delegate {
63
for (int n=0; n<10; n++)
64
b3.PackStart (new Label ("Line " + n), BoxMode.None);
68
v3.VerticalScrollPolicy = ScrollPolicy.Automatic;
69
PackStart (v3, BoxMode.FillAndExpand);
71
ScrollView v4 = new ScrollView ();
72
PackStart (v4, BoxMode.FillAndExpand);
73
var sb = new ScrollableCanvas ();
75
v4.VerticalScrollPolicy = ScrollPolicy.Always;
79
class ScrollableCanvas: Canvas
81
ScrollAdjustment hscroll;
82
ScrollAdjustment vscroll;
85
public ScrollableCanvas ()
91
protected override void OnDraw (Context ctx, Rectangle dirtyRect)
94
ctx.Translate (-hscroll.Value, -vscroll.Value);
95
ctx.Rectangle (new Rectangle (0, 0, imageSize, imageSize));
96
ctx.SetColor (Xwt.Drawing.Colors.White);
98
ctx.Arc (imageSize / 2, imageSize / 2, imageSize / 2 - 20, 0, 360);
99
ctx.SetColor (new Color (0,0,1));
103
ctx.Rectangle (0, 0, Bounds.Width, 30);
104
ctx.SetColor (new Color (1, 0, 0, 0.5));
108
protected override bool SupportsCustomScrolling {
114
protected override void SetScrollAdjustments (ScrollAdjustment horizontal, ScrollAdjustment vertical)
116
hscroll = horizontal;
119
hscroll.UpperValue = imageSize;
120
hscroll.PageIncrement = Bounds.Width;
121
hscroll.PageSize = Bounds.Width;
122
hscroll.ValueChanged += delegate {
126
vscroll.UpperValue = imageSize;
127
vscroll.PageIncrement = Bounds.Height;
128
vscroll.PageSize = Bounds.Height;
129
vscroll.ValueChanged += delegate {
134
protected override void OnBoundsChanged ()
136
vscroll.PageSize = vscroll.PageIncrement = Bounds.Height;
137
hscroll.PageSize = hscroll.PageIncrement = Bounds.Width;