The Green Shoes Manual 1.1.362

The Styles Master List

You want to mess with the look of things? Well, throughout Green Shoes, styles are used to change the way elements appear. In some cases, you can even style an entire class of elements. (Like giving all links without an underline.)

Styles are easy to spot. They usually show up when the element is created.

 Shoes.app title: "A Styling Sample" do
   para 'Green Shoes', align: 'center', size: 50
 end

Here we've got a :title style on the app. And on the paragraph inside the app, a center :align style and 50 font :size style.

The style hash can also be changed by using the style method, available on every element and slot.

Note: Green Shoes can change style hash on Shape element only so far.

 Shoes.app title: "A Styling Sample" do
   choose = 
     lambda{[red, blue, green, yellow].sample}
   s = star 100, 50, 30, 200, 180, strokewidth: 5
   button 'change colors' do
     s.style stroke: choose.call, fill: choose.call
   end
 end

Most styles can also be set by calling them as methods. (I'd use the manual search to find the method.)

Note: Green Shoes doesn't support them as methods.

 # Not yet available
 Shoes.app title: "A Styling Sample" do
   choose = 
     lambda{[red, blue, green, yellow].sample}
   s = star 100, 50, 30, 200, 180, strokewidth: 5
   button 'change colors' do
     s.stroke = choose.call; s.fill = choose.call
   end
 end

Rather than making you plow through the whole manual to figure out what styles go where, this helpful page speeds through every style in Green Shoes and suggests where that style is used.

:align » a string

For: banner, caption, inscription, para, subtitle, tagline, title

The alignment of the text. It is either:

:angle » a number

For: background, border, line, oval, rect, shape, star.

The angle at which to apply a gradient. Normally, gradient colors range from top to bottom. If the :angle is set to 90, the gradient will rotate 90 degrees counter-clockwise and the gradient will go from left to right.

:attach » a slot or element

For: flow, stack.

Pins a slot relative to another slot or element. Also, one may write :attach => Window to position the slot at the window's top, left corner. Taking this a bit further, the style :top => 10, :left => 10, :attach => Window would place the slot at (10, 10) in the window's coordinates.

If a slot is attached to an element that moves, the slot will move with it. If the attachment is reset to nil, the slot will flow in with the other objects that surround, as normal.

Note: Green Shoes doesn't support :attach style.

:autoplay » true or false

For: video.

Should this video begin playing after it appears? If set to true, the video will start without asking the user.

Note: Green Shoes doesn't support video.

:back » true or false

For: shapes, image, textblocks.

Comes to the back of the other elements.

 Shoes.app do
   rect 100, 100, 100, 100, fill: green
   rect 120, 120, 100, 100, fill: yellow
   para 'hello', left: 150, top: 150, front: true
   oval 150, 150, 100, 100, fill: red
   oval 180, 180, 100, 100, fill: gray, back: true
 end
:bottom » a number

For: all slots and elements.

Sets the pixel coordinate of an element's lower edge. The edge is placed relative to its container's lower edge. So, :bottom => 0 will align the element so that its bottom edge and the bottom edge of its slot touch.

Note: Green Shoes doesn't support :bottom style.

:cap » :curve or :rect or :project

For: arc, line, shape.

Sets the shape of the line endpoint, whether curved or square. See the cap method for more explanation.

:center » true or false

For: arc, image, oval, rect, shape.

Indicates whether the :top and :left coordinates refer to the center of the shape or not. If set to true, this is similar to setting the transform method to :center.

Note: Green Shoes doesn't support :center style.

:change » a proc

For: edit_box, edit_line, list_box.

The change event handler is stored in this style. See the change method for the edit_box, as an example.

:checked » true or false

For: check, radio.

Is this checkbox or radio button checked? If set to true, the box is checked. Also see the checked= method.

:choose » a string

For: list_box.

Sets the currently chosen item in the list. More information at choose.

:click » a proc

For: arc, arrow, button, check, flow, image, line, link, oval, radio, rect, shape, stack, star.

The click event handler is stored in this style. See the click method for a description.

:curve » a number

For: background, border, rect.

The radius of curved corners on each of these rectangular elements. As an example, if this is set to 6, the corners of the rectangle are given a curve with a 6-pixel radius.

:displace_left » a number

For: all slots and elements.

Moves a shape, text block or any other kind of object to the left or right. A positive number displaces to the right by the given number of pixels; a negative number displaces to the left. Displacing an object doesn't effect the actual layout of the page. Before using this style, be sure to read the displace docs, since its behavior can be a bit surprising.

Note: Green Shoes doesn't support :displace_left style.

:displace_top » a number

For: all slots and elements.

Moves a shape, text block or any other kind of object up or down. A positive number moves the object down by this number of pixels; a negative number moves it up. Displacing doesn't effect the actual layout of the page or the object's true coordinates. Read the displace docs, since its behavior can be a bit surprising.

Note: Green Shoes doesn't support :displace_top style.

:emphasis » a string

For: banner, caption, inscription, para, span, subtitle, tagline, title.

Styles the text with an emphasis (commonly italicized.)

This style recognizes three possible settings:

:family » a string

For: banner, caption, inscription, para, span, subtitle, tagline, title.

Styles the text with a given font family. The string should contain the family name or a comma-separated list of families.

:fill » a hex code, a rgb array or a range of either

For: background, banner, border, caption, inscription, para, line, oval, rect, shape, star, subtitle, tagline, title.

The color of the background pen. For shapes, this is the fill color, the paint inside the shape. For textblock, this color is painted in the background (as if marked with a highlighter pen.)

:font » a string

For: banner, caption, inscription, para, subtitle, tagline, title.

Styles the text with a font description. The string is pretty flexible, but can take the form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is a comma separated list of families optionally terminated by a comma, STYLE_OPTIONS is a whitespace separated list of words where each WORD describes one of style, variant, weight, stretch, or gravity, and SIZE is a decimal number (size in points) or optionally followed by the unit modifier "px" for absolute size. Any one of the options may be absent. If FAMILY-LIST is absent, then the default font family (Arial) will be used.

:front » true or false

For: shapes, image, textblocks.

Comes to the front of the other elements.

:group » a string

For: radio.

Indicates what group a radio button belongs to. Without this setting, radio buttons are grouped together with other radio buttons in their immediate slot. "Grouping" radio buttons doesn't mean they'll be grouped next to each other on the screen. It means that only one radio button from the group can be selected at a time.

By giving this style a string, the radio button will be grouped with other radio buttons that have the same group name.

:height » a number

For: all slots and elements.

Sets the pixel height of this object. If the number is a decimal number, the height becomes a percentage of its parent's height (with 0.0 being 0% and 1.0 being 100%.)

:hidden » true or false

For: all slots and elements.

Hides or shows this object. Any object with hidden: true are not displayed on the screen. Neither are its children.

 Shoes.app do
   slot = stack hidden: true do
     title 'hello'
     flow do
       image File.join DIR, '../samples/loogink.png'
     end
     para link('Go go!'){alert 'hi'}
   end
   timer(2){slot.show}
   timer(5){slot.hide}
 end

Note: Green Shoes supports :hidden style for only slots, shapes, textblocks and images so far.

:inner » a number

For: star.

The size of the inner radius (in pixels.) The inner radius describes the solid circle within the star where the points begin to separate.

:items » an array

For: list_box.

The list of selections in the list box. See the list_box method for an example.

:justify » true or false

For: banner, caption, inscription, para, subtitle, tagline, title.

Evenly spaces the text horizontally.

:kerning » a number

For: banner, caption, code, del, em, ins, inscription, link, para, span, strong, sub, sup, subtitle, tagline, title.

Adds to the natural spacing between letters, in pixels.

Note: Green Shoes doesn't support :kerning style.

:leading » a number

For: banner, caption, inscription, para, subtitle, tagline, title.

Sets the spacing between lines in a text block. Defaults to 4 pixels.

:left » a number

For: all slots and elements.

Sets the left coordinate of this object to a specific pixel. Setting left: 10 places the object's left edge ten pixels away from the left edge of the slot containing it. If this style is left unset (or set to nil,) the object will flow in with the other objects surrounding it.

:margin » a number or an array of four numbers

For: all slots and elements.

Margins space an element out from its surroundings. Each element has a left, top, right, and bottom margin. If the :margin style is set to a single number, the spacing around the element uniformly matches that number. In other words, if margin: 8 is set, all the margins around the element are set to eight pixels in length.

This style can also be given an array of four numbers in the form [left, top, right, bottom].

:margin_bottom » a number

For: all slots and elements.

Sets the bottom margin of the element to a specific pixel size.

:margin_left » a number

For: all slots and elements.

Sets the left margin of the element to a specific pixel size.

:margin_right » a number

For: all slots and elements.

Sets the right margin of the element to a specific pixel size.

:margin_top » a number

For: all slots and elements.

Sets the top margin of the element to a specific pixel size.

:outer » a number

For: star.

Sets the outer radius (half of the total width) of the star, in pixels.

:points » a number

For: star.

How many points does this star have? A style of points: 5 creates a five-pointed star.

:radius » a number

For: oval.

Sets the radius (half of the diameter or total width) for each of these elements. Setting this is equivalent to setting both :width and :height to double this number.

:right » a number

For: all slots and elements.

Sets the pixel coordinate of an element's right edge. The edge is placed relative to its container's rightmost edge. So, :right => 0 will align the element so that its own right edge and the right edge of its slot touch. Whereas :right => 20 will position the right edge of the element off to the left of its slot's right edge by twenty pixels.

Note: Green Shoes doesn't support :right style.

:rise » a number

For: banner, caption, inscription, para, span, subtitle, tagline, title.

Lifts or plunges the font baseline for some text. For example, a sup has a :rise of 10 pixels. Conversely, the sub element has a :rise of -10 pixels.

:scroll » true or false

For: flow, stack.

Establishes this slot as a scrolling slot. If :scroll => true is set, the slot will show a scrollbar if any of its contents go past its height. The scrollbar will appear and disappear as needed. It will also appear inside the width of the slot, meaning the slot's width will never change, regardless of whether there is a scrollbar or not.

Note: Green Shoes has restrictions. :scroll style is just a trial so far.

 Shoes.app do
   s = stack left: 100, top: 50, width: 300, 
     height: 100, scroll: true do
     background gold
     image File.join(DIR, '../samples/loogink.png')
     10.times{para 'hello'}
     flush
   end
 end
:secret » true or false

For: ask, edit_line.

Used for password fields, this setting keeps any characters typed in from becoming visible on the screen. Instead, a replacement character (such as an asterisk) is show for each letter typed.

:size » a number

For: banner, caption, inscription, para, span, subtitle, tagline, title.

Sets the pixel size for the font used inside this text block.

Font size may also be augmented, through use of the following strings:

:state » a string

For: button, check, edit_box, edit_line, list_box, radio.

The :state style is for disabling or locking certain controls, if you don't want them to be edited.

Here are the possible style settings:

:stretch » a string

For: banner, caption, code, del, em, ins, inscription, link, para, span, strong, sub, sup, subtitle, tagline, title.

Sets the font stretching used for a text object.

Possible settings are:

Note: Green Shoes doesn't support :stretch style.

:strikecolor » a RGB array

For: banner, caption, inscription, para, span, subtitle, tagline, title.

The color used to paint any lines stricken through this text.

:strikethrough » a string

For: banner, caption, inscription, para, span, subtitle, tagline, title.

Is this text stricken through? Two options here:

:stroke » a hex code, a rgb array or a range of either

For: background, banner, border, caption, inscription, para, line, oval, rect, shape, star, subtitle, tagline, title.

The color of the foreground pen. In the case of shapes, this is the color the lines are drawn with. For textblock, the letters are printed in this color.

:strokewidth » a number

For: background, border, line, oval, rect, shape, star.

The thickness of the stroke, in pixels, of the line defining each of these shapes. For example, the number two would set the strokewidth to 2 pixels.

:text » a string

For: edit_box, edit_line.

Sets the message displayed on the contents of edit_box or edit_line.

:top » a number

For: all slots and elements.

Sets the top coordinate for an object, relative to the top slot (window). If an object is set with top: 40, this means the object's top edge will be placed 40 pixels beneath the top edge of the top slot (window). If no :top style is given, the object is automatically placed in the natural flow of the slot it contains.

:undercolor » a RGB array

For: banner, caption, inscription, para, span, subtitle, tagline, title.

The color used to underline text.

:underline » a string

For: banner, caption, inscription, para, span, subtitle, tagline, title.

Dictates the style of underline used in the text.

The choices for this setting are:

:variant » a string

For: banner, caption, code, del, em, ins, inscription, link, para, span, strong, sub, sup, subtitle, tagline, title.

Vary the font for a group of text. Two choices:

Note: Green Shoes doesn't support :variant style.

:weight » a string

For: banner, caption, inscription, para, span, subtitle, tagline, title.

Set the boldness of the text. Commonly, this style is set to one of the following strings:

However, you may also pass in the numerical weight directly.

:width » a number

For: all slots and elements.

Sets the pixel width for the element. If the number is a decimal, the width is converted to a percentage (with 0.0 being 0% and 1.0 being 100%.) A width of 100% means the object fills its parent slot.

:wrap » a string

For: banner, caption, inscription, para, span, subtitle, tagline, title.

How should the text wrap when it fills its width? Possible options are:

Next: Classes List