The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Finishing Up

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Finishing Up Posted: Sep 12, 2007 3:02 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Finishing Up
Feed Title: Pollock
Feed URL: http://www.cincomsmalltalk.com/rssBlog/pollock-rss.xml
Feed Description: Pollock - the next VW GUI
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Pollock

Advertisement

M - I - CEEEEE

It seemed only appropriate that I finish the ScrollingCanvas discussion.

People wanted to know how to have a Canvas that they could scroll.

But there is a secret I have been hiding since the very beginning. There was no need to make a special Canvas like pane with scrollbars!

I undertook the discussion since it would reveal the workings of borders and interior decorations. In particular, the details of how a custom widget creator would add scrollbar support to a new pane. As we already saw, there is a lot of work to do, and there was a bunch more to go... Probably about 3 or 4 postings worth.

But those details are now moot.

K - E - YIIIIIII

Never fear though. For those who want to do this or something similar with Widgetry here is the secret I was hiding:

You can already do this with a Form and a Canvas!

You see, a Form already has a #contentsExtent:. Just like we were starting to put on our ScrollingCanvas!

So, all one has to do is create a Form with a

#contentsExtent

, put a Canvas inside it with its frame fully attached, and then do some simple drawing calculations.

M - O - U - S - EEEEE

Here's the code:

	Smalltalk defineClass: #ScrollingCanvasFormWork
		superclass: #{Widgetry.UserInterface}
		indexedType: #none
		private: false
		instanceVariableNames: 'form canvas '
		classInstanceVariableNames: ''
		imports: 'private Widgetry.*'
		category: '(none)'

Standard stuff there.

	createInterface

		form := Form new.
		form frame: (FractionalFrame
			fractionLeft: 0.05
			right: 0.95
			top: 0.05
			bottom: 0.95).
		self addComponent: form.
		canvas := Canvas new.
		canvas frame: FractionalFrame fullyAttached.
		form addComponent: canvas.

See that? I created the Canvas, gave it a FractionalFrame, fully attached, and put it in the Form.

	hookupInterface

		form contentsExtent: 500 @ 500.
		form allScrollbars: true.
		canvas drawActionBlock:
			[:aGraphicsContext :pane |
			| oldLineWidth oldPaint offset enclosingForm |
			enclosingForm := pane enclosingPane.
			offset := pane scrolledOffset negated.
			oldLineWidth := aGraphicsContext lineWidth.
			oldPaint := aGraphicsContext paint.
			aGraphicsContext lineWidth: 5.
			aGraphicsContext paint: ColorValue red.
			aGraphicsContext 
				displayLineFrom: offset 
				to: offset + enclosingForm contentsExtent.
			aGraphicsContext lineWidth: 10.
			aGraphicsContext paint: ColorValue blue.
			aGraphicsContext \
				displayLineFrom: (offset x @ (offset y + pane enclosingPane contentsExtent y)) 
				to: (offset x + pane enclosingPane contentsExtent x @ offset y).
			aGraphicsContext paint: oldPaint.
			aGraphicsContext lineWidth: oldLineWidth].

Here I tell the Form to have a big contentsExtent... Just like we were doing with our ScrolledCanvas.

In our drawActionBlock: we get the enclosing pane, the Form, so we can get its contentsExtent. Then we get the Canvas' #scrolledOffset.

When you are in any pane, you can ask it what its #scrolledOffset is. That value is 0 @ 0 when the pane is just in a window. But if it is in a Form, or in a Form in a Form, the value will be the total amount of scroll offset that any higher enclosing forms may be affecting the pane in any way.

The #scrolledOffset is always a value less than or equal to 0 @ 0. Why we get and use the negated value is an important but now boring detail.

Here it is in action:

Good Night Boys And Girls

Well, that's it! No more blog postings about Widgetry. No more blogging for me at all.

I personally feel that Widgetry was and is a success. Unfortunately we never had enough resources to get it out sooner, nor in June when it went 1.0, enough resources to create the Tools to support it.

Widgetry is now part of that statistic of projects that have failed. Not because of technical merit, but due to wider circumstances.

And So It Goes
Sames

Read: Finishing Up

Topic: Office App Competition Previous Topic   Next Topic Topic: Reading Smalltalk

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use