Re: [shoes] Question about SWT layout
- From:
- Peter Fitzgibbons
- Date:
- 2012-01-20 @ 12:51
HI Ash,
I believe I used
Control#setLocation(x,y)<http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Control.html#setBounds%28int,%20int,%20int,%20int%29>
Unfortunately my refactoring has clobbered some of my code, and I know the
last thing I did before this refactoring was getting the bouncing-button
example working.
I'll keep this in mind as I move along.
Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com
On Fri, Jan 20, 2012 at 4:30 AM, ashbb <ashbbb@gmail.com> wrote:
> Hi Peter and SWT users,
>
> I have a question. :)
>
> I wrote the following snippet and save to a `test1.rb` file and executed
> by `jruby --1.9 test1.rb` on my Windows 7.
>
> # test1.rb
> require 'java'
> require 'swt'
> class Object
> include_package 'org.eclipse.swt'
> include_package 'org.eclipse.swt.layout'
> include_package 'org.eclipse.swt.widgets'
> end
> display = Display.new
> shell = Shell.new display
> shell.setSize 300, 300
> shell.setLayout RowLayout.new
> b = Button.new shell, SWT::PUSH
> b.setText 'Button'
> shell.open
> while !shell.isDisposed do
> display.sleep unless display.readAndDispatch
> end
> display.dispose
>
> The above snippet worked well. I got a button on a window.
> Okay now, I have a question.
>
> How do I move the button to another position (e.g. left: 100, top: 50)?
>
> I can't find a good layout widget... :(
>
> In the case of GTK2, I will write the code like this:
>
> canvas = Gtk::Layout.new
> button = Gtk::Button.new 'Button'
> canvas.put button, 100, 50
>
> Umm,...
> ashbb
>
>
Re: [shoes] Question about SWT layout
- From:
- ashbb
- Date:
- 2012-01-22 @ 02:18
Hi Peter,
> I believe I used Control#setLocation(x,y)
Thank you so much!
I tried to add `b.setLocation 100, 100` like this:
# test1.rb
require 'java'
require 'swt'
class Object
include_package 'org.eclipse.swt'
include_package 'org.eclipse.swt.layout'
include_package 'org.eclipse.swt.widgets'
end
display = Display.new
shell = Shell.new display
shell.setSize 300, 300
shell.setLayout RowLayout.new
b = Button.new shell, SWT::PUSH
b.setText 'Button'
b.setLocation 100, 100
shell.open
while !shell.isDisposed do
display.sleep unless display.readAndDispatch
end
display.dispose
But, umm.... nothing happened...
I don't understand quite basic things...
Anyway, thank you for the information. I'll walk around Control class. ;-)
ashbb
ps.
> the last thing I did before this refactoring was getting the
bouncing-button
> example working.
Awesome! I'd love to see the code. :-D
Re: [shoes] Question about SWT layout
- From:
- ashbb
- Date:
- 2012-01-22 @ 08:42
Hi Peter and folks,
I got it!
# test1.rb
require 'java'
require 'swt'
class Object
include_package 'org.eclipse.swt'
include_package 'org.eclipse.swt.widgets'
end
display = Display.new
shell = Shell.new display
shell.setSize 300, 300
b = Button.new shell, SWT::PUSH
b.setText 'Button'
b.setSize 100, 30
b.setLocation 100, 100
shell.open
while !shell.isDisposed do
display.sleep unless display.readAndDispatch
end
display.dispose
It seems to be necessary to specify both setSize() and setLocation().
ashbb
Re: [shoes] Question about SWT layout
- From:
- Peter Fitzgibbons
- Date:
- 2012-01-22 @ 12:18
HI Ash,
It is not necessary to call both.
Please inspect commit
https://github.com/shoes/brown_shoes/commit/31414188353db7abaa571ae902760a5fa2fa2e13
You'll want to look at :
./lib/shoes/button.rb
./lib/shoes/native.rb
./samples/simple-button-animate.rb
I recall that there was magic both in the Animation code
(./lib/shoes/animation.rb) and the exact incantation around Native#displace.
Happy code-hunting!
Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com
On Sun, Jan 22, 2012 at 2:42 AM, ashbb <ashbbb@gmail.com> wrote:
> Hi Peter and folks,
>
> I got it!
>
>
> # test1.rb
> require 'java'
> require 'swt'
> class Object
> include_package 'org.eclipse.swt'
> include_package 'org.eclipse.swt.widgets'
> end
> display = Display.new
> shell = Shell.new display
> shell.setSize 300, 300
> b = Button.new shell, SWT::PUSH
> b.setText 'Button'
> b.setSize 100, 30
>
> b.setLocation 100, 100
>
> shell.open
> while !shell.isDisposed do
> display.sleep unless display.readAndDispatch
> end
> display.dispose
>
> It seems to be necessary to specify both setSize() and setLocation().
>
> ashbb
>
>
Re: [shoes] Question about SWT layout
- From:
- ashbb
- Date:
- 2012-01-23 @ 13:03
Hi Peter,
> It is not necessary to call both.
Oh, you are right.
The following snippet worked well!
I added `pack`. Right?
# test1.rb
require 'java'
require 'swt'
class Object
include_package 'org.eclipse.swt'
include_package 'org.eclipse.swt.widgets'
end
display = Display.new
shell = Shell.new display
shell.setSize 300, 300
b = Button.new shell, SWT::PUSH
b.setText 'Button'
b.setLocation 100, 100
b.pack
shell.open
while !shell.isDisposed do
display.sleep unless display.readAndDispatch
end
display.dispose
ashbb
Re: [shoes] Question about SWT layout
- From:
- Peter Fitzgibbons
- Date:
- 2012-01-23 @ 15:21
I'm still quite fuzzy on the action of #pack.
There are times when #pack may override your #setLocation.
I'm gaining momentum to write a blog post about this.
If your example worked, then you're well on your way to understanding how
the backend of SWT will work for Shoes.
Peter Fitzgibbons
(847) 859-9550
Email: peter.fitzgibbons@gmail.com
IM GTalk: peter.fitzgibbons
IM AOL: peter.fitzgibbons@gmail.com