Mental math of GUI placement + widget tutorial
May 3, 2012 16:55:56 GMT 1
Post by bigbass on May 3, 2012 16:55:56 GMT 1
Bacon has a lot of power you can place things exactly where you want them on the GUI
The GUI part of the code needs to be explained (it uses HUG) so that you can get started with making your own apps
I will be using an example given by rod Gatordog and explaining it in more detail with images
Note: rod was and is a big influence getting me started on BaCon
he is busy with other things in life ATM so I want to carry on with his examples
I was lucky enough to have worked together with him on some coding projects
First example Hello
The code syntax you can learn a little at a time it is easy to read
The mental math however is a hurdle to
get a mental picture of whats going on to understand the exact placement
on the GUI so a careful study is given below
when you see what's happening with this example making your own apps
will be much easier
for this reason I will start off with the mental math part
1.) Create your main working window, 250 pixels wide x 100 pixels high
2. ) Create a label Hello BaCon! with text, 150 x 30
This is not a position "on" the screen
it is the size of the viewable text of Hello BaCon!
if the first number which is the width is less than 150
some of the word Hello BaCon! would be cut from viewing
if the second number was less than 30 which is the height
of the viewable text you would see half of the text displayed
the term MARK is used think of this a writing something
with a marker
3.) Attach the label to the main window pin pointed
at coordinates 50 x 20 that allows centered text
from top left corner starting at
the first letter in the title bar
think of this as pasting an image of the message Hello BaCon!
with glue exactly where you want it
special note text is aligned with the the first letter in the title bar
so if you wanted text to start flush from the left you would
need to use a negative number -30 ,20
4.) Create a button
This is not a position "on" the screen
it is the size of the viewable text of "I'm done"
if the first number which is the width is less than 80
some of the word "I'm done" would be cut from viewing
if the second number was less than 25 which is the height
of the viewable text you would see half of the text displayed
5.) Attach button to the main window pin pointed
at coordinates 10 x 60 that allows text to be
from top left corner starting at zero NO negative numbers
*this is different than the label position rule *
think of this as pasting an image of the message "I'm done"
with glue exactly where you want it
Make button do something
CALLBACK( My_btn, QUIT)
Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY
Done with the math lets move on to real code below
briefly explained full code for easy reading
heavily explained full code
The GUI part of the code needs to be explained (it uses HUG) so that you can get started with making your own apps
I will be using an example given by rod Gatordog and explaining it in more detail with images
Note: rod was and is a big influence getting me started on BaCon
he is busy with other things in life ATM so I want to carry on with his examples
I was lucky enough to have worked together with him on some coding projects
First example Hello
The code syntax you can learn a little at a time it is easy to read
The mental math however is a hurdle to
get a mental picture of whats going on to understand the exact placement
on the GUI so a careful study is given below
when you see what's happening with this example making your own apps
will be much easier
for this reason I will start off with the mental math part
1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "Hello Title Bar", 250, 100 )
2. ) Create a label Hello BaCon! with text, 150 x 30
This is not a position "on" the screen
it is the size of the viewable text of Hello BaCon!
if the first number which is the width is less than 150
some of the word Hello BaCon! would be cut from viewing
if the second number was less than 30 which is the height
of the viewable text you would see half of the text displayed
the term MARK is used think of this a writing something
with a marker
My_label = MARK( "Hello BaCon!", 150, 30 )
3.) Attach the label to the main window pin pointed
at coordinates 50 x 20 that allows centered text
from top left corner starting at
the first letter in the title bar
think of this as pasting an image of the message Hello BaCon!
with glue exactly where you want it
special note text is aligned with the the first letter in the title bar
so if you wanted text to start flush from the left you would
need to use a negative number -30 ,20
ATTACH( Mainwin, My_label, 50, 20 )
4.) Create a button
This is not a position "on" the screen
it is the size of the viewable text of "I'm done"
if the first number which is the width is less than 80
some of the word "I'm done" would be cut from viewing
if the second number was less than 25 which is the height
of the viewable text you would see half of the text displayed
My_btn = BUTTON( "I'm done", 80, 25)
5.) Attach button to the main window pin pointed
at coordinates 10 x 60 that allows text to be
from top left corner starting at zero NO negative numbers
*this is different than the label position rule *
think of this as pasting an image of the message "I'm done"
with glue exactly where you want it
ATTACH( Mainwin, My_btn, 10, 60 )
Make button do something
CALLBACK( My_btn, QUIT)
Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 155, 60 )
Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY
Done with the math lets move on to real code below
briefly explained full code for easy reading
' BaCon / HUG Hello World
' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT
' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "Hello Title Bar", 250, 100 )
' 2. ) Create a label Hello BaCon! with text, 150 x 30
My_label = MARK( "Hello BaCon!", 150, 30 )
' 3.) Attach the label to the main window
ATTACH( Mainwin, My_label, 50, 20 )
' 4.) Create a button
My_btn = BUTTON( "I'm done", 80, 25)
' 5.) Attach button to the main window
ATTACH( Mainwin, My_btn, 10, 60 )
' 6.) Make button do something
CALLBACK( My_btn, QUIT)
'7.) Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 155, 60 )
'8.)Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY
heavily explained full code
' BaCon / HUG Hello World
' Include the files for making a GUI.
INCLUDE "hug.bac"
INIT
' the syntax is easy to grasp. The mental math however is a hurdle to
' get a mental picture of whats going on to understand the exact placement
' on the GUI so a careful study is given below
' 1.) Create your main working window, 250 pixels wide x 100 pixels high
Mainwin = WINDOW( "Hello Title Bar", 250, 100 )
' 2. ) Create a label Hello BaCon! with text, 150 x 30
' This is not a position "on" the screen
' it is the size of the viewable text of Hello BaCon!
' if the first number which is the width is less than 150
' some of the word Hello BaCon! would be cut from viewing
' if the second number was less than 30 which is the height
' of the viewable text you would see half of the text displayed
' the term MARK is used think of this a writing something
' with a marker
My_label = MARK( "Hello BaCon!", 150, 30 )
' 3.) Attach the label to the main window pin pointed
' at coordinates 50 x 20 that allows centered text
' from top left corner starting at
' the first letter in the title bar
' think of this as pasting an image of the message Hello BaCon!
' with glue exactly where you want it
' special note text is aligned with the the first letter in the title bar
' so if you wanted text to start flush from the left you would
' need to use a negative number -30 ,20
ATTACH( Mainwin, My_label, 50, 20 )
' 4.) Create a button
' This is not a position "on" the screen
' it is the size of the viewable text of "I'm done"
' if the first number which is the width is less than 80
' some of the word "I'm done" would be cut from viewing
' if the second number was less than 25 which is the height
' of the viewable text you would see half of the text displayed
My_btn = BUTTON( "I'm done", 80, 25)
' 5.) Attach button to the main window pin pointed
' at coordinates 10 x 60 that allows text
' from top left corner starting at zero
' think of this as pasting an image of the message "I'm done"
' with glue exactly where you want it
' *this is different than the label*
ATTACH( Mainwin, My_btn, 10, 60 )
' 6.)Make button do something
CALLBACK( My_btn, QUIT)
' 7.) Create a button.
My_chk = STOCK("gtk-quit", 80, 25)
ATTACH( Mainwin, My_chk, 155, 60 )
'8.) Make button do something
CALLBACK( My_chk, QUIT)
DISPLAY