Commit 0d7aec6a authored by h2b's avatar h2b

Layout package started.

parent b6025fc7
/*
SimGraf - A Simple Scala Graphics Library
Copyright 2016-2017 Hans-Hermann Bode
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package de.h2b.scala.lib.simgraf.layout
import de.h2b.scala.lib.simgraf.Pixel
/**
* A rectangular area.
*
* The horizontal axis is oriented from left to right, while the vertical axis
* is oriented from top to bottom.
*
* @since 1.1.0
* @author h2b
*/
class Cell private (private val width: Int, private val height: Int) {
import Cell.HorizontalOrientation._
import Cell.VerticalOrientation._
/**
* Returns the top-left pixel position of a rectangular area with specified
* dimensions and orientation within this cell.
*
* @param w the width of of the area to be fitted in
* @param h the height of of the area to be fitted in
* @param o the orientation of of the area to be fitted in within this cell
* @return the resulting top-left pixel position
*/
def fit (w: Int, h: Int, o: Cell.Orientation): Pixel = {
var x = 0
var y = 0
o.horizontal match {
case Left x = 0
case HCenter x = (width -w)/2
case Right width-w
}
o.vertical match {
case Top y = 0
case VCenter (height-h)/2
case Bottom height-h
}
Pixel(x, y)
}
}
object Cell {
object HorizontalOrientation extends Enumeration {
type HorizontalOrientation = Value
val Left, HCenter, Right = Value
}
import HorizontalOrientation._
object VerticalOrientation extends Enumeration {
type VerticalOrientation = Value
val Top, VCenter, Bottom = Value
}
import VerticalOrientation._
class Orientation (val horizontal: HorizontalOrientation, val vertical: VerticalOrientation)
object Orientation {
def apply (horizontal: HorizontalOrientation, vertical: VerticalOrientation) =
new Orientation(horizontal, vertical)
}
val defaultOrientation = Orientation(HCenter, VCenter)
def apply (width: Int, height: Int) = new Cell(width, height)
}
/*
SimGraf - A Simple Scala Graphics Library
Copyright 2016-2017 Hans-Hermann Bode
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package de.h2b.scala.lib.simgraf
/**
* A package collecting some tools for positioning elements on the screen.
*
* @since 1.1.0
* @author h2b
*/
package object layout
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment