Rename @image-url(..., 9slice(...)) to @image-url(..., nine-slice(...))

As per API review:
 - In the Rust and C++ API we use `set_nine_slice_edges` because the getter couldn't start with 9
 - in english we spell number less than 10 with letters and this is a name
This commit is contained in:
Olivier Goffart 2024-03-07 14:36:39 +01:00
parent c588013530
commit 255dc59ef4
13 changed files with 62 additions and 62 deletions

View file

@ -361,7 +361,7 @@ export component Example inherits Window {
}
```
Example using 9slice:
Example using nine-slice:
```slint
export component Example inherits Window {
@ -369,7 +369,7 @@ export component Example inherits Window {
height: 150px;
VerticalLayout {
Image {
source: @image-url("https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png", 9slice(30));
source: @image-url("https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png", nine-slice(30));
}
}
}

View file

@ -175,7 +175,7 @@ export component Example inherits Window {
```
It is also possible to load images supporting [9 slice scaling](https://en.wikipedia.org/wiki/9-slice_scaling) (also called nine patch or border images)
by adding a `9slice(...)` argument. The argument can have either one, two, or four numbers that specifies the size of the edges.
by adding a `nine-slice(...)` argument. The argument can have either one, two, or four numbers that specifies the size of the edges.
The numbers are either `top right bottom left` or `vertical horizontal`, or one number for everything
## Structs

View file

@ -553,7 +553,7 @@ module.exports = grammar({
field("name", "@image-url"),
"(",
field("image", $.string_value),
optional(seq(",", "9slice", "(", repeat($._int_number), ")")),
optional(seq(",", "nine-slice", "(", repeat($._int_number), ")")),
")",
),

View file

@ -219,7 +219,7 @@ impl<'a, T> Display for DisplayExpression<'a, T> {
Expression::ImageReference { resource_ref, nine_slice } => {
write!(f, "{:?}", resource_ref)?;
if let Some(nine_slice) = &nine_slice {
write!(f, "9slice({:?})", nine_slice)?;
write!(f, "nine-slice({:?})", nine_slice)?;
}
Ok(())
}

View file

@ -417,8 +417,8 @@ fn parse_tr(p: &mut impl Parser) {
/// ```test,AtImageUrl
/// @image-url("foo.png")
/// @image-url("foo.png",)
/// @image-url("foo.png", 9slice(1 2 3 4))
/// @image-url("foo.png", 9slice(1))
/// @image-url("foo.png", nine-slice(1 2 3 4))
/// @image-url("foo.png", nine-slice(1))
/// ```
fn parse_image_url(p: &mut impl Parser) {
let mut p = p.start_node(SyntaxKind::AtImageUrl);
@ -449,8 +449,8 @@ fn parse_image_url(p: &mut impl Parser) {
if p.test(SyntaxKind::RParent) {
return;
}
if p.peek().as_str() != "9slice" {
p.error("Expected '9slice(...)' argument");
if p.peek().as_str() != "nine-slice" {
p.error("Expected 'nine-slice(...)' argument");
p.until(SyntaxKind::RParent);
return;
}
@ -474,7 +474,7 @@ fn parse_image_url(p: &mut impl Parser) {
p.consume();
}
SyntaxKind::Comma | SyntaxKind::Colon => {
p.error("Arguments of 9slice need to be separated by spaces");
p.error("Arguments of nine-slice need to be separated by spaces");
p.until(SyntaxKind::RParent);
break;
}

View file

@ -369,16 +369,16 @@ impl Expression {
.children_with_tokens()
.filter_map(|n| n.into_token())
.filter(|t| t.kind() == SyntaxKind::NumberLiteral)
.skip(1) // slip "9slice"
.map(|arg| {
arg.text().parse().unwrap_or_else(|err: std::num::ParseIntError| {
match err.kind() {
IntErrorKind::PosOverflow | IntErrorKind::NegOverflow => {
ctx.diag.push_error("Number too big".into(), &arg)
}
IntErrorKind::InvalidDigit => ctx
.diag
.push_error("Border widths of a 9slice can't have units".into(), &arg),
IntErrorKind::InvalidDigit => ctx.diag.push_error(
"Border widths of a nine-slice can't have units".into(),
&arg,
),
_ => ctx.diag.push_error("Cannot parse number literal".into(), &arg),
};
0u16

View file

@ -15,34 +15,34 @@ export component SuperSimple {
property <image> i6: @image-url;
// ^error{Syntax error: expected '\('}
property <image> i7: @image-url("foo", "bar");
// ^error{Expected '9slice\(...\)' argument}
// ^error{Expected 'nine-slice\(...\)' argument}
property <image> i8: @image-url("foo", xyz(abc));
// ^error{Expected '9slice\(...\)' argument}
property <image> i9: @image-url("foo", 9slice(abc));
// ^error{Expected number literal or '\)'}
property <image> i10: @image-url("foo", 9slice(1 2 3));
// ^error{Expected 1 or 2 or 4 numbers}
property <image> i11: @image-url("foo", 9slice());
// ^error{Expected 1 or 2 or 4 numbers}
property <image> i12: @image-url("foo", 9slice(1 2 3 4 5));
// ^error{Expected 'nine-slice\(...\)' argument}
property <image> i9: @image-url("foo", nine-slice(abc));
// ^error{Expected number literal or '\)'}
property <image> i10: @image-url("foo", nine-slice(1 2 3));
// ^error{Expected 1 or 2 or 4 numbers}
property <image> i13: @image-url("foo", 9slice(1 2 foobar 4 5));
property <image> i11: @image-url("foo", nine-slice());
// ^error{Expected 1 or 2 or 4 numbers}
property <image> i12: @image-url("foo", nine-slice(1 2 3 4 5));
// ^error{Expected 1 or 2 or 4 numbers}
property <image> i13: @image-url("foo", nine-slice(1 2 foobar 4 5));
// ^error{Expected number literal or '\)'}
property <image> i14: @image-url("foo", nine-slice);
// ^error{Syntax error: expected '\('}
property <image> i15: @image-url("foo", nine-slice,);
// ^error{Syntax error: expected '\('}
property <image> i16: @image-url("foo", nine-slice 42 42);
// ^error{Syntax error: expected '\('}
property <image> i17: @image-url("foo", nine-slice(1px)); // error reported later
property <image> i18: @image-url("foo", nine-slice(1%)); // error reported later
property <image> i19: @image-url("foo", nine-slice(1, 2));
// ^error{Arguments of nine-slice need to be separated by spaces}
property <image> i20: @image-url("foo", nine-slice(2 + 3 ));
// ^error{Expected number literal or '\)'}
property <image> i21: @image-url("foo", nine-slice(2 -3 ));
// ^error{Expected number literal or '\)'}
property <image> i22: @image-url("foo", nine-slice(-2));
// ^error{Expected number literal or '\)'}
property <image> i14: @image-url("foo", 9slice);
// ^error{Syntax error: expected '\('}
property <image> i15: @image-url("foo", 9slice,);
// ^error{Syntax error: expected '\('}
property <image> i16: @image-url("foo", 9slice 42 42);
// ^error{Syntax error: expected '\('}
property <image> i17: @image-url("foo", 9slice(1px)); // error reported later
property <image> i18: @image-url("foo", 9slice(1%)); // error reported later
property <image> i19: @image-url("foo", 9slice(1, 2));
// ^error{Arguments of 9slice need to be separated by spaces}
property <image> i20: @image-url("foo", 9slice(2 + 3 ));
// ^error{Expected number literal or '\)'}
property <image> i21: @image-url("foo", 9slice(2 -3 ));
// ^error{Expected number literal or '\)'}
property <image> i22: @image-url("foo", 9slice(-2));
// ^error{Expected number literal or '\)'}
property <image> i22: @image-url("foo", 9slice(123456789));
property <image> i22: @image-url("foo", nine-slice(123456789));
}

View file

@ -2,14 +2,14 @@
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
export component SuperSimple {
property <image> i17: @image-url("foo", 9slice(1px));
// ^error{Border widths of a 9slice can't have units}
property <image> i18: @image-url("foo", 9slice(1%));
// ^error{Border widths of a 9slice can't have units}
property <image> i22: @image-url("foo", 9slice(123456789));
// ^error{Number too big}
property <image> j01: @image-url("foo", 9slice(1 52deg 456456456 12abc));
// ^error{Border widths of a 9slice can't have units}
// ^^error{Border widths of a 9slice can't have units}
// ^^^error{Number too big}
property <image> i17: @image-url("foo", nine-slice(1px));
// ^error{Border widths of a nine-slice can't have units}
property <image> i18: @image-url("foo", nine-slice(1%));
// ^error{Border widths of a nine-slice can't have units}
property <image> i22: @image-url("foo", nine-slice(123456789));
// ^error{Number too big}
property <image> j01: @image-url("foo", nine-slice(1 52deg 456456456 12abc));
// ^error{Border widths of a nine-slice can't have units}
// ^^error{Border widths of a nine-slice can't have units}
// ^^^error{Number too big}
}

View file

@ -326,7 +326,7 @@ impl ImageCacheKey {
}
}
/// Represent a 9slice image with the base image and the 4 borders
/// Represent a nine-slice image with the base image and the 4 borders
pub struct NineSliceImage(pub ImageInner, pub [u16; 4]);
impl NineSliceImage {
@ -1052,7 +1052,7 @@ pub fn fit(
.adjust_for_tiling(ratio, alignment, tiling)
}
/// Generate an iterator of [`FitResult`] for each slice of a 9slice border image
/// Generate an iterator of [`FitResult`] for each slice of a nine-slice border image
pub fn fit9slice(
source_rect: IntSize,
[t, r, b, l]: [u16; 4],

View file

@ -13,7 +13,7 @@ TestCase := Rectangle {
source-clip-x: 20;
}
out property <image> with-border: @image-url("dog.jpg", 9slice(12 13 14 15));
out property <image> with-border: @image-url("dog.jpg", nine-slice(12 13 14 15));
property <length> img_width: img.width;
property <length> img_height: img.height;

View file

@ -8,14 +8,14 @@ export component TestCase inherits Window {
height: 64px;
HorizontalLayout {
Image {
source: @image-url("border-image.png", 9slice(5));
source: @image-url("border-image.png", nine-slice(5));
vertical-tiling: repeat;
vertical-alignment: bottom;
horizontal-tiling: repeat;
horizontal-alignment: center;
}
Image {
source: @image-url("border-image.png", 9slice(6 5));
source: @image-url("border-image.png", nine-slice(6 5));
vertical-tiling: round;
vertical-alignment: bottom;
horizontal-tiling: round;

View file

@ -8,17 +8,17 @@ export component TestCase inherits Window {
height: 64px;
GridLayout {
Image {
source: @image-url("border-image.png", 9slice(6));
source: @image-url("border-image.png", nine-slice(6));
colspan: 2;
}
Image {
source: @image-url("border-image.png", 9slice(6 0));
source: @image-url("border-image.png", nine-slice(6 0));
row: 1;
width: 50%;
height: 50%;
}
Image {
source: @image-url("border-image.png", 9slice(5 6 2 0));
source: @image-url("border-image.png", nine-slice(5 6 2 0));
}
}
}

View file

@ -10,15 +10,15 @@ export component TestCase inherits Window {
Image {
width: 100%;
height: 100%;
source: @image-url("border-image-rect.png", 9slice(5 5 15 5));
source: @image-url("border-image-rect.png", nine-slice(5 5 15 5));
VerticalLayout {
padding: 5px;
Image {
// The border is bigger than the image
source: @image-url("border-image-rect.png", 9slice(50 2));
source: @image-url("border-image-rect.png", nine-slice(50 2));
}
Image {
source: @image-url("border-image-rect.png", 9slice(1 0));
source: @image-url("border-image-rect.png", nine-slice(1 0));
}
}
}