JFLib

5. Widgets#

All of them are Ui methods (API.md, sections Widgets, Text boxes, Lists, Values). Labels are copied, so they may come from temporary Strings.

Text and buttons

ui.box_begin(0, BOX_H | BOX_XCENTER, 12);
if ui.accent_button(ID_APPLY, "Übernehmen") & EV_ACT != 0 {
    ui.cmd_run(CMD_RESET, 0); // the work runs in App::command after the frame
}
ui.next_flags(ST_DISABLED);
ui.button(ID_APPLY + 1, "Deaktiviert");
ui.next_icon(IC_ADD);
ui.button(ID_APPLY + 2, "Mit Icon");
ui.icon_button(ID_APPLY + 3, IC_SAVE, "Speichern"); // the label becomes the tooltip
ui.cmd_button(CMD_SAVE, ST_ICON_ONLY | ST_SUBTLE);   // a button for a command (section 6)
ui.tooltip("Speichert das Bild");                     // tooltip of the last widget
ui.box_end();
  • text(TS_* | TX_*, s): text styles TS_CAPTION, TS_BODY, TS_BODY_STRONG, TS_SUBTITLE, TS_TITLE, TS_TITLE_LARGE, TS_DISPLAY; flags TX_SECONDARY, TX_TERTIARY, TX_ACCENT, TX_WRAP (wrap at the box width), TX_HYPHENATE (with TX_WRAP: hyphenate words that do not fit, section 11), TX_ELLIPSIS (cut with "…"; with TX_WRAP at the height of next_size), TX_CENTER, TX_RIGHT. heading(level, TS_* | TX_*, s) draws the same text as a section title that screen readers know as a heading of that level (1 the top; their heading navigation finds it, section 19).
  • Buttons: button, accent_button, icon_button(id, IC_*, label), toggle_button(id, label, &mut v), tool_button(id, IC_*, label, &mut sel, mine) (tool palettes), cmd_button(cmd, ST_*).
  • Modifiers for the next widget: next_flags(ST_DISABLED | ST_SUBTLE | ST_ACCENT | ST_CHECKED | ST_LARGE | ST_COMPACT | ST_NOFOCUS | ST_ICON_ONLY), next_icon(IC_*). Post-modifiers for the last widget: tooltip(s), context_menu(menu); for one part of it (an item on a canvas) tooltip_part(s, part): the delay starts again when the part changes.
  • icon(IC_*, size_dip), separator(), progress(id, v, max).

Selection and ranges

ui.checkbox(ID_SHOW, "Anzeigen", &mut self.show);
for (k, label) in ["Rot", "Grün", "Blau"].iter().enumerate() {
    ui.radio(ID_MODE + k as u32, label, &mut self.mode, k as i32);
}
ui.switch(ID_SHOW + 1, "WLAN", &mut self.wlan);
ui.next_size(200, 0);
if ui.slider(ID_SIZE, &mut self.size, &RG_SIZE) & EV_COMMIT != 0 {
    // released: a good moment for expensive work
}
ui.number_box(ID_SIZE + 1, &mut self.size, &RG_SIZE);

with const RG_SIZE: Range = Range::new(1, 100, 1, 0); (min, max, step, RG_* flags: RG_VERT, RG_TICKS, RG_TIP). A vertical slider needs a height: next_size(60, 100).

