SusImg

Хост изображения с sizing, cover crop, скруглением и хуками load / error.
Пакет
SusKit · Атомы (коммерческий)
Свойства
| Имя | Тип | По умолчанию | |
|---|---|---|---|
Src | Prop<string> | "" | |
LazySrc | Prop<string> | "" | |
Alt | Prop<string> | "" | |
Height | Prop<float> | 0f | |
MaxHeight | Prop<float> | 0f | |
Width | Prop<float> | 0f | |
MaxWidth | Prop<float> | 0f | |
Cover | Prop<bool> | false | |
Stretch | Prop<bool> | false | |
Anchor | Prop<string> | "center" | |
Rounded | Prop<string> | "" | |
Gradient | Prop<string> | "" | |
AspectRatio | Prop<float> | 0f | |
Fit | Prop<string> | "width" |
Слоты
| Имя |
|---|
placeholder |
error |
События
| Имя | Поле | Payload |
|---|---|---|
Load | OnLoad | Texture2D |
Error | OnError | string |
Хуки стиля
Контракт USS-классов — внешний вид переопределяется без правки C#. Состояния переключаются этими классами:
sus-imgsus-img__errorsus-img__error-textsus-img__gradientsus-img__placeholdersus-img__placeholder-textsus-img__surfacesus-img--coversus-img--errorsus-img--rounded-0sus-img--rounded-circlesus-img--rounded-lgsus-img--rounded-mdsus-img--rounded-pillsus-img--rounded-smsus-img--rounded-xssus-img--stretch
Использование
xml
<template>
<sus:SusImg Src="portraits/hero"
Alt="Hero portrait"
Cover="true"
Rounded="md"
AspectRatio="1"
@load="OnLoaded"
@error="OnFailed" />
</template>
<script>
void OnLoaded(Texture2D tex) { /* … */ }
void OnFailed(string reason) { /* … */ }
</script>csharp
var img = new SusImg();
img.Src.Value = "ui/banner";
img.Cover.Value = true;
img.MaxHeight.Value = 180f;
img.OnError += msg => { /* … */ };Заметки
LazySrcзагружается после первой отрисовки, если задан.- Слоты
placeholder/errorкастомизируют пустое состояние и состояние ошибки.