O1Library Docs
Fall 2026
Docs API

# o1.gui

package o1.gui

## Members list

### Packages

package o1.gui.colors
package o1.gui.event
package o1.gui.font
package o1.gui.layout
package o1.gui.viewimpl

### Type members

#### Classlikes

object Align

The `Align` singleton provides tools for describing the horizontal and vertical alignment of graphical elements.

The `Align` singleton provides tools for describing the horizontal and vertical alignment of graphical elements.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Align.type

final class Animation(frames: Iterable[Pic], val frameRate: Double, val terminateOnClose: Boolean, val atEnd: AtEnd)

An `Animation` object has an iterable sequence of Pics which it can show in a separate window (a simple View).

An `Animation` object has an iterable sequence of Pics which it can show in a separate window (a simple View).

## Parameters

atEnd

  what should happen once the animation reaches the final Pic

frameRate

  a target speed (in Pics per second), which the `Animation` will roughly observe if possible

frames

  the Pics that the animation consists of, in order; they should be identical in size

terminateOnClose

  whether the entire application should exit when the animation window is closed

## Attributes

Companion
  object
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Animation

object Animation

This companion object of class Animation provides a couple of convenience methods (show, generate) for starting animations and an enumeration (AtEnd) for use with the class.

This companion object of class Animation provides a couple of convenience methods (show, generate) for starting animations and an enumeration (AtEnd) for use with the class.

## Attributes

Companion
  class
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Animation.type

final class Color extends Fill

Each instance of this class represents a color. The class uses the RGB color scheme: each color is a combination of a red, green, and blue components; there’s also a fourth component of opacity. `Color` objects are immutable.

Each instance of this class represents a color. The class uses the RGB color scheme: each color is a combination of a red, green, and blue components; there’s also a fourth component of opacity. `Color` objects are immutable.

You don’t instantiate `Color` directly; instead, you create `Color`s with the methods on the `Color` companion object (e.g., `Color(200, 150, 255)`) or use one of the named color constants in o1.gui.colors. There are also a few methods in this class that returns new Color objects defined in terms of existing ones (e.g., lighter, edit).

This class has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`.

## Parameters

blue

  the amount of blue in the color, between Color.Min and Color.Max; that is, 0–255

green

  the amount of green in the color, between Color.Min and Color.Max; that is, 0–255

opacity

  the color’s opacity, between Color.Min and Color.Max; that is, 0–255

presetName

  the name of a color contant in “regular form”, i.e., with spaces and largely in lower case (e.g., "saddle blue", "Irish green")

red

  the amount of red in the color, between Color.Min and Color.Max; that is, 0–255

## Attributes

Companion
  object
Supertypes
  trait Fill
  class Object
  trait Matchable
  class Any

object Color

This companion object of class `Color` provides methods for creating new `Color` objects. There is also a small selection of related utility methods and constants.

This companion object of class `Color` provides methods for creating new `Color` objects. There is also a small selection of related utility methods and constants.

For many constants of type Color that represent different preset colors, see o1.gui.colors.

This object has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`.

## Attributes

Companion
  class
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Color.type

trait DefaultFrameSettings extends Frame

Giving this convenience trait to a Swing GUI frame will place the frame at (120, 120) and set it as unresizeable.

Giving this convenience trait to a Swing GUI frame will place the frame at (120, 120) and set it as unresizeable.

## Attributes

Supertypes
  class Frame
  trait RichWindow
  class Window
  trait RootPanel
  trait Container
  trait UIElement
  trait Publisher
  trait Reactor
  trait Proxy
  class Object
  trait Matchable
  class Any
  Show all
Known subtypes
  class SimpleFrame

object Dialog

This object provides convenience methods for displaying messages and reading user input via simple Swing dialogs.

This object provides convenience methods for displaying messages and reading user input via simple Swing dialogs.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Dialog.type

trait Escapable extends Frame

Give this convenience trait to a Swing GUI frame to make it close when the Escape key is pressed.

Give this convenience trait to a Swing GUI frame to make it close when the Escape key is pressed.

## Attributes

Supertypes
  class Frame
  trait RichWindow
  class Window
  trait RootPanel
  trait Container
  trait UIElement
  trait Publisher
  trait Reactor
  trait Proxy
  class Object
  trait Matchable
  class Any
  Show all

trait Fill

A supertype for objects that “can be used as paint” to define the fill color(s) of a shape. The simplest sort of fill is a Color, but gradients and other more complex fills may also be defined.

A supertype for objects that “can be used as paint” to define the fill color(s) of a shape. The simplest sort of fill is a Color, but gradients and other more complex fills may also be defined.

## Attributes

Companion
  object
Supertypes
  class Object
  trait Matchable
  class Any
Known subtypes
  class Color
  object None