Text input

  • textbox(id, Some("placeholder"), &mut string, cap | TB_*) -> EV_ACT = changed, EV_COMMIT = Enter / focus lost. cap is the byte capacity; flags TB_PASSWORD, TB_READONLY, TB_DIGITS (+ TB_SIGNED, TB_DECIMAL), TB_MULTI (+ TB_WRAP; give it a height with next_size; + TB_HYPHENATE: hyphenation, section 11), TB_SPELL (spell checking, below). The capacity takes bits 0..22 (at most 8 MB).
  • A TB_PASSWORD box sets the input method's purpose itself: IP_PASSWORD while it has the keyboard (Windows takes the input method away, X11 keeps the keys from IBus as GTK does, Wayland tells the compositor), the purpose of before once it lost the keyboard or went away with its window -- no plat::ime_purpose call in the app (viewtest tests/password.uis).
  • Formatted text (bold, lists, links ...) and source code with highlighting: the editors ui.richtext and ui.code_editor (section 28).
  • number_box(id, &mut i32, &Range), number_box_f(id, &mut f64, &RangeF) with RangeF::new(min, max, step, decimals, flags); ui.fmt_f64(v, decimals) / ui.parse_f64(s) use the UI's decimal separator (default ,; set_decimal_sep).
  • clip_set / clip_get / clip_set_image / clip_get_image reach the clipboard (headless runs use a private one). On Android that is the system's ClipboardManager: text and HTML go to other apps, an image as a PNG through the app's GalleryFiles provider (declared in the manifest; without it images stay in the app), the library's RTF / DOCX forms stay in the app and count while the system's clip is the one it set. Android lets only the focused app read the clipboard, so a paste right after the system's picker may find it empty.
  • Text boxes follow Unicode's segmentation (text::segment, UAX #29 / #14, Unicode 15.0): the arrows and Delete move over whole characters as the user sees them (an accented letter in two code points, an emoji family, a flag); Backspace removes an emoji sequence whole and of other characters the last code point; Ctrl+arrows and a double click work on words (can't and 3.14 are one word, runs of punctuation one unit); wrapped boxes and TX_WRAP texts break lines after spaces and hyphens, between ideographs and never inside a number or before a closing bracket; after a soft hyphen (U+00AD, invisible inside a line) they draw a hyphen. Your own text code can use text::segment::{graphemes, word_bounds, word_at, line_breaks, wrap_end, wrap_end_hyph} (wrap_end_hyph: soft hyphens and a hyphenation hook such as spell::Hyphenator::hyphenate).

Spell checking. A text box with TB_SPELL (one line or TB_MULTI) underlines misspelled words with a red wavy line; a right click on one -- or the menu key / Shift+F10 with the caret in it -- offers up to five suggestions, "Zum Wörterbuch hinzufügen" and "Ignorieren". The word being typed is marked only once the caret leaves it; password, read-only and digit boxes are never checked; the app's own context_menu() still opens on unmarked words.

ui.textbox(ID_BODY, None, &mut self.body, 4096 | TB_MULTI | TB_WRAP | TB_SPELL);
ui.spell_enable(self.settings.spelling);      // the switch for the whole UI (default on)
ui.spell_language("en-GB");                   // default "": the user's languages
let bad = ui.spell_errors(ID_BODY);           // misspelled byte ranges, as last checked
if let Some(sp) = ui.speller() { sp.add("JFLib"); } // spell::Speller: check, suggest, add, ignore
  • The checker (crate spell): the system's own when it knows the language (Windows' ISpellChecker, macOS' NSSpellChecker with ~/Library/Spelling, iOS' UITextChecker), else Hunspell dictionaries the library reads itself -- Linux /usr/share/hunspell, myspell, ~/.local/share/hunspell, DICPATH; then config://hunspell and the app's own in apps/NAME/assets/hunspell (de_DE.aff + de_DE.dic; Web and Android only these). spell_sources(SRC_APP) limits it, spell_set(Speller::with_dictionary(..)) sets one.
  • "Zum Wörterbuch hinzufügen" writes config://spell/<language>.dic (one word per line); "Ignorieren" lasts for the session. Headless runs read only app://hunspell and keep both in memory, so scripts give the same result everywhere.
  • Suggestions from a Hunspell dictionary are made on a worker (a long German compound takes up to a few tenths of a second): the menu opens at once with "Vorschläge werden gesucht …" and fills when they are there; Windows' checker answers at once. Headless runs make them at once too; ui.spell_suggest_async(true) lets a script see the waiting menu (sync waits for the worker, apps/spelltest/tests/async.uis).
  • Checking is cached per text and per word: typing re-checks only new words; a long text is checked in slices of at most 6 ms per frame (spell_state() is SPELL_LOADING while a dictionary is read in the background).
  • The Hunspell reader follows Hunspell 1.7 (affixes, compounds, COMPOUNDRULE, case rules); it was compared with real de_DE / en_US / en_GB and twelve more dictionaries (docs/ROADMAP.md 4).
  • Tests: apps/spelltest (--test engine for the Hunspell rules, scripts for marks, menu, word list, typing, language; --compare AFF DIC WORDS [--sug N] checks a word list with any dictionary, e.g. to compare it with Hunspell), plattest --test spell (the real ISpellChecker).

