github.com/Seikaijyu/gio@v0.0.1/io/system/locale.go (about)

     1  package system
     2  
     3  // Locale provides language information for the current system.
     4  type Locale struct {
     5  	// Language is the BCP-47 tag for the primary language of the system.
     6  	Language string
     7  	// Direction indicates the primary direction of text and layout
     8  	// flow for the system.
     9  	Direction TextDirection
    10  }
    11  
    12  const (
    13  	axisShift = iota
    14  	progressionShift
    15  )
    16  
    17  // TextDirection defines a direction for text flow.
    18  type TextDirection byte
    19  
    20  const (
    21  	// LTR is left-to-right text.
    22  	LTR TextDirection = TextDirection(Horizontal<<axisShift) | TextDirection(FromOrigin<<progressionShift)
    23  	// RTL is right-to-left text.
    24  	RTL TextDirection = TextDirection(Horizontal<<axisShift) | TextDirection(TowardOrigin<<progressionShift)
    25  )
    26  
    27  // Axis returns the axis of the text layout.
    28  func (d TextDirection) Axis() TextAxis {
    29  	return TextAxis((d & (1 << axisShift)) >> axisShift)
    30  }
    31  
    32  // Progression returns the way that the text flows relative to the origin.
    33  func (d TextDirection) Progression() TextProgression {
    34  	return TextProgression((d & (1 << progressionShift)) >> progressionShift)
    35  }
    36  
    37  func (d TextDirection) String() string {
    38  	switch d {
    39  	case RTL:
    40  		return "RTL"
    41  	default:
    42  		return "LTR"
    43  	}
    44  }
    45  
    46  // TextAxis defines the layout axis of text.
    47  type TextAxis byte
    48  
    49  const (
    50  	// Horizontal indicates text that flows along the X axis.
    51  	Horizontal TextAxis = iota
    52  	// Vertical indicates text that flows along the Y axis.
    53  	Vertical
    54  )
    55  
    56  // TextProgression indicates how text flows along an axis relative to the
    57  // origin. For these purposes, the origin is defined as the upper-left
    58  // corner of coordinate space.
    59  type TextProgression byte
    60  
    61  const (
    62  	// FromOrigin indicates text that flows along its axis away from the
    63  	// origin (upper left corner).
    64  	FromOrigin TextProgression = iota
    65  	// TowardOrigin indicates text that flows along its axis towards the
    66  	// origin (upper left corner).
    67  	TowardOrigin
    68  )