object Fill

This companion object of class Fill provides a singleton object for the special case where there is no fill at all.

This companion object of class Fill provides a singleton object for the special case where there is no fill at all.

## Attributes

Companion
  trait
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Fill.type

object Line

The `Line` singleton provides tools for specifying what a line-drawing style — a Stroke — is like.

The `Line` singleton provides tools for specifying what a line-drawing style — a Stroke — is like.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Line.type

final class Pic extends HasAnchor

Each instance of this class represents a picture: an immutable two-dimensional image.

Each instance of this class represents a picture: an immutable two-dimensional image.

You don’t instantiate `Pic` directly; instead, you create `Pic`s with the methods on the `Pic` companion object. For instance, you can:

- load existing images: `Pic("mypic.png")` or `Pic("http://address.of/mypic.png")`),
- create `Pic`s of shapes (e.g., `circle(150, Red)` or `star(100, Black)`); or
- generate the pixels of a `Pic` with a function.

Moreover, many of the methods of a `Pic` object create and return new `Pic`s that represent combinations or transformations of existing `Pic`s.

This class has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`.

The examples below illustrate a few of the methods (assuming the above import):

    val background = rectangle(400, 300, Red)
    val rotatedSquare = square(50, Blue).clockwise(30)
    val squareAgainstBg = background.place(rotatedSquare, Pos(100, 100))
    squareAgainstBg.show()

    val ladybug = Pic("ladybug.png").scaleTo(100).flipHorizontal
    val combination = circle(100, Red).leftOf(ladybug)
    val part = combination.crop(Pos(10, 10), 180, 80)
    val negative = part.transformColors( _.negative )
    negative.show()

Some of the methods of a `Pic` that use Pos objects or plain x and y coordinates to indicate positions within the `Pic` (e.g., `place` and `crop` above). All these methods consider the origo to be at the top left-hand corner or the `Pic`, with x values increasing downwards and y values rightwards. The coordinates are in pixels.

Each image has an anchor that defines where it connects to other `Pic`s. By default, the anchor is Center; for example, the `place` method call above puts the center of the square at `Pos(100, 100)` within the background.

Here is a list of the main types of operations as methods on a `Pic`, and examples of each type:

- Combining `Pic`s by positioning them relative to each other: `above`, `below`, `leftOf`, `rightOf`, `onto`, `against`, `place`.

- Rotations (*): `clockwise`, `counterclockwise`

- Changing size (*): `scaleBy`, `scaleTo`

- Selecting and moving pixels (**): `crop`, `shift`, `flipHorizontal`, `flipVertical`

- Examining and manipulating individual pixels (**): `pixelColor`, `transformXY`, `transformColors`, `combine`

- Convenience methods for experimentation and debugging: `show`, `hide`.

### Notes on implementation and efficiency:

Internally, a `Pic` stores its contents either as vector-based graphics, as a bitmap (raster), or as a combination of the two. By design, that internal representation is meant to be largely opaque to the user of the `Pic` class: students in O1 working on O1’s standard assignments generally shouldn’t need to know or care about it. Nevertheless, whether a particular `Pic` is stored in vector or bitmap form does have a very substantial effect on efficiency in some contexts; `Pic`, like the rest of O1Library, is not designed for high-performance graphics.

Some users of this class may wish to know the following:

- `Pic`s start out in either vector form or bitmap form, depending on which method created them. Specifically, the shape-creating methods (like `rectangle` and `circle`). produce `Pic`s in vector form.

- No operation on a `Pic` ever changes an already rasterized bitmap into vector graphics.

- Some operations always produce a rasterized `Pic`. These are marked with a double asterisk (**) in the list above. Some operations sometimes produce rasterized `Pic`s but may retain the vector-based representation in simple cases. These are marked with a single asterisk (*).

- Operations like `leftOf` can produce a `Pic` that is stored as a combination of a vector graphic and a bitmap.

- You can call freeze to force rasterization.

## Attributes

Companion
  object
Supertypes
  trait HasAnchor
  trait HasSize
  class Object
  trait Matchable
  class Any

object Pic

The primary purpose of this companion object of class `Pic` is to provide methods for creating new Pic instances: (apply, generate, circle, etc. There is also a small selection of related utility methods.

The primary purpose of this companion object of class `Pic` is to provide methods for creating new Pic instances: (apply, generate, circle, etc. There is also a small selection of related utility methods.

This object has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`. The shape-creating methods of this object (such as `circle`) are also available as functions in package o1.

## Attributes

Companion
  class
Supertypes
  class Object
  trait Matchable
  class Any
Self type
  Pic.type

open class SimpleFrame(initialTitle: String) extends Frame, DefaultFrameSettings

Inherit this class to obtain a Swing GUI frame that has the DefaultFrameSettings and the given title.