Values and colours

const RF_ZOOM: RangeF = RangeF::new(10.0, 800.0, 0.0, 1, 0);

ui.next_size(200, 0);
ui.slider_f(ID_ZOOM, &mut self.zoom, &RF_ZOOM);
ui.number_box_f(ID_ZOOM + 1, &mut self.zoom, &RF_ZOOM);
ui.angle(ID_ANGLE, &mut self.angle, 0);
ui.swatch(ID_COLOR, self.color, false);
ui.color_picker(ID_COLOR + 1, &mut self.color);

Also prop_slider(id, label, &mut v, &range, default) / prop_slider_f (paint.net-style property rows with a reset button), track_slider(id, &mut v, &range, Some(&track)) (a slider over a gradient: Track::new(TK_*, &stops)), pan(id, &mut x, &mut y, thumb, ver, flags), color_picker_ex(id, &mut argb, CP_ALPHA | CP_FIELDS), color_wheel(id, &mut hsv_or_argb, CW_HSV); hsv_to_rgb / rgb_to_hsv convert (hue in tenths of a degree, S / V 0..1000). CP_PIPETTE adds a pipette button beside the preview where the user can pick a colour anywhere on the screen (Windows, X11, the Wayland / Flatpak screenshot portal, Chromium's EyeDropper; not shown elsewhere): the picked colour (alpha kept) comes back as EV_ACT | EV_COMMIT of the picker's next pass. The pick itself is ui.pick_color() (section 21).

Containers

ui.tabs(ID_TABS, &mut self.tab, &["Allgemein", "Erweitert"]);
if self.tab == 0 {
    ui.next_size(0, 200);
    let (first, end) = ui.list_begin(ID_LIST, &mut self.sel, 1000, 0); // 1000 rows, default height
    for i in first..end {                                              // only the visible rows
        if ui.list_item(i, &format!("Eintrag {}", i + 1)) & EV_DOUBLE != 0 {
            ui.cmd_run(CMD_OPEN, i as u32);
        }
    }
    let (_ev, _v) = ui.list_end(&mut self.sel);
} else {
    if ui.expander_begin(ID_EXP, "Erweiterte Einstellungen", &mut self.exp) != 0 {
        ui.checkbox(ID_AUTO, "Automatisch speichern", &mut self.auto);
    }
    ui.expander_end();
}
  • scroll_begin(id, SC_V | SC_H | SC_NOBAR | BOX_* flags) / scroll_end(): a scroll view (give it a size, e.g. next_size(0, -1)); scroll_to, scroll_pos, scroll_extent.
  • list_begin(id, &mut sel, count, row_h | LF_REORDER) -> (first, end): emit rows first..end with list_item(i, label) or list_item_begin(i) ... any widgets ... list_item_end(); list_end_full(&mut sel) -> ListEnd { ev, sel, drop }: EV_ACT selection changed, EV_DOUBLE; with LF_REORDER, EV_DRAG and drop = Some((from, to)) (the gallery's "Listen" section moves the item). list_end(&mut sel) -> (EV_*, value) is the older form: value = from | to << 16, so it reports no move from or to a row past 65 535.
  • tabs(id, &mut sel, names), expander_begin(id, header, &mut open) (non-zero: emit the content) / expander_end(), scrollbar(id, &mut pos, content, view, vertical) for custom canvases.
  • Only what changed is drawn (dirty regions: every command is hashed into 32 × 32 px cells and compared with the last frame). When a scroll view's content only moved, the pixels it still shows are copied in the framebuffer and just the band that came into view (and what really changed) is drawn -- byte for byte what a full redraw gives. Scroll views, lists, data views, vlist, the document and code views and multi-line text boxes do this. A widget of your own that scrolls its content by drawing it at origin - offset can join in: call ui.scroll_copy_begin(id, ox, oy) right after its clip_push (ox, oy: window px of the content's origin, i.e. its place minus the scroll offset; i64 for long contents) and ui.scroll_copy_end() before the clip_pop. Content that does not move with the origin (a sticky header) is simply drawn again; text, icons and images are copied, rounded corners, circles, lines and Draw objects are drawn again (the rasterizer works in absolute coordinates). Whether a frame copies is measured per view: copying costs memory bandwidth, so flat content (cards, backgrounds) is cheaper to fill again.

Images, custom drawing, canvases

  • image(id, &Rc<Surface>, ver) shows a surface at its natural size (or next_size); bump ver when its pixels change (the dirty-region renderer compares it).

  • Drawing between widgets, in physical pixels on the current layer: draw_color(argb), draw_rect, draw_rrect, draw_frame, draw_text(x, y, s, FONT_* | size_fx << 8), draw_icon(IC_*, x, y, size_fx), draw_circle / draw_line (24.8 fixed point = px × 256), draw_image(&rc, ver, x, y, w, h), draw_clip / draw_unclip. Colours of the theme come from ui.color(T_*).

    let r = ui.last_rect();
    let c = ui.color(T_ACCENT);
    ui.draw_color(c);
    ui.draw_rect(r[0], r[1] + r[3] - ui.hair(), r[2], ui.hair());
  • canvas(id, Some(draw), user, version) is a custom area with full pointer input. The draw object implements ui::Draw and runs at render time with the clip set to the widget; it gets a Gfx (the draw context dc, the target surface sf, the text engine; g.shapes() for anti-aliased rounded rectangles, circles and lines). It always runs on the UI thread (large redraws draw the other commands on several threads, section 9), and the clip may be only a part of the widget (a dirty rectangle, a row band): draw the same pixels whatever the clip. Share the data it draws through Rc / RefCell / Cell:

    struct Board {
        img: RefCell<gfx::Surface>,
    }
    
    impl Draw for Board {
        fn draw(&self, g: &mut Gfx, r: [i32; 4]) {
            g.dc.set_color(0xFFFF_FFFF);
            g.dc.fill(g.sf, r[0], r[1], r[2], r[3]);
            g.dc.blit(g.sf, &self.img.borrow(), r[0], r[1]);
            g.dc.set_color(0xFF00_78D4);
            g.shapes().stroke_rrect(r[0] + 4, r[1] + 4, r[2] - 8, r[3] - 8, 6, 2);
        }
    }
    
    // in frame (board: Rc<Board>, board_ver: u32):
    ui.next_size(320, 200);
    let d: DrawRef = self.board.clone();
    let inp = ui.canvas(ID_CANVAS, Some(d), 0, self.board_ver).clone();
    if inp.ev & EV_HELD != 0 && inp.btn & (1 << BTN_LEFT) != 0 {
        let mut img = self.board.img.borrow_mut();
        let mut dc = gfx::Dc::new(img.w, img.h);
        dc.set_color(self.color);
        for p in &inp.pts {                       // every move point since the last frame
            dc.fill(&mut img, p[0] - 2, p[1] - 2, 5, 5);
        }
        self.board_ver += 1; // the content changed: the canvas must be redrawn
        ui.repass();         // ... in this frame (its command carries the old version)
    }

    UiInput has the position relative to the widget (x, y, press_x, press_y), buttons (btn, pressed, released, bit 1 << BTN_*), wheel_x / wheel_y (120 per notch), mods, all move points pts, the first unconsumed key, and pen data (pressure, ptype, ppress, tilt; legacy/ASMLIB/docs/modules/PEN_INPUT.md). The cursor shape comes from next_flags(CUR_* << HB_CURSOR_SHIFT), the crosshair without one; with HB_CURSOR_SET the bits count as given, so CUR_ARROW (0) is the arrow (a web page's cursor changes with what lies under the pointer: set it every frame). ui.canvas returns a borrow of ui: clone the input before calling more ui methods. canvas_damage(id, x, y, w, h) redraws a part without a version change.

  • The wheel (UiInput): wheel_x / wheel_y count notches, 120 each (up and right positive). What a notch scrolls is the system's setting: ui.wheel_lines() lines (Windows' mouse settings, SPI_GETWHEELSCROLLLINES; KDE's WheelScrollLines; 3 elsewhere and in headless runs; plat::WHEEL_PAGE: a page), ui.wheel_chars() characters sideways; ui.wheel_notch_px(line_px, page_px, horizontal) is that in pixels for a view's lines. The library's views follow it (scroll views, lists and documents: lines of WHEEL_LINE_DIP = 16 DIP, 48 DIP a notch with three; text boxes, editors and the terminal: their own lines); a change reaches the app as UIC_SETTINGS. A touchpad, a trackpad or a high-resolution wheel scrolls by pixels: wheel_precise is set and wheel_px_x / wheel_px_y hold the turn in physical pixels (up and right positive), which an app scrolls by at once, without smooth scrolling -- macOS' trackpad and Wayland's fingers give pixels (plat::WHEEL_PIXELS), Windows' precision touchpads and high-resolution wheels fine steps of the 120 (plat::WHEEL_FINE: a delta that is no multiple of 120, or one from a touchpad), turned into pixels as wheel_lines() lines of 16 DIP per 120 (Chromium takes 100/3 DIP a line; a browser that wants its distances scales Windows' pixels by 25/12); wheel_x / wheel_y say the same turn in notches, the fractions of both carried to the next turn. X11 has notches only (its smooth scrolling through XInput 2 is not read yet), the browser host 120 per notch as before:

    let inp = ui.canvas(ID_PAGE, Some(d), 0, self.ver).clone();
    if inp.wheel_precise {
        self.page.scroll_px(inp.wheel_px_x, -inp.wheel_px_y);        // a touchpad: at once
    } else if inp.wheel_x != 0 || inp.wheel_y != 0 {
        let (line, page) = (self.page.line_px(), self.page.height_px());
        let dy = -inp.wheel_y * ui.wheel_notch_px(line, page, false) / 120; // a page: WHEEL_PAGE
        let dx = inp.wheel_x * ui.wheel_notch_px(line, page, true) / 120;
        self.page.scroll_smooth(dx, dy);
    }

    Scripts turn the wheel with wheel S DY [DX] [fine|pixels] (viewtest tests/wheel.uis, gallery tests/wheel.uis); system env jfgui_WHEEL_LINES N|page and system settings other play the system's setting.

  • More cursors (a web page's CSS cursor): the 4 flag bits hold the first shapes (CUR_ARROW .. CUR_NONE, CUR_CUSTOM); ui.cursor_next(shape) gives the next hit box (a canvas, a button, hit_rect) any shape and wins over its flags -- CUR_NOT_ALLOWED, CUR_NO_DROP, CUR_GRAB, CUR_GRABBING, CUR_HELP, CUR_PROGRESS, CUR_ZOOM_IN, CUR_ZOOM_OUT, CUR_CELL, CUR_VTEXT, CUR_ALIAS, CUR_COPY, CUR_CONTEXT_MENU, CUR_ALL_SCROLL, CUR_COL_RESIZE, CUR_ROW_RESIZE and the edges and corners CUR_SIZE_N / _S / _E / _W / _NE / _NW / _SE / _SW (CUR_X0 .. CUR_X_END), CUR_CUSTOM too. Wayland with cursor-shape, the browser and macOS (most) have all of them; Windows has not-allowed, help, progress and the resize shapes, X11's cursor font a few more. Grab, grabbing, zoom-in / -out, cell, vertical text, alias, copy and context menu are drawn on Windows, X11 and Wayland without cursor-shape (lib/plat/cursor_art.rs: small bitmaps at the size of the system's cursors for the window's dpi, made once per size; white with a black outline as Windows' own, on X11 black with a white outline as the Adwaita and Breeze themes; without RENDER X11 keeps its cursor font's shapes). Where a system still has no such cursor it shows plat::cursor_fallback(shape)'s (macOS: zoom and cell the crosshair; an edge: its double arrow). ui.cursor_at(x, y) is the cursor at a point (px) in the last pass. A page's own pictures (cursor: url(..)) are custom cursors: ui.cursor_new(draw, w, h, hot) -> a handle, ui.cursor_custom(handle) + cursor_next(CUR_CUSTOM) shows it, ui.cursor_replace(handle, draw, w, h, hot) draws it anew under the same handle, ui.cursor_free(handle) gives the slot back (32 at most):

    let shape = match css { Css::NotAllowed => CUR_NOT_ALLOWED, Css::Grab => CUR_GRAB, Css::Url(k) => {
        ui.cursor_custom(self.page_cursors[k]); CUR_CUSTOM }, .. };
    ui.cursor_next(shape);
    let inp = ui.canvas(ID_PAGE, Some(d), 0, self.ver).clone();

    apps/viewtest tests/cursors.uis.

  • A canvas that takes the keyboard (a web page, a terminal, an emulator): with next_flags(HB_KEYS) every key is the canvas's while it has the focus (a press gives it the focus, ui.focus(id) too) and no popup of the window is open (a menu keeps its keys, and key_take gives none then): no accelerator of the command table, no Tab, arrow or F6 of the keyboard navigation (section 27), no Enter / Space action and no ui.undo_keys takes one. The canvas takes them with ui.key_take() (the first unconsumed key, VK | mods << 16, consumed; 0 when none is left) and typed text with ui.text_take; a key it does not use goes back to the command table with ui.accel_run(key) (true when a command ran). Unlike HB_TEXT there are no text box rules: no reserved keys, no input method, no on-screen keyboard. Keys the app must keep for itself (Ctrl+T, Ctrl+Tab in a browser) it takes before it hands the rest on:

    ui.next_flags(HB_KEYS | HB_CURSOR_SET | self.cursor << HB_CURSOR_SHIFT);
    let inp = ui.canvas(ID_PAGE, Some(d), 0, self.ver).clone();
    if inp.ev & EV_FOCUS != 0 {
        loop {
            let k = ui.key_take();
            if k == 0 {
                break;
            }
            if reserved(k) {
                ui.accel_run(k);         // the app's own shortcut
            } else {
                self.page.key_down(k);   // the engine; one it did not use comes back as accel_run(k)
            }
        }
    }

    apps/viewtest is such a page (tests/keys.uis).

    A page that passes the keyboard on as it is (a web page's keydown / keyup with key, repeat, code and location) takes ui.key_event_take() instead of key_take: the next KeyEvent { vk, mods, down, repeat, scancode, location, ch, dead, code } of the batch until None -- downs and ups, the system's auto-repeat, the key's place on the keyboard whatever the layout (code: a USB HID usage, the same on every platform, plat::KC_*, section 39; plat::key_code_name(code) is the web page's code name; scancode: the platform's own code, Windows' scan code with 0xE0.. for extended keys, Linux's evdev code, the usage on macOS, iOS and in the browser; both 0 on Android) and location (KL_STANDARD, KL_LEFT / KL_RIGHT for the two Shift, Ctrl, Alt and Windows keys, KL_NUMPAD). ch is the character the keyboard layout gives the key with Shift, Caps Lock and AltGr as they are but without Ctrl, Alt and the Windows / Super key -- what a browser names the key also when Ctrl or Alt is held and the key types nothing: Ctrl+Z on a German keyboard (whose Z sits at the US layout's Y) has vk VK_Z and ch 'z', Ctrl++ there VK_OEM_PLUS (the US layout's "=") and '+', AltGr+Q '@', Ctrl+Shift+Z 'Z'; 0 for keys that type no character (Enter, Tab, Esc, Backspace, the arrows, F1 ...). dead: a dead key, ch its spacing character (´ ^ ~). Windows asks the layout (ToUnicodeEx, from Windows 10 1607 on: the pending dead key stays for the text), Linux the keymap of X11 and Wayland, macOS charactersIgnoringModifiers; the browser and Android give 0. A key's up gives a pass of its own while such a canvas has the focus. A down taken here is taken for key_take too; the text still comes through text_take:

    while let Some(k) = ui.key_event_take() {
        if k.down && reserved(k.vk | k.mods << 16) {
            ui.accel_run(k.vk | k.mods << 16);
        } else {
            let key = char::from_u32(k.ch).filter(|_| k.ch != 0);   // None: a named key ("Enter")
            self.page.key(k.down, k.vk, key, k.dead, k.mods, k.repeat, k.scancode, k.location);
        }
    }

    Scripts hold keys with keydown CHORD [scan N | code N] [left|right|numpad] [char "c"|none] [dead] and let them go with keyup CHORD ... (code N: the key at USB HID usage N, this platform's scan code for it); a script's keys have the US layout's characters, char "c" gives another layout's (viewtest tests/keyraw.uis, tests/keychar.uis). The platform's events carry the character in Event::y with the location (plat::key_y, key_location, key_char, key_dead).

    An input method for a field the page draws itself (a web page's <input>, Japanese or Chinese typed into it): while such a field has the focus, ui.ime_enable(true, IP_TEXT) (also IP_URL, IP_EMAIL, IP_NUMBER, IP_PHONE, IP_SEARCH; IP_PASSWORD takes the input method away on Windows, keeps the keys from IBus on X11 and tells Wayland, also when the purpose changes from one field to the next) and every frame ui.ime_pos(x, y, h) at the field's caret (px of the window: the candidates follow it); ui.ime_enable(false, 0) when it loses the focus. The composition is the app's to draw at the caret, underlined: ui.ime_preedit() gives its text and caret (a byte offset; empty when none is going on), a change gives a pass. Windows hides the input method's own composition window then (its candidate list stays); IBus and Wayland's text input have none. The committed text comes through text_take as typed text does. The library's code and rich-text editors draw the composition inline too; its text boxes leave it to the input method's window.

    let want = self.page.focus_editable() && inp.ev & EV_FOCUS != 0;
    if want != self.ime_on { self.ime_on = want; ui.ime_enable(want, IP_TEXT); }
    if want {
        let c = self.page.caret_rect();                     // px of the window
        ui.ime_pos(c[0], c[1], c[3]);
        self.page.set_composition(&ui.ime_preedit());       // drawn by the page at its caret
        let typed = ui.text_take(256);                      // commits and typed text
        self.page.insert_text(&typed);
    }

    Scripts compose with preedit "text" [CURSOR] and commit with commit "text" (viewtest tests/ime.uis).

  • Zoom and pan without a re-raster: right after the canvas's command, ui.canvas_gpu(CanvasDesc { id, name, rect, view, ver, content, gpu, exact_pan }) says what it shows. content is an Rc<dyn CanvasContent> whose draw_view(g, view, rect) draws the content through any CanvasView { scale, ox, oy } (window px = o + content * scale), opaque, what the Draw paints at that view; ver stands for everything it shows, ui.canvas_gpu_damage(id, r) reports a changed content rectangle. With the GPU output, while the view moves and the content stays, the picture comes from tiles (256 x 256 textures, drawn once, kept under a budget) that the GPU draws with the transform; a moment after the last move the CPU draws it, so at rest it is the CPU path's byte for byte. gpu: CanvasGpu::Pan only moves by whole pixels at the same scale (exact when the raster does not depend on the place), Zoom also scales the tiles while a zoom runs (soft for a moment), Cpu never. On other targets, without a GPU and in headless runs it does nothing: the code is the same, the Draw paints every frame. Everything over the canvas (selection, handles, anything recorded after it) stays recorded commands. image_view (ImageViewState::gpu) and diagram (DiagramState::gpu) do this themselves. While a canvas is apart ui.fb() lacks its view: ui.gpu_settle() first, outside a pass. Details and numbers: GPU.md "Leinwände".

  • Direct pixel work (paint programs): gfx::Surface::new(w, h, FMT_PARGB), a gfx::Dc (fill, blit, blit_scaled, clip and origin), gfx::path / raster / stroke for anti-aliased vector paths, gfx::blendmode, gfx::tmask (selection masks), gfx::flood, gfx::gradient; the text engine in the field ui.text (text::Text) draws text into any surface (set_font, draw, measure). img_core::ops rotates, flips, scales and crops, img_core::resample resizes with filters, img_core::xform applies affine transforms.

Source: docs/GUIDE.md in the JFLib repository.