github.com/jmigpin/editor@v1.6.0/util/uiutil/widget/xyaxis.go (about)

     1  package widget
     2  
     3  import "image"
     4  
     5  // Allows calculations to be done X oriented, and have it translated to Y axis.
     6  // Useful for layouts that want to layout elements in a vertical or horizontal direction depending on a flag.
     7  type XYAxis struct {
     8  	YAxis bool
     9  }
    10  
    11  type XYAxisBoolPair struct {
    12  	X, Y bool
    13  }
    14  
    15  func (xy *XYAxis) Point(p *image.Point) image.Point {
    16  	if xy.YAxis {
    17  		return image.Point{p.Y, p.X}
    18  	}
    19  	return *p
    20  }
    21  func (xy *XYAxis) Rectangle(r *image.Rectangle) image.Rectangle {
    22  	if xy.YAxis {
    23  		return image.Rect(r.Min.Y, r.Min.X, r.Max.Y, r.Max.X)
    24  	}
    25  	return *r
    26  }
    27  func (xy *XYAxis) BoolPair(bp XYAxisBoolPair) XYAxisBoolPair {
    28  	if xy.YAxis {
    29  		return XYAxisBoolPair{bp.Y, bp.X}
    30  	}
    31  	return bp
    32  }