Inherit this class to obtain a Swing GUI frame that has the DefaultFrameSettings and the given title.

## Attributes

Supertypes
  trait DefaultFrameSettings
  class Frame
  trait RichWindow
  class Window
  trait RootPanel
  trait Container
  trait UIElement
  trait Publisher
  trait Reactor
  trait Proxy
  class Object
  trait Matchable
  class Any
  Show all

sealed class Stroke(val fill: Fill, val thickness: Double = ..., val cap: Cap = ..., val join: Join = ..., val onTop: Boolean = ...)

A `Stroke` is a style for drawing shape outlines and other lines. A `Stroke` object defines, among other things, the color and width of lines drawn using the stroke.

A `Stroke` is a style for drawing shape outlines and other lines. A `Stroke` object defines, among other things, the color and width of lines drawn using the stroke.

## Parameters

cap

  the style of the cap (end point) for lines drawn using this stroke; the default is a square cap.

fill

  a fill style for lines drawn using this stroke; this can be a Color or a gradient, for example

join

  the style in which lines drawn using this stroke join up with each other; the default is a miter join

onTop

  a value that affects filled shapes that have an outline drawn using this stroke: if `true`, the outline will be drawn on top of the filled shape and fully visible; if `false`, the outline will be below the fill and partially invisible. Defaults to `true`.

thickness

  the width of lines drawn using this stroke; defaults to 1

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Known subtypes
  object None

trait TerminatesOnClose extends Window

Give this convenience trait to a Swing GUI frame to make it terminate the application when closed.

Give this convenience trait to a Swing GUI frame to make it terminate the application when closed.

## Attributes

Supertypes
  class Window
  trait RootPanel
  trait Container
  trait UIElement
  trait Publisher
  trait Reactor
  trait Proxy
  class Object
  trait Matchable
  class Any
  Show all

object View

This object holds miscellaneous utilities (traits, constants, etc.) that can be used in combinations with `View`s. These utilities are generic to the o1.gui.mutable and o1.gui.immutable `View` variants.

This object holds miscellaneous utilities (traits, constants, etc.) that can be used in combinations with `View`s. These utilities are generic to the o1.gui.mutable and o1.gui.immutable `View` variants.

Note to students: You’re unlikely to need this for anything in O1.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Self type
  View.type

object swingops

Life-quality improvements for working with the Swing GUI library in Scala.

Life-quality improvements for working with the Swing GUI library in Scala.

## Attributes

Supertypes
  class Object
  trait Matchable
  class Any
Self type
  swingops.type

#### Types

type Anchor = Anchor

The `Anchor` type represents anchoring points of two-dimensional elements (such as Pics) within other such elements; it is an alias for the type of the same name in `o1.world.objects`.

The `Anchor` type represents anchoring points of two-dimensional elements (such as Pics) within other such elements; it is an alias for the type of the same name in `o1.world.objects`.

## Attributes

type Bounds = Bounds

The `Bounds` type represents rectangular boundaries on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

The `Bounds` type represents rectangular boundaries on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

## Attributes

type HasAnchor = HasAnchor

A supertype for two-dimensional elements that have an anchoring point; this is an alias for the trait of the same name in `o1.world.objects`.

A supertype for two-dimensional elements that have an anchoring point; this is an alias for the trait of the same name in `o1.world.objects`.

## Attributes

type Key = scala.swing.event.Key

The `Key` type represents keys on the keyboard; it is an alias for the corresponding type in Scala’s Swing GUI library

The `Key` type represents keys on the keyboard; it is an alias for the corresponding type in Scala’s Swing GUI library

## Attributes

type Pos = Pos

The `Pos` type represents locations on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

The `Pos` type represents locations on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

## Attributes

### Value members

#### Concrete fields

val Anchor: Anchor.type

The `Anchor` type represents anchoring points of two-dimensional elements (such as Pics) within other such elements; it is an alias for the type of the same name in `o1.world.objects`.

The `Anchor` type represents anchoring points of two-dimensional elements (such as Pics) within other such elements; it is an alias for the type of the same name in `o1.world.objects`.

## Attributes

val Bounds: Bounds.type

The `Bounds` type represents rectangular boundaries on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

The `Bounds` type represents rectangular boundaries on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

## Attributes

val Key: Key.type

The `Key` type represents keys on the keyboard; it is an alias for the corresponding type in Scala’s Swing GUI library

The `Key` type represents keys on the keyboard; it is an alias for the corresponding type in Scala’s Swing GUI library

## Attributes

val Pos: Pos.type

The `Pos` type represents locations on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

The `Pos` type represents locations on a two-dimensional plane; it is an alias for the class of the same name in `o1.world`.

## Attributes

var isInTestMode: Boolean