ui

source of widgets

1// The base widgets: text, buttons, checkboxes, sliders and images, each2// describing itself to screen readers.34import std::string;5import std::vector;6import std::option;7import std::math;8import std::time;9import std::process;10import pkg::alloy::window;11import pkg::alloy::gpu;12import pkg::alloy::draw;13import pkg::alloy::text as text;1415import ui;16import tree;17import motion;18import extensions;1920// The text laid out in the theme's font, on one line when it fits the21// width and wrapped at the width when not, its lines at the element's22// start.23exp fn text_layout(24    arrange: &var Arrange,25    text: &[u8],26    size: f32,27    weight: u32,28    width: f3229) -> text::Layout {30    const align = TextAlign::Start.lines(arrange.direction());31    var style = arrange.text_style(size);32    style.weight = weight;33    const fonts = &var arrange.fonts();34    return text::Layout::fitted(&fonts, &text, &style, width, align);35}3637/* --- Text --- */3839pub fn layout(self t: &var Text, arrange: &var Arrange, limits: Limits) -> Extent {40    const size = if (t.size is ::Some |size|) size else if (41        t.heading42    ) arrange.theme().heading_size else arrange.theme().text_size;43    const direction = arrange.direction();44    var style = arrange.text_style(size);45    style.weight = t.weight;46    const fonts = &var arrange.fonts();47    const laid = text::Layout::fitted(48        &fonts,49        &t.text.view(),50        &style,51        limits.max_width,52        t.align.lines(direction)53    );54    const extent = Extent { .width = laid.width, .height = laid.height };55    // painted now, so the layout goes at once: the element's size is56    // the limits' of this, Start and End on the element's sides57    const room = limits.constrain(extent).width - laid.width;58    const x = t.align.offset(room, direction);59    const color = if (t.color.color(&arrange.theme()) is ::Some |c|) c else arrange.theme().text;60    var drawn = Paint::empty();61    drawn.text(&laid, Point { .x = x, .y = 0.0 }, color);62    drawn.shrink();63    t.drawn = ::Some(move drawn);64    // read by its lines and words while a screen reader reads, when it65    // has several; the browser reads the web's itself66    if (target() != "web-wasm32") {67        t.map = ::None;68        if (arrange.ui.access_on && laid.lines.length() > 1) {69            const look = TextLook {70                .size = size,71                .weight = t.weight,72                .color = color,73                .heading = t.heading,74                .read_only = true75            };76            const at = Point { .x = x, .y = 0.0 };77            if (arrange.ui.extensions_text_map(&laid, at, look) is ::Some |move map|) {78                t.map = ::Some(new move map);79            }80        }81    }82    return extent;83}8485exp fn paint(self t: &Text, look: &Look, paint: &var Paint) {}8687pub fn take_paint(self t: &var Text) -> Option<Paint> {88    var taken = move t.drawn;89    t.drawn = ::None;90    return move taken;91}9293exp fn renew(self t: &var Text, next: Text) -> Change {94    // its paint is made with its layout, so any change lays it out again95    const changed = t.text != next.text || t.size != next.size || t.weight != next.weight96        || t.heading != next.heading97        || t.sizing != next.sizing || t.color != next.color || t.align != next.align;98    t.text = move next.text;99    t.size = next.size;100    t.weight = next.weight;101    t.color = next.color;102    t.heading = next.heading;103    t.align = next.align;104    t.sizing = next.sizing;105    if (changed) {106        t.drawn = ::None;107        return Change::Layout;108    }109    return Change::Nothing;110}111112pub fn sizing(self t: &Text) -> Sizing => t.sizing;113114pub fn semantics(self t: &Text) -> Semantics => Semantics {115    .role = Role::Label,116    .label = copy t.text117};118119// What a screen reader says after a field's label: its error, then what120// more there is to say, as a hint.121pub fn described(error: &String, more: &String) -> String {122    if (error.length() == 0) {123        return copy more;124    }125    if (more.length() == 0) {126        return copy error;127    }128    return f"{error} {more}";129}130131// The label a screen reader says: the accessible text, else the visible.132exp fn said(accessible: &String, shown: &String) -> String {133    if (accessible.length() > 0) {134        return copy accessible;135    }136    return copy shown;137}138139/* --- Buttons --- */140141pub fn layout(self b: &var Button, arrange: &var Arrange, limits: Limits) -> Extent {142    return button_layout(&var arrange, &b.label, &b.padding, limits, &var b.laid);143}144145// A button's label laid out within its padding, kept in `laid`: its size.146exp fn button_layout(147    arrange: &var Arrange,148    label: &String,149    padding: &Padding,150    limits: Limits,151    laid: &var Option<*text::Layout>152) -> Extent {153    const inner = limits.inside(&padding);154    const size = arrange.theme().text_size;155    var made = text_layout(&var arrange, &label.view(), size, 500, inner.max_width);156    const extent = Extent {157        .width = made.width + padding.start + padding.end,158        .height = made.height + padding.top + padding.bottom159    };160    laid = ::Some(new made);161    return extent;162}163164exp fn paint(self b: &Button, look: &Look, paint: &var Paint) {165    paint_button(&b.laid, b.variant, b.enabled, false, &look, &var paint);166}167168// A button's fill, focus ring and label, as pressed when `held`.169exp fn paint_button(170    laid: &Option<*text::Layout>,171    variant: ButtonVariant,172    enabled: bool,173    held: bool,174    look: &Look,175    paint: &var Paint176) {177    const theme = &look.theme;178    const area = Rect::sized(look.size.width, look.size.height);179    var fill = match (variant) {180        ::Primary theme.primary;181        ::Neutral theme.neutral;182        ::Plain Color::rgba(theme.text.r, theme.text.g, theme.text.b, 0.0);183    };184    var ink = match (variant) {185        ::Primary theme.on_primary;186        ::Neutral theme.text;187        ::Plain theme.primary;188    };189    if (enabled) {190        const amount = if (held) theme.press else emphasis(&look, true);191        fill = shade(fill, amount, variant is ::Plain);192    } else {193        fill.a = fill.a * 0.5;194        ink.a = ink.a * 0.5;195    }196    paint.rounded_rect(area, Radii::all(theme.radius), Fill::Color(fill));197    focus_ring(&look, &var paint, area, theme.radius);198    if (laid is ::Some |&label|) {199        const x = (look.size.width - label.width) / 2.0;200        const y = (look.size.height - label.height) / 2.0;201        paint.text(&label, Point { .x = x, .y = y }, ink);202    }203}204205// How much pressing or hovering shades a control, by the theme, easing206// as they come and go.207pub fn emphasis(look: &Look, enabled: bool) -> f32 {208    if (!enabled) {209        return 0.0;210    }211    return max(look.press * look.theme.press, look.hover * look.theme.hover);212}213214// How long after a change, in nanoseconds, a built-in widget's own215// drawing may still move: past the theme's short duration, which its216// motion takes.217exp const SETTLE: u64 = 400000000;218219// How far along a built-in widget's own motion is, `since` its change:220// over the theme's short duration.221exp fn settled(look: &Look) -> f32 {222    const span = max(look.theme.motion.short.nanoseconds to f32, 1.0);223    return Easing::Standard.eased(look.since.nanoseconds to f32 / span);224}225226// The color darkened by the amount, or for a plain button a tint of its227// own color that hovering shows.228exp fn shade(color: Color, amount: f32, plain: bool) -> Color {229    if (plain) {230        return Color::rgba(color.r, color.g, color.b, amount);231    }232    const keep = 1.0 - amount;233    return Color::rgba(color.r * keep, color.g * keep, color.b * keep, color.a);234}235236pub fn event(self b: &var Button, ui: &var Ui, input: &Input) -> bool {237    if (input is ::Key |&k|) {238        if (!activates(&k)) {239            return false;240        }241        if (k.pressed && b.enabled) {242            b.on_press(&var ui);243        }244        return true;245    }246    if (input is ::Click && b.enabled) {247        b.on_press(&var ui);248    }249    return claims(&input);250}251252// Whether a control takes the input it was given: all but focus changes253// and the wheel, which goes on to the scrolling ancestor.254exp fn claims(input: &Input) -> bool => !(input is ::Focus || input is ::Scroll);255256pub fn semantics(self b: &Button) -> Semantics => Semantics {257    .role = Role::Button,258    .label = said(&b.accessible, &b.label),259    .disabled = !b.enabled,260    .focusable = b.enabled261};262263// Whether the key presses what has the focus: Enter or Space.264exp fn activates(k: &KeyEvent) -> bool => match (k.key) {265    ::Enter true;266    ::Character |c| c == ' ' to u32;267    else false;268};269270pub fn focusable(self b: &Button) -> bool => b.enabled;271272pub fn cursor(self b: &Button) -> Cursor => if (b.enabled) Cursor::Hand else Cursor::Arrow;273274// The theme's focus ring around the area.275exp fn focus_ring(look: &Look, paint: &var Paint, area: Rect, radius: f32) {276    if (look.focus_ring) {277        paint.border(area.inflated(3.0), Radii::all(radius + 3.0), 2.0, look.theme.focus);278    }279}280281exp fn renew(self b: &var Button, next: Button) -> Change {282    const relayout = b.label != next.label || b.padding != next.padding || b.sizing != next.sizing;283    const repaint = b.variant != next.variant || b.enabled != next.enabled284        || b.accessible != next.accessible;285    b.label = move next.label;286    b.accessible = move next.accessible;287    b.on_press = move next.on_press;288    b.variant = next.variant;289    b.enabled = next.enabled;290    b.padding = next.padding;291    b.sizing = next.sizing;292    if (relayout) {293        b.laid = ::None;294        return Change::Layout;295    }296    return if (repaint) Change::Paint else Change::Nothing;297}298299pub fn sizing(self b: &Button) -> Sizing => b.sizing;300301pub fn interactive(self b: &Button) -> bool => true;302303/* --- Checkboxes --- */304305const BOX: f32 = 18.0;306const BOX_GAP: f32 = 8.0;307308pub fn layout(self c: &var Checkbox, arrange: &var Arrange, limits: Limits) -> Extent {309    var width = BOX;310    var height = BOX;311    if (c.label.length() > 0) {312        const size = arrange.theme().text_size;313        var laid = text_layout(314            &var arrange,315            &c.label.view(),316            size,317            REGULAR,318            max(limits.max_width - BOX - BOX_GAP, 1.0)319        );320        width += BOX_GAP + laid.width;321        height = max(height, laid.height);322        c.laid = ::Some(new laid);323    } else {324        c.laid = ::None;325    }326    return Extent { .width = width, .height = height };327}328329exp fn paint(self c: &Checkbox, look: &Look, paint: &var Paint) {330    const theme = &look.theme;331    const area = Rect::at(look.from_start(0.0, BOX), (look.size.height - BOX) / 2.0, BOX, BOX);332    // its fill and check fading in or out over the short duration333    const t = if (c.flipped) settled(&look) else 1.0;334    const on = if (c.checked) t else 1.0 - t;335    var fill = shade(336        Color::mix(theme.surface, theme.primary, on),337        emphasis(&look, c.enabled),338        false339    );340    if (!c.enabled) {341        fill.a = fill.a * 0.5;342    }343    paint.rounded_rect(area, Radii::all(4.0), Fill::Color(fill));344    if (on > 0.0 && look.marks.check is ::Some |mark|) {345        var ink = theme.on_primary;346        ink.a = ink.a * on;347        paint.mask(area, mark, ink);348    }349    if (on < 1.0) {350        var ring = if (c.error.length() > 0) theme.danger else Color::mix(351            theme.border,352            theme.muted,353            if (c.enabled) look.hover else 0.0354        );355        ring.a = ring.a * (1.0 - on);356        paint.border(area, Radii::all(4.0), 1.5, ring);357    }358    focus_ring(&look, &var paint, area, 4.0);359    if (c.laid is ::Some |&laid|) {360        var ink = theme.text;361        if (!c.enabled) {362            ink.a = 0.5;363        }364        paint.text(365            &laid,366            Point {367                .x = look.from_start(BOX + BOX_GAP, laid.width),368                .y = (look.size.height - laid.height) / 2.0369            },370            ink371        );372    }373}374375pub fn event(self c: &var Checkbox, ui: &var Ui, input: &Input) -> bool {376    if (input is ::Key |&k|) {377        if (!activates(&k)) {378            return false;379        }380        if (k.pressed && c.enabled) {381            c.on_change(&var ui, !c.checked);382        }383        return true;384    }385    if (input is ::Click && c.enabled) {386        c.on_change(&var ui, !c.checked);387    }388    return claims(&input);389}390391pub fn semantics(self c: &Checkbox) -> Semantics => Semantics {392    .role = Role::CheckBox,393    .label = said(&c.accessible, &c.label),394    .checked = ::Some(c.checked),395    .disabled = !c.enabled,396    .focusable = c.enabled,397    .invalid = c.error.length() > 0,398    .required = c.required,399    .description = copy c.error400};401402exp fn renew(self c: &var Checkbox, next: Checkbox) -> Change {403    const relayout = c.label != next.label || c.sizing != next.sizing;404    const repaint = c.checked != next.checked || c.enabled != next.enabled405        || c.accessible != next.accessible406        || c.error != next.error407        || c.required != next.required;408    c.flipped = c.checked != next.checked;409    c.checked = next.checked;410    c.label = move next.label;411    c.accessible = move next.accessible;412    c.on_change = move next.on_change;413    c.enabled = next.enabled;414    c.error = move next.error;415    c.required = next.required;416    c.sizing = next.sizing;417    return if (relayout) Change::Layout else if (repaint) Change::Paint else Change::Nothing;418}419420pub fn sizing(self c: &Checkbox) -> Sizing => c.sizing;421pub fn settling(self c: &Checkbox, since: Duration) -> bool => c.flipped422    && since.nanoseconds < SETTLE;423pub fn interactive(self c: &Checkbox) -> bool => true;424pub fn focusable(self c: &Checkbox) -> bool => c.enabled;425pub fn cursor(self c: &Checkbox) -> Cursor => if (c.enabled) Cursor::Hand else Cursor::Arrow;426427/* --- Sliders --- */428429const THUMB: f32 = 8.0; // its radius430431const LABEL_GAP: f32 = 12.0; // between a slider's label and its track432433pub fn layout(self s: &var Slider, arrange: &var Arrange, limits: Limits) -> Extent {434    const width = if (435        limits.max_width < UNBOUNDED436    ) limits.max_width else max(limits.min_width, 160.0);437    var height: f32 = 24.0;438    s.laid = ::None;439    if (s.label.length() > 0) {440        const laid = text_layout(441            &var arrange,442            &s.label.view(),443            arrange.theme().text_size,444            REGULAR,445            UNBOUNDED446        );447        height = max(height, laid.height);448        s.laid = ::Some(new laid);449    }450    return Extent { .width = max(width, s.track_start() + 2.0 * THUMB), .height = height };451}452453// Where the track starts, after the label.454fn track_start(self s: &Slider) -> f32 {455    if (s.laid is ::Some |&laid|) {456        return laid.width + LABEL_GAP;457    }458    return 0.0;459}460461// Where the value puts the thumb's center along the width.462fn thumb_x(self s: &Slider, width: f32) -> f32 {463    const span = s.max - s.min;464    const t = if (span > 0.0) clamp((s.value - s.min) / span, 0.0, 1.0) else 0.0;465    const start = s.track_start();466    return start + THUMB + t * max(width - start - 2.0 * THUMB, 0.0);467}468469// The value a thumb at x gives, by the step.470fn value_at(self s: &Slider, x: f32, width: f32) -> f32 {471    const start = s.track_start();472    const track = max(width - start - 2.0 * THUMB, 1.0);473    const t = clamp((x - start - THUMB) / track, 0.0, 1.0);474    return s.stepped(s.min + t * (s.max - s.min));475}476477fn stepped(self s: &Slider, value: f32) -> f32 {478    var v = clamp(value, min(s.min, s.max), max(s.min, s.max));479    if (s.step > 0.0) {480        v = clamp(481            s.min + round((v - s.min) / s.step) * s.step,482            min(s.min, s.max),483            max(s.min, s.max)484        );485    }486    return v;487}488489// Its label at its start, the track after it, the minimum at the490// track's start: the right right to left. Lengths from the start, made491// x from the left as drawn.492exp fn paint(self s: &Slider, look: &Look, paint: &var Paint) {493    const theme = &look.theme;494    const middle = look.size.height / 2.0;495    var x = s.thumb_x(look.size.width);496    // the thumb going to a value given, unless dragged there497    if (s.from is ::Some |from| && !look.pressed && !look.reduced) {498        var was = copy s;499        was.value = from;500        const start = was.thumb_x(look.size.width);501        x = start + (x - start) * settled(&look);502    }503    const alpha: f32 = if (s.enabled) 1.0 else 0.5;504    var rail = theme.neutral;505    rail.a = rail.a * alpha;506    var done = theme.primary;507    done.a = done.a * alpha;508    const start = s.track_start();509    if (s.laid is ::Some |&laid|) {510        var ink = theme.text;511        ink.a = ink.a * alpha;512        paint.text(513            &laid,514            Point {515                .x = look.from_start(0.0, laid.width),516                .y = (look.size.height - laid.height) / 2.0517            },518            ink519        );520    }521    const track = max(look.size.width - start - 2.0 * THUMB, 0.0);522    paint.rounded_rect(523        Rect::at(look.from_start(start + THUMB, track), middle - 2.0, track, 4.0),524        Radii::all(2.0),525        Fill::Color(rail)526    );527    const filled = x - start - THUMB;528    paint.rounded_rect(529        Rect::at(look.from_start(start + THUMB, filled), middle - 2.0, filled, 4.0),530        Radii::all(2.0),531        Fill::Color(done)532    );533    const thumb = Rect::at(534        look.from_start(x - THUMB, 2.0 * THUMB),535        middle - THUMB,536        2.0 * THUMB,537        2.0 * THUMB538    );539    paint.shadow(540        thumb,541        Radii::all(THUMB),542        Shadow::soft(0.0, 1.0, 3.0, Color::rgba(0.0, 0.0, 0.0, 0.25 * alpha))543    );544    paint.rounded_rect(545        thumb,546        Radii::all(THUMB),547        Fill::Color(shade(Color::white(), emphasis(&look, s.enabled), false))548    );549    paint.border(thumb, Radii::all(THUMB), 1.0, theme.border);550    focus_ring(&look, &var paint, thumb, THUMB);551}552553pub fn event(self s: &var Slider, ui: &var Ui, input: &Input) -> bool {554    if (!s.enabled) {555        return claims(&input);556    }557    const rtl = ui.handling_rtl();558    match (input) {559        ::Press, ::Moved |p| {560            const width = ui.handling_size().width;561            s.change_to(&var ui, s.value_at(if (rtl) width - p.x else p.x, width));562        }563        ::Key |&k| {564            if (!k.pressed) {565                return match (k.key) {566                    ::Left, ::Right, ::Up, ::Down true;567                    else false;568                };569            }570            const by = if (s.step > 0.0) s.step else (s.max - s.min) / 20.0;571            // Left and Right the way they point: Right toward the minimum572            // right to left573            const v = match (k.key) {574                ::Down s.stepped(s.value - by);575                ::Up s.stepped(s.value + by);576                ::Left s.stepped(if (rtl) s.value + by else s.value - by);577                ::Right s.stepped(if (rtl) s.value - by else s.value + by);578                ::Home s.min;579                ::End s.max;580                else {581                    return false;582                }583            };584            s.change_to(&var ui, v);585        }586        ::Focus, ::Scroll {587            return false;588        }589        ::Action |&a| {590            // stepping comes as arrow keys591            if (a is ::SetValue |&text| && parse_number(&text.view()) is ::Some |x|) {592                s.change_to(&var ui, s.stepped(x to f32));593            }594        }595        else {}596    }597    return true;598}599600// Tells the program the value, when it is another.601fn change_to(self s: &Slider, ui: &var Ui, value: f32) {602    if (value != s.value) {603        s.on_change(&var ui, value);604    }605}606607pub fn semantics(self s: &Slider) -> Semantics => Semantics {608    .role = Role::Slider,609    .label = said(&s.accessible, &s.label),610    .value = f"{s.value}",611    .range = ::Some(AccessRange {612        .value = s.value to f64,613        .minimum = s.min to f64,614        .maximum = s.max to f64,615        .step = s.step to f64616    }),617    .disabled = !s.enabled,618    .focusable = s.enabled619};620621// A decimal number as a screen reader sets it: `-12.5`.622fn parse_number(text: &[u8]) -> Option<f64> {623    const negative = text.length() > 0 && text[0] == '-';624    var value: f64 = 0.0;625    var scale: f64 = 0.0; // a digit's place after the point, 0 before it626    var digits = 0;627    for (text[(if (negative) 1 else 0)..]) |c| {628        if (c == '.' && scale == 0.0) {629            scale = 1.0;630        } else if (c >= '0' && c <= '9') {631            const digit = (c - '0') to f64;632            if (scale == 0.0) {633                value = value * 10.0 + digit;634            } else {635                scale /= 10.0;636                value += digit * scale;637            }638            digits += 1;639        } else {640            return ::None;641        }642    }643    if (digits == 0) {644        return ::None;645    }646    return ::Some(if (negative) -value else value);647}648649exp fn renew(self s: &var Slider, next: Slider) -> Change {650    const relayout = s.sizing != next.sizing || s.label != next.label;651    var laid = move s.laid;652    const was = s.value;653    s = move next;654    s.from = if (was != s.value) ::Some(was) else ::None;655    if (relayout) {656        return Change::Layout;657    }658    s.laid = move laid;659    return Change::Paint;660}661662pub fn sizing(self s: &Slider) -> Sizing => s.sizing;663pub fn settling(self s: &Slider, since: Duration) -> bool => s.from is ::Some664    && since.nanoseconds < SETTLE;665pub fn interactive(self s: &Slider) -> bool => true;666pub fn focusable(self s: &Slider) -> bool => s.enabled;667pub fn cursor(self s: &Slider) -> Cursor => if (s.enabled) Cursor::Hand else Cursor::Arrow;668669/* --- Images --- */670671pub fn layout(self i: &var Image, arrange: &var Arrange, limits: Limits) -> Extent {672    var natural = Extent::zero();673    if (arrange.ui.stored_image(i.image) is ::Some |&stored|) {674        natural = Extent { .width = stored.width to f32, .height = stored.height to f32 };675    }676    i.natural = natural;677    if (natural.width <= 0.0 || natural.height <= 0.0) {678        return limits.constrain(natural);679    }680    // one side fixed, the other keeps the picture's shape681    const aspect = natural.height / natural.width;682    if (limits.min_width == limits.max_width && limits.min_height != limits.max_height) {683        return limits.constrain(Extent {684            .width = limits.max_width,685            .height = limits.max_width * aspect686        });687    }688    if (limits.min_height == limits.max_height && limits.min_width != limits.max_width) {689        return limits.constrain(Extent {690            .width = limits.max_height / aspect,691            .height = limits.max_height692        });693    }694    var size = natural;695    if (size.width > limits.max_width) {696        size = Extent { .width = limits.max_width, .height = limits.max_width * aspect };697    }698    if (size.height > limits.max_height) {699        size = Extent { .width = limits.max_height / aspect, .height = limits.max_height };700    }701    return limits.constrain(size);702}703704exp fn paint(self i: &Image, look: &Look, paint: &var Paint) {705    const stored = if (stored_in(&look.images, i.image) is ::Some |&s|) &s else {706        return;707    };708    const picture = if (stored.picture is ::Some |p|) p else {709        return;710    };711    const w = look.size.width;712    const h = look.size.height;713    var area = Rect::sized(w, h);714    if (i.natural.width > 0.0 && i.natural.height > 0.0 && !(i.fit is ::Fill)) {715        const sx = w / i.natural.width;716        const sy = h / i.natural.height;717        const s = if (i.fit is ::Cover) max(sx, sy) else min(sx, sy);718        const fw = i.natural.width * s;719        const fh = i.natural.height * s;720        area = Rect::at((w - fw) / 2.0, (h - fh) / 2.0, fw, fh);721    }722    if (i.mirrors && look.direction is ::RightToLeft) {723        // the region read from its right edge to its left724        const r = picture.region;725        paint.image(area, Picture {726            .texture = picture.texture,727            .region = Rect::at(r.x + r.width, r.y, -r.width, r.height)728        });729        return;730    }731    paint.image(area, picture);732}733734exp fn renew(self i: &var Image, next: Image) -> Change {735    const relayout = i.image != next.image || i.fit != next.fit || i.sizing != next.sizing;736    const repaint = i.accessible != next.accessible || i.mirrors != next.mirrors;737    i.image = next.image;738    i.accessible = move next.accessible;739    i.fit = next.fit;740    i.mirrors = next.mirrors;741    i.sizing = next.sizing;742    return if (relayout) Change::Layout else if (repaint) Change::Paint else Change::Nothing;743}744745pub fn sizing(self i: &Image) -> Sizing => i.sizing;746pub fn clips(self i: &Image) -> bool => i.fit is ::Cover;747748// An image without accessible text is decoration a screen reader skips.749pub fn semantics(self i: &Image) -> Semantics => Semantics {750    .role = if (i.accessible.length() > 0) Role::Image else Role::Unknown,751    .label = copy i.accessible752};