@@ -1128,169 +1128,171 @@ pub fn build_border_instances(
1128
1128
instances
1129
1129
}
1130
1130
1131
- pub fn create_nine_patch_segments (
1132
- rect : & LayoutRect ,
1133
- nine_patch : & NinePatchDescriptor ,
1134
- ) -> Vec < BrushSegment > {
1135
- // Calculate the modified rect as specific by border-image-outset
1136
- let origin = LayoutPoint :: new (
1137
- rect. origin . x - nine_patch. outset . left ,
1138
- rect. origin . y - nine_patch. outset . top ,
1139
- ) ;
1140
- let size = LayoutSize :: new (
1141
- rect. size . width + nine_patch. outset . left + nine_patch. outset . right ,
1142
- rect. size . height + nine_patch. outset . top + nine_patch. outset . bottom ,
1143
- ) ;
1144
- let rect = LayoutRect :: new ( origin, size) ;
1145
-
1146
- // Calculate the local texel coords of the slices.
1147
- let px0 = 0.0 ;
1148
- let px1 = nine_patch. slice . left as f32 ;
1149
- let px2 = nine_patch. width as f32 - nine_patch. slice . right as f32 ;
1150
- let px3 = nine_patch. width as f32 ;
1131
+ impl NinePatchDescriptor {
1132
+ pub fn create_segments (
1133
+ & self ,
1134
+ rect : & LayoutRect ,
1135
+ ) -> Vec < BrushSegment > {
1136
+ // Calculate the modified rect as specific by border-image-outset
1137
+ let origin = LayoutPoint :: new (
1138
+ rect. origin . x - self . outset . left ,
1139
+ rect. origin . y - self . outset . top ,
1140
+ ) ;
1141
+ let size = LayoutSize :: new (
1142
+ rect. size . width + self . outset . left + self . outset . right ,
1143
+ rect. size . height + self . outset . top + self . outset . bottom ,
1144
+ ) ;
1145
+ let rect = LayoutRect :: new ( origin, size) ;
1151
1146
1152
- let py0 = 0.0 ;
1153
- let py1 = nine_patch. slice . top as f32 ;
1154
- let py2 = nine_patch. height as f32 - nine_patch. slice . bottom as f32 ;
1155
- let py3 = nine_patch. height as f32 ;
1147
+ // Calculate the local texel coords of the slices.
1148
+ let px0 = 0.0 ;
1149
+ let px1 = self . slice . left as f32 ;
1150
+ let px2 = self . width as f32 - self . slice . right as f32 ;
1151
+ let px3 = self . width as f32 ;
1156
1152
1157
- let tl_outer = LayoutPoint :: new ( rect. origin . x , rect. origin . y ) ;
1158
- let tl_inner = tl_outer + vec2 ( nine_patch. widths . left , nine_patch. widths . top ) ;
1153
+ let py0 = 0.0 ;
1154
+ let py1 = self . slice . top as f32 ;
1155
+ let py2 = self . height as f32 - self . slice . bottom as f32 ;
1156
+ let py3 = self . height as f32 ;
1159
1157
1160
- let tr_outer = LayoutPoint :: new ( rect. origin . x + rect . size . width , rect. origin . y ) ;
1161
- let tr_inner = tr_outer + vec2 ( -nine_patch . widths . right , nine_patch . widths . top ) ;
1158
+ let tl_outer = LayoutPoint :: new ( rect. origin . x , rect. origin . y ) ;
1159
+ let tl_inner = tl_outer + vec2 ( self . widths . left , self . widths . top ) ;
1162
1160
1163
- let bl_outer = LayoutPoint :: new ( rect. origin . x , rect. origin . y + rect. size . height ) ;
1164
- let bl_inner = bl_outer + vec2 ( nine_patch . widths . left , -nine_patch . widths . bottom ) ;
1161
+ let tr_outer = LayoutPoint :: new ( rect. origin . x + rect. size . width , rect. origin . y ) ;
1162
+ let tr_inner = tr_outer + vec2 ( - self . widths . right , self . widths . top ) ;
1165
1163
1166
- let br_outer = LayoutPoint :: new (
1167
- rect. origin . x + rect. size . width ,
1168
- rect. origin . y + rect. size . height ,
1169
- ) ;
1170
- let br_inner = br_outer - vec2 ( nine_patch. widths . right , nine_patch. widths . bottom ) ;
1171
-
1172
- fn add_segment (
1173
- segments : & mut Vec < BrushSegment > ,
1174
- rect : LayoutRect ,
1175
- uv_rect : TexelRect ,
1176
- repeat_horizontal : RepeatMode ,
1177
- repeat_vertical : RepeatMode
1178
- ) {
1179
- if uv_rect. uv1 . x > uv_rect. uv0 . x &&
1180
- uv_rect. uv1 . y > uv_rect. uv0 . y {
1181
-
1182
- // Use segment relative interpolation for all
1183
- // instances in this primitive.
1184
- let mut brush_flags =
1185
- BrushFlags :: SEGMENT_RELATIVE |
1186
- BrushFlags :: SEGMENT_TEXEL_RECT ;
1187
-
1188
- // Enable repeat modes on the segment.
1189
- if repeat_horizontal == RepeatMode :: Repeat {
1190
- brush_flags |= BrushFlags :: SEGMENT_REPEAT_X ;
1191
- }
1192
- if repeat_vertical == RepeatMode :: Repeat {
1193
- brush_flags |= BrushFlags :: SEGMENT_REPEAT_Y ;
1194
- }
1164
+ let bl_outer = LayoutPoint :: new ( rect. origin . x , rect. origin . y + rect. size . height ) ;
1165
+ let bl_inner = bl_outer + vec2 ( self . widths . left , -self . widths . bottom ) ;
1195
1166
1196
- let segment = BrushSegment :: new (
1197
- rect,
1198
- true ,
1199
- EdgeAaSegmentMask :: empty ( ) ,
1200
- [
1201
- uv_rect. uv0 . x ,
1202
- uv_rect. uv0 . y ,
1203
- uv_rect. uv1 . x ,
1204
- uv_rect. uv1 . y ,
1205
- ] ,
1206
- brush_flags,
1207
- ) ;
1167
+ let br_outer = LayoutPoint :: new (
1168
+ rect. origin . x + rect. size . width ,
1169
+ rect. origin . y + rect. size . height ,
1170
+ ) ;
1171
+ let br_inner = br_outer - vec2 ( self . widths . right , self . widths . bottom ) ;
1172
+
1173
+ fn add_segment (
1174
+ segments : & mut Vec < BrushSegment > ,
1175
+ rect : LayoutRect ,
1176
+ uv_rect : TexelRect ,
1177
+ repeat_horizontal : RepeatMode ,
1178
+ repeat_vertical : RepeatMode
1179
+ ) {
1180
+ if uv_rect. uv1 . x > uv_rect. uv0 . x &&
1181
+ uv_rect. uv1 . y > uv_rect. uv0 . y {
1182
+
1183
+ // Use segment relative interpolation for all
1184
+ // instances in this primitive.
1185
+ let mut brush_flags =
1186
+ BrushFlags :: SEGMENT_RELATIVE |
1187
+ BrushFlags :: SEGMENT_TEXEL_RECT ;
1188
+
1189
+ // Enable repeat modes on the segment.
1190
+ if repeat_horizontal == RepeatMode :: Repeat {
1191
+ brush_flags |= BrushFlags :: SEGMENT_REPEAT_X ;
1192
+ }
1193
+ if repeat_vertical == RepeatMode :: Repeat {
1194
+ brush_flags |= BrushFlags :: SEGMENT_REPEAT_Y ;
1195
+ }
1208
1196
1209
- segments. push ( segment) ;
1197
+ let segment = BrushSegment :: new (
1198
+ rect,
1199
+ true ,
1200
+ EdgeAaSegmentMask :: empty ( ) ,
1201
+ [
1202
+ uv_rect. uv0 . x ,
1203
+ uv_rect. uv0 . y ,
1204
+ uv_rect. uv1 . x ,
1205
+ uv_rect. uv1 . y ,
1206
+ ] ,
1207
+ brush_flags,
1208
+ ) ;
1209
+
1210
+ segments. push ( segment) ;
1211
+ }
1210
1212
}
1211
- }
1212
1213
1213
- // Build the list of image segments
1214
- let mut segments = Vec :: new ( ) ;
1214
+ // Build the list of image segments
1215
+ let mut segments = Vec :: new ( ) ;
1215
1216
1216
- // Top left
1217
- add_segment (
1218
- & mut segments,
1219
- LayoutRect :: from_floats ( tl_outer. x , tl_outer. y , tl_inner. x , tl_inner. y ) ,
1220
- TexelRect :: new ( px0, py0, px1, py1) ,
1221
- RepeatMode :: Stretch ,
1222
- RepeatMode :: Stretch
1223
- ) ;
1224
- // Top right
1225
- add_segment (
1226
- & mut segments,
1227
- LayoutRect :: from_floats ( tr_inner. x , tr_outer. y , tr_outer. x , tr_inner. y ) ,
1228
- TexelRect :: new ( px2, py0, px3, py1) ,
1229
- RepeatMode :: Stretch ,
1230
- RepeatMode :: Stretch
1231
- ) ;
1232
- // Bottom right
1233
- add_segment (
1234
- & mut segments,
1235
- LayoutRect :: from_floats ( br_inner. x , br_inner. y , br_outer. x , br_outer. y ) ,
1236
- TexelRect :: new ( px2, py2, px3, py3) ,
1237
- RepeatMode :: Stretch ,
1238
- RepeatMode :: Stretch
1239
- ) ;
1240
- // Bottom left
1241
- add_segment (
1242
- & mut segments,
1243
- LayoutRect :: from_floats ( bl_outer. x , bl_inner. y , bl_inner. x , bl_outer. y ) ,
1244
- TexelRect :: new ( px0, py2, px1, py3) ,
1245
- RepeatMode :: Stretch ,
1246
- RepeatMode :: Stretch
1247
- ) ;
1248
-
1249
- // Center
1250
- if nine_patch. fill {
1217
+ // Top left
1251
1218
add_segment (
1252
1219
& mut segments,
1253
- LayoutRect :: from_floats ( tl_inner. x , tl_inner. y , tr_inner. x , bl_inner. y ) ,
1254
- TexelRect :: new ( px1, py1, px2, py2) ,
1255
- nine_patch. repeat_horizontal ,
1256
- nine_patch. repeat_vertical
1220
+ LayoutRect :: from_floats ( tl_outer. x , tl_outer. y , tl_inner. x , tl_inner. y ) ,
1221
+ TexelRect :: new ( px0, py0, px1, py1) ,
1222
+ RepeatMode :: Stretch ,
1223
+ RepeatMode :: Stretch
1224
+ ) ;
1225
+ // Top right
1226
+ add_segment (
1227
+ & mut segments,
1228
+ LayoutRect :: from_floats ( tr_inner. x , tr_outer. y , tr_outer. x , tr_inner. y ) ,
1229
+ TexelRect :: new ( px2, py0, px3, py1) ,
1230
+ RepeatMode :: Stretch ,
1231
+ RepeatMode :: Stretch
1232
+ ) ;
1233
+ // Bottom right
1234
+ add_segment (
1235
+ & mut segments,
1236
+ LayoutRect :: from_floats ( br_inner. x , br_inner. y , br_outer. x , br_outer. y ) ,
1237
+ TexelRect :: new ( px2, py2, px3, py3) ,
1238
+ RepeatMode :: Stretch ,
1239
+ RepeatMode :: Stretch
1240
+ ) ;
1241
+ // Bottom left
1242
+ add_segment (
1243
+ & mut segments,
1244
+ LayoutRect :: from_floats ( bl_outer. x , bl_inner. y , bl_inner. x , bl_outer. y ) ,
1245
+ TexelRect :: new ( px0, py2, px1, py3) ,
1246
+ RepeatMode :: Stretch ,
1247
+ RepeatMode :: Stretch
1257
1248
) ;
1258
- }
1259
1249
1260
- // Add edge segments.
1250
+ // Center
1251
+ if self . fill {
1252
+ add_segment (
1253
+ & mut segments,
1254
+ LayoutRect :: from_floats ( tl_inner. x , tl_inner. y , tr_inner. x , bl_inner. y ) ,
1255
+ TexelRect :: new ( px1, py1, px2, py2) ,
1256
+ self . repeat_horizontal ,
1257
+ self . repeat_vertical
1258
+ ) ;
1259
+ }
1261
1260
1262
- // Top
1263
- add_segment (
1264
- & mut segments,
1265
- LayoutRect :: from_floats ( tl_inner. x , tl_outer. y , tr_inner. x , tl_inner. y ) ,
1266
- TexelRect :: new ( px1, py0, px2, py1) ,
1267
- nine_patch. repeat_horizontal ,
1268
- RepeatMode :: Stretch ,
1269
- ) ;
1270
- // Bottom
1271
- add_segment (
1272
- & mut segments,
1273
- LayoutRect :: from_floats ( bl_inner. x , bl_inner. y , br_inner. x , bl_outer. y ) ,
1274
- TexelRect :: new ( px1, py2, px2, py3) ,
1275
- nine_patch. repeat_horizontal ,
1276
- RepeatMode :: Stretch ,
1277
- ) ;
1278
- // Left
1279
- add_segment (
1280
- & mut segments,
1281
- LayoutRect :: from_floats ( tl_outer. x , tl_inner. y , tl_inner. x , bl_inner. y ) ,
1282
- TexelRect :: new ( px0, py1, px1, py2) ,
1283
- RepeatMode :: Stretch ,
1284
- nine_patch. repeat_vertical ,
1285
- ) ;
1286
- // Right
1287
- add_segment (
1288
- & mut segments,
1289
- LayoutRect :: from_floats ( tr_inner. x , tr_inner. y , br_outer. x , br_inner. y ) ,
1290
- TexelRect :: new ( px2, py1, px3, py2) ,
1291
- RepeatMode :: Stretch ,
1292
- nine_patch. repeat_vertical ,
1293
- ) ;
1261
+ // Add edge segments.
1294
1262
1295
- segments
1263
+ // Top
1264
+ add_segment (
1265
+ & mut segments,
1266
+ LayoutRect :: from_floats ( tl_inner. x , tl_outer. y , tr_inner. x , tl_inner. y ) ,
1267
+ TexelRect :: new ( px1, py0, px2, py1) ,
1268
+ self . repeat_horizontal ,
1269
+ RepeatMode :: Stretch ,
1270
+ ) ;
1271
+ // Bottom
1272
+ add_segment (
1273
+ & mut segments,
1274
+ LayoutRect :: from_floats ( bl_inner. x , bl_inner. y , br_inner. x , bl_outer. y ) ,
1275
+ TexelRect :: new ( px1, py2, px2, py3) ,
1276
+ self . repeat_horizontal ,
1277
+ RepeatMode :: Stretch ,
1278
+ ) ;
1279
+ // Left
1280
+ add_segment (
1281
+ & mut segments,
1282
+ LayoutRect :: from_floats ( tl_outer. x , tl_inner. y , tl_inner. x , bl_inner. y ) ,
1283
+ TexelRect :: new ( px0, py1, px1, py2) ,
1284
+ RepeatMode :: Stretch ,
1285
+ self . repeat_vertical ,
1286
+ ) ;
1287
+ // Right
1288
+ add_segment (
1289
+ & mut segments,
1290
+ LayoutRect :: from_floats ( tr_inner. x , tr_inner. y , br_outer. x , br_inner. y ) ,
1291
+ TexelRect :: new ( px2, py1, px3, py2) ,
1292
+ RepeatMode :: Stretch ,
1293
+ self . repeat_vertical ,
1294
+ ) ;
1295
+
1296
+ segments
1297
+ }
1296
1298
}
0 commit comments