К содержимому

SusImg

SusImg

Хост изображения с sizing, cover crop, скруглением и хуками load / error.

Пакет

SusKit · Атомы (коммерческий)

Открыть в песочнице

SusKit · Atoms

Свойства

ИмяТипПо умолчанию
SrcProp<string>""
LazySrcProp<string>""
AltProp<string>""
HeightProp<float>0f
MaxHeightProp<float>0f
WidthProp<float>0f
MaxWidthProp<float>0f
CoverProp<bool>false
StretchProp<bool>false
AnchorProp<string>"center"
RoundedProp<string>""
GradientProp<string>""
AspectRatioProp<float>0f
FitProp<string>"width"

Слоты

Имя
placeholder
error

События

ИмяПолеPayload
LoadOnLoadTexture2D
ErrorOnErrorstring

Хуки стиля

Контракт USS-классов — внешний вид переопределяется без правки C#. Состояния переключаются этими классами:

  • sus-img
  • sus-img__error
  • sus-img__error-text
  • sus-img__gradient
  • sus-img__placeholder
  • sus-img__placeholder-text
  • sus-img__surface
  • sus-img--cover
  • sus-img--error
  • sus-img--rounded-0
  • sus-img--rounded-circle
  • sus-img--rounded-lg
  • sus-img--rounded-md
  • sus-img--rounded-pill
  • sus-img--rounded-sm
  • sus-img--rounded-xs
  • sus-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 кастомизируют пустое состояние и состояние ошибки.