mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 12:54:45 +00:00
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:
parent
c588013530
commit
255dc59ef4
13 changed files with 62 additions and 62 deletions
|
@ -361,7 +361,7 @@ export component Example inherits Window {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Example using 9slice:
|
Example using nine-slice:
|
||||||
|
|
||||||
```slint
|
```slint
|
||||||
export component Example inherits Window {
|
export component Example inherits Window {
|
||||||
|
@ -369,7 +369,7 @@ export component Example inherits Window {
|
||||||
height: 150px;
|
height: 150px;
|
||||||
VerticalLayout {
|
VerticalLayout {
|
||||||
Image {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
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
|
The numbers are either `top right bottom left` or `vertical horizontal`, or one number for everything
|
||||||
|
|
||||||
## Structs
|
## Structs
|
||||||
|
|
|
@ -553,7 +553,7 @@ module.exports = grammar({
|
||||||
field("name", "@image-url"),
|
field("name", "@image-url"),
|
||||||
"(",
|
"(",
|
||||||
field("image", $.string_value),
|
field("image", $.string_value),
|
||||||
optional(seq(",", "9slice", "(", repeat($._int_number), ")")),
|
optional(seq(",", "nine-slice", "(", repeat($._int_number), ")")),
|
||||||
")",
|
")",
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ impl<'a, T> Display for DisplayExpression<'a, T> {
|
||||||
Expression::ImageReference { resource_ref, nine_slice } => {
|
Expression::ImageReference { resource_ref, nine_slice } => {
|
||||||
write!(f, "{:?}", resource_ref)?;
|
write!(f, "{:?}", resource_ref)?;
|
||||||
if let Some(nine_slice) = &nine_slice {
|
if let Some(nine_slice) = &nine_slice {
|
||||||
write!(f, "9slice({:?})", nine_slice)?;
|
write!(f, "nine-slice({:?})", nine_slice)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,8 +417,8 @@ fn parse_tr(p: &mut impl Parser) {
|
||||||
/// ```test,AtImageUrl
|
/// ```test,AtImageUrl
|
||||||
/// @image-url("foo.png")
|
/// @image-url("foo.png")
|
||||||
/// @image-url("foo.png",)
|
/// @image-url("foo.png",)
|
||||||
/// @image-url("foo.png", 9slice(1 2 3 4))
|
/// @image-url("foo.png", nine-slice(1 2 3 4))
|
||||||
/// @image-url("foo.png", 9slice(1))
|
/// @image-url("foo.png", nine-slice(1))
|
||||||
/// ```
|
/// ```
|
||||||
fn parse_image_url(p: &mut impl Parser) {
|
fn parse_image_url(p: &mut impl Parser) {
|
||||||
let mut p = p.start_node(SyntaxKind::AtImageUrl);
|
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) {
|
if p.test(SyntaxKind::RParent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if p.peek().as_str() != "9slice" {
|
if p.peek().as_str() != "nine-slice" {
|
||||||
p.error("Expected '9slice(...)' argument");
|
p.error("Expected 'nine-slice(...)' argument");
|
||||||
p.until(SyntaxKind::RParent);
|
p.until(SyntaxKind::RParent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ fn parse_image_url(p: &mut impl Parser) {
|
||||||
p.consume();
|
p.consume();
|
||||||
}
|
}
|
||||||
SyntaxKind::Comma | SyntaxKind::Colon => {
|
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);
|
p.until(SyntaxKind::RParent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,16 +369,16 @@ impl Expression {
|
||||||
.children_with_tokens()
|
.children_with_tokens()
|
||||||
.filter_map(|n| n.into_token())
|
.filter_map(|n| n.into_token())
|
||||||
.filter(|t| t.kind() == SyntaxKind::NumberLiteral)
|
.filter(|t| t.kind() == SyntaxKind::NumberLiteral)
|
||||||
.skip(1) // slip "9slice"
|
|
||||||
.map(|arg| {
|
.map(|arg| {
|
||||||
arg.text().parse().unwrap_or_else(|err: std::num::ParseIntError| {
|
arg.text().parse().unwrap_or_else(|err: std::num::ParseIntError| {
|
||||||
match err.kind() {
|
match err.kind() {
|
||||||
IntErrorKind::PosOverflow | IntErrorKind::NegOverflow => {
|
IntErrorKind::PosOverflow | IntErrorKind::NegOverflow => {
|
||||||
ctx.diag.push_error("Number too big".into(), &arg)
|
ctx.diag.push_error("Number too big".into(), &arg)
|
||||||
}
|
}
|
||||||
IntErrorKind::InvalidDigit => ctx
|
IntErrorKind::InvalidDigit => ctx.diag.push_error(
|
||||||
.diag
|
"Border widths of a nine-slice can't have units".into(),
|
||||||
.push_error("Border widths of a 9slice can't have units".into(), &arg),
|
&arg,
|
||||||
|
),
|
||||||
_ => ctx.diag.push_error("Cannot parse number literal".into(), &arg),
|
_ => ctx.diag.push_error("Cannot parse number literal".into(), &arg),
|
||||||
};
|
};
|
||||||
0u16
|
0u16
|
||||||
|
|
|
@ -15,34 +15,34 @@ export component SuperSimple {
|
||||||
property <image> i6: @image-url;
|
property <image> i6: @image-url;
|
||||||
// ^error{Syntax error: expected '\('}
|
// ^error{Syntax error: expected '\('}
|
||||||
property <image> i7: @image-url("foo", "bar");
|
property <image> i7: @image-url("foo", "bar");
|
||||||
// ^error{Expected '9slice\(...\)' argument}
|
// ^error{Expected 'nine-slice\(...\)' argument}
|
||||||
property <image> i8: @image-url("foo", xyz(abc));
|
property <image> i8: @image-url("foo", xyz(abc));
|
||||||
// ^error{Expected '9slice\(...\)' argument}
|
// ^error{Expected 'nine-slice\(...\)' argument}
|
||||||
property <image> i9: @image-url("foo", 9slice(abc));
|
property <image> i9: @image-url("foo", nine-slice(abc));
|
||||||
// ^error{Expected number literal or '\)'}
|
// ^error{Expected number literal or '\)'}
|
||||||
property <image> i10: @image-url("foo", 9slice(1 2 3));
|
property <image> i10: @image-url("foo", nine-slice(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 1 or 2 or 4 numbers}
|
// ^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 '\)'}
|
// ^error{Expected number literal or '\)'}
|
||||||
property <image> i14: @image-url("foo", 9slice);
|
property <image> i22: @image-url("foo", nine-slice(123456789));
|
||||||
// ^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));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
|
||||||
|
|
||||||
export component SuperSimple {
|
export component SuperSimple {
|
||||||
property <image> i17: @image-url("foo", 9slice(1px));
|
property <image> i17: @image-url("foo", nine-slice(1px));
|
||||||
// ^error{Border widths of a 9slice can't have units}
|
// ^error{Border widths of a nine-slice can't have units}
|
||||||
property <image> i18: @image-url("foo", 9slice(1%));
|
property <image> i18: @image-url("foo", nine-slice(1%));
|
||||||
// ^error{Border widths of a 9slice can't have units}
|
// ^error{Border widths of a nine-slice can't have units}
|
||||||
property <image> i22: @image-url("foo", 9slice(123456789));
|
property <image> i22: @image-url("foo", nine-slice(123456789));
|
||||||
// ^error{Number too big}
|
// ^error{Number too big}
|
||||||
property <image> j01: @image-url("foo", 9slice(1 52deg 456456456 12abc));
|
property <image> j01: @image-url("foo", nine-slice(1 52deg 456456456 12abc));
|
||||||
// ^error{Border widths of a 9slice can't have units}
|
// ^error{Border widths of a nine-slice can't have units}
|
||||||
// ^^error{Border widths of a 9slice can't have units}
|
// ^^error{Border widths of a nine-slice can't have units}
|
||||||
// ^^^error{Number too big}
|
// ^^^error{Number too big}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]);
|
pub struct NineSliceImage(pub ImageInner, pub [u16; 4]);
|
||||||
|
|
||||||
impl NineSliceImage {
|
impl NineSliceImage {
|
||||||
|
@ -1052,7 +1052,7 @@ pub fn fit(
|
||||||
.adjust_for_tiling(ratio, alignment, tiling)
|
.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(
|
pub fn fit9slice(
|
||||||
source_rect: IntSize,
|
source_rect: IntSize,
|
||||||
[t, r, b, l]: [u16; 4],
|
[t, r, b, l]: [u16; 4],
|
||||||
|
|
|
@ -13,7 +13,7 @@ TestCase := Rectangle {
|
||||||
source-clip-x: 20;
|
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_width: img.width;
|
||||||
property <length> img_height: img.height;
|
property <length> img_height: img.height;
|
||||||
|
|
|
@ -8,14 +8,14 @@ export component TestCase inherits Window {
|
||||||
height: 64px;
|
height: 64px;
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
Image {
|
Image {
|
||||||
source: @image-url("border-image.png", 9slice(5));
|
source: @image-url("border-image.png", nine-slice(5));
|
||||||
vertical-tiling: repeat;
|
vertical-tiling: repeat;
|
||||||
vertical-alignment: bottom;
|
vertical-alignment: bottom;
|
||||||
horizontal-tiling: repeat;
|
horizontal-tiling: repeat;
|
||||||
horizontal-alignment: center;
|
horizontal-alignment: center;
|
||||||
}
|
}
|
||||||
Image {
|
Image {
|
||||||
source: @image-url("border-image.png", 9slice(6 5));
|
source: @image-url("border-image.png", nine-slice(6 5));
|
||||||
vertical-tiling: round;
|
vertical-tiling: round;
|
||||||
vertical-alignment: bottom;
|
vertical-alignment: bottom;
|
||||||
horizontal-tiling: round;
|
horizontal-tiling: round;
|
||||||
|
|
|
@ -8,17 +8,17 @@ export component TestCase inherits Window {
|
||||||
height: 64px;
|
height: 64px;
|
||||||
GridLayout {
|
GridLayout {
|
||||||
Image {
|
Image {
|
||||||
source: @image-url("border-image.png", 9slice(6));
|
source: @image-url("border-image.png", nine-slice(6));
|
||||||
colspan: 2;
|
colspan: 2;
|
||||||
}
|
}
|
||||||
Image {
|
Image {
|
||||||
source: @image-url("border-image.png", 9slice(6 0));
|
source: @image-url("border-image.png", nine-slice(6 0));
|
||||||
row: 1;
|
row: 1;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
height: 50%;
|
height: 50%;
|
||||||
}
|
}
|
||||||
Image {
|
Image {
|
||||||
source: @image-url("border-image.png", 9slice(5 6 2 0));
|
source: @image-url("border-image.png", nine-slice(5 6 2 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,15 @@ export component TestCase inherits Window {
|
||||||
Image {
|
Image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 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 {
|
VerticalLayout {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
Image {
|
Image {
|
||||||
// The border is bigger than the 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 {
|
Image {
|
||||||
source: @image-url("border-image-rect.png", 9slice(1 0));
|
source: @image-url("border-image-rect.png", nine-slice(1 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue