Class: Tuile::Component::Layout::Insets
- Inherits:
-
Object
- Object
- Tuile::Component::Layout::Insets
- Defined in:
- lib/tuile/component/layout.rb,
sig/tuile.rbs
Overview
Per-edge padding for a Box, in cells:
Insets[top: 1] # one blank row above the children
Insets[top: 1, left: 2, right: 2] # unnamed edges default to 0
Insets.coerce(1) # uniform on all four edges
Keyword-only: AWT and JavaFX order these same four numbers differently, so a positional form would be a coin flip.
Constant Summary collapse
- ZERO =
No padding on any edge.
new
Instance Attribute Summary collapse
-
#bottom ⇒ Integer
readonly
@return — cells inset from the bottom edge.
-
#left ⇒ Integer
readonly
@return — cells inset from the left edge.
-
#right ⇒ Integer
readonly
@return — cells inset from the right edge.
-
#top ⇒ Integer
readonly
@return — cells inset from the top edge.
Class Method Summary collapse
-
.[](*positional, **kwargs) ⇒ Insets
Needed because
Data's inherited[]never dispatches through anewoverride, so the guard above alone would missInsets[1, 2, 3, 4]. -
.coerce(value) ⇒ Insets
@param
value— an Integer becomes a uniform inset. -
.new(*positional, **kwargs) ⇒ Insets
@param
positional— must be empty — see the class doc.
Instance Method Summary collapse
-
#horizontal ⇒ Integer
@return —
left+right. -
#initialize(top: 0, right: 0, bottom: 0, left: 0) ⇒ Object
constructor
@param
top— cells inset from the top edge;>= 0. -
#vertical ⇒ Integer
@return —
top+bottom.
Constructor Details
#initialize(top: 0, right: 0, bottom: 0, left: 0) ⇒ Object
@param top — cells inset from the top edge; >= 0.
@param right — cells inset from the right edge; >= 0.
@param bottom — cells inset from the bottom edge; >= 0.
@param left — cells inset from the left edge; >= 0.
148 149 150 151 152 153 154 155 156 |
# File 'lib/tuile/component/layout.rb', line 148 def initialize(top: 0, right: 0, bottom: 0, left: 0) { top:, right:, bottom:, left: }.each do |edge, cells| unless cells.is_a?(Integer) && !cells.negative? raise ArgumentError, "Insets #{edge}: expected a non-negative Integer, got #{cells.inspect}" end end super end |
Instance Attribute Details
#bottom ⇒ Integer (readonly)
@return — cells inset from the bottom edge.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/tuile/component/layout.rb', line 112 class Insets < Data.define(:top, :right, :bottom, :left) # @param positional [Array] must be empty — see the class doc. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.new(*positional, **kwargs) raise ArgumentError, "Insets is keyword-only, got #{positional.inspect}" unless positional.empty? super(**kwargs) end # Needed because `Data`'s inherited `[]` never dispatches through a `new` # override, so the guard above alone would miss `Insets[1, 2, 3, 4]`. # @param positional [Array] must be empty. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.[](*positional, **kwargs) = new(*positional, **kwargs) # @param value [Insets, Integer] an Integer becomes a uniform inset. # @raise [ArgumentError] on anything else, or a negative Integer. # @return [Insets] def self.coerce(value) return value if value.is_a?(Insets) unless value.is_a?(Integer) && !value.negative? raise ArgumentError, "expected Insets or a non-negative Integer, got #{value.inspect}" end new(top: value, right: value, bottom: value, left: value) end # @param top [Integer] cells inset from the top edge; `>= 0`. # @param right [Integer] cells inset from the right edge; `>= 0`. # @param bottom [Integer] cells inset from the bottom edge; `>= 0`. # @param left [Integer] cells inset from the left edge; `>= 0`. # @raise [ArgumentError] unless every edge is a non-negative Integer. def initialize(top: 0, right: 0, bottom: 0, left: 0) { top:, right:, bottom:, left: }.each do |edge, cells| unless cells.is_a?(Integer) && !cells.negative? raise ArgumentError, "Insets #{edge}: expected a non-negative Integer, got #{cells.inspect}" end end super end # @return [Integer] `left` + `right`. def horizontal = left + right # @return [Integer] `top` + `bottom`. def vertical = top + bottom # No padding on any edge. # @return [Insets] ZERO = new end |
#left ⇒ Integer (readonly)
@return — cells inset from the left edge.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/tuile/component/layout.rb', line 112 class Insets < Data.define(:top, :right, :bottom, :left) # @param positional [Array] must be empty — see the class doc. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.new(*positional, **kwargs) raise ArgumentError, "Insets is keyword-only, got #{positional.inspect}" unless positional.empty? super(**kwargs) end # Needed because `Data`'s inherited `[]` never dispatches through a `new` # override, so the guard above alone would miss `Insets[1, 2, 3, 4]`. # @param positional [Array] must be empty. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.[](*positional, **kwargs) = new(*positional, **kwargs) # @param value [Insets, Integer] an Integer becomes a uniform inset. # @raise [ArgumentError] on anything else, or a negative Integer. # @return [Insets] def self.coerce(value) return value if value.is_a?(Insets) unless value.is_a?(Integer) && !value.negative? raise ArgumentError, "expected Insets or a non-negative Integer, got #{value.inspect}" end new(top: value, right: value, bottom: value, left: value) end # @param top [Integer] cells inset from the top edge; `>= 0`. # @param right [Integer] cells inset from the right edge; `>= 0`. # @param bottom [Integer] cells inset from the bottom edge; `>= 0`. # @param left [Integer] cells inset from the left edge; `>= 0`. # @raise [ArgumentError] unless every edge is a non-negative Integer. def initialize(top: 0, right: 0, bottom: 0, left: 0) { top:, right:, bottom:, left: }.each do |edge, cells| unless cells.is_a?(Integer) && !cells.negative? raise ArgumentError, "Insets #{edge}: expected a non-negative Integer, got #{cells.inspect}" end end super end # @return [Integer] `left` + `right`. def horizontal = left + right # @return [Integer] `top` + `bottom`. def vertical = top + bottom # No padding on any edge. # @return [Insets] ZERO = new end |
#right ⇒ Integer (readonly)
@return — cells inset from the right edge.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/tuile/component/layout.rb', line 112 class Insets < Data.define(:top, :right, :bottom, :left) # @param positional [Array] must be empty — see the class doc. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.new(*positional, **kwargs) raise ArgumentError, "Insets is keyword-only, got #{positional.inspect}" unless positional.empty? super(**kwargs) end # Needed because `Data`'s inherited `[]` never dispatches through a `new` # override, so the guard above alone would miss `Insets[1, 2, 3, 4]`. # @param positional [Array] must be empty. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.[](*positional, **kwargs) = new(*positional, **kwargs) # @param value [Insets, Integer] an Integer becomes a uniform inset. # @raise [ArgumentError] on anything else, or a negative Integer. # @return [Insets] def self.coerce(value) return value if value.is_a?(Insets) unless value.is_a?(Integer) && !value.negative? raise ArgumentError, "expected Insets or a non-negative Integer, got #{value.inspect}" end new(top: value, right: value, bottom: value, left: value) end # @param top [Integer] cells inset from the top edge; `>= 0`. # @param right [Integer] cells inset from the right edge; `>= 0`. # @param bottom [Integer] cells inset from the bottom edge; `>= 0`. # @param left [Integer] cells inset from the left edge; `>= 0`. # @raise [ArgumentError] unless every edge is a non-negative Integer. def initialize(top: 0, right: 0, bottom: 0, left: 0) { top:, right:, bottom:, left: }.each do |edge, cells| unless cells.is_a?(Integer) && !cells.negative? raise ArgumentError, "Insets #{edge}: expected a non-negative Integer, got #{cells.inspect}" end end super end # @return [Integer] `left` + `right`. def horizontal = left + right # @return [Integer] `top` + `bottom`. def vertical = top + bottom # No padding on any edge. # @return [Insets] ZERO = new end |
#top ⇒ Integer (readonly)
@return — cells inset from the top edge.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/tuile/component/layout.rb', line 112 class Insets < Data.define(:top, :right, :bottom, :left) # @param positional [Array] must be empty — see the class doc. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.new(*positional, **kwargs) raise ArgumentError, "Insets is keyword-only, got #{positional.inspect}" unless positional.empty? super(**kwargs) end # Needed because `Data`'s inherited `[]` never dispatches through a `new` # override, so the guard above alone would miss `Insets[1, 2, 3, 4]`. # @param positional [Array] must be empty. # @param kwargs [Hash{Symbol => Integer}] any of `top:`/`right:`/`bottom:`/`left:`. # @raise [ArgumentError] if any positional argument is given. # @return [Insets] def self.[](*positional, **kwargs) = new(*positional, **kwargs) # @param value [Insets, Integer] an Integer becomes a uniform inset. # @raise [ArgumentError] on anything else, or a negative Integer. # @return [Insets] def self.coerce(value) return value if value.is_a?(Insets) unless value.is_a?(Integer) && !value.negative? raise ArgumentError, "expected Insets or a non-negative Integer, got #{value.inspect}" end new(top: value, right: value, bottom: value, left: value) end # @param top [Integer] cells inset from the top edge; `>= 0`. # @param right [Integer] cells inset from the right edge; `>= 0`. # @param bottom [Integer] cells inset from the bottom edge; `>= 0`. # @param left [Integer] cells inset from the left edge; `>= 0`. # @raise [ArgumentError] unless every edge is a non-negative Integer. def initialize(top: 0, right: 0, bottom: 0, left: 0) { top:, right:, bottom:, left: }.each do |edge, cells| unless cells.is_a?(Integer) && !cells.negative? raise ArgumentError, "Insets #{edge}: expected a non-negative Integer, got #{cells.inspect}" end end super end # @return [Integer] `left` + `right`. def horizontal = left + right # @return [Integer] `top` + `bottom`. def vertical = top + bottom # No padding on any edge. # @return [Insets] ZERO = new end |
Class Method Details
.[](*positional, **kwargs) ⇒ Insets
Needed because Data's inherited [] never dispatches through a new
override, so the guard above alone would miss Insets[1, 2, 3, 4].
@param positional — must be empty.
@param kwargs — any of top:/right:/bottom:/left:.
129 |
# File 'lib/tuile/component/layout.rb', line 129 def self.[](*positional, **kwargs) = new(*positional, **kwargs) |
.coerce(value) ⇒ Insets
@param value — an Integer becomes a uniform inset.
134 135 136 137 138 139 140 141 |
# File 'lib/tuile/component/layout.rb', line 134 def self.coerce(value) return value if value.is_a?(Insets) unless value.is_a?(Integer) && !value.negative? raise ArgumentError, "expected Insets or a non-negative Integer, got #{value.inspect}" end new(top: value, right: value, bottom: value, left: value) end |
.new(*positional, **kwargs) ⇒ Insets
@param positional — must be empty — see the class doc.
@param kwargs — any of top:/right:/bottom:/left:.
117 118 119 120 121 |
# File 'lib/tuile/component/layout.rb', line 117 def self.new(*positional, **kwargs) raise ArgumentError, "Insets is keyword-only, got #{positional.inspect}" unless positional.empty? super(**kwargs) end |
Instance Method Details
#horizontal ⇒ Integer
@return — left + right.
159 |
# File 'lib/tuile/component/layout.rb', line 159 def horizontal = left + right |
#vertical ⇒ Integer
@return — top + bottom.
162 |
# File 'lib/tuile/component/layout.rb', line 162 def vertical = top + bottom |