JFLib

Values and colours#

ui/value.rs#

Source: lib/ui/value.rs

value -- decimal values, gradient tracks, angle dial and pan control (U1)
                                                                 [src/ui/ui_value.s]

  slider_f(id, &mut v, &rf) -> EV           slider for an f64 (RangeF): EV_ACT while the
       value changes, EV_COMMIT on release and on key steps.  Keys (focused): arrows = one
       step, PgUp / PgDn = 10 steps, Home / End = minimum / maximum.
  track_slider(id, &mut v, &rg, track) -> EV   slider for an i32 (Range) whose track shows
       the colour gradient of a Track (TK_CHECKER: over a checkerboard, for alpha);
       horizontal or RG_VERT; same keys as slider_f
  prop_slider(id, label, &mut v, &rg, default) -> EV   paint.net property row: label over
       slider + number box + reset button (i32; default NO_DEFAULT = no reset button);
       EV_ACT while the slider is dragged or a number is typed (live preview), EV_COMMIT
       on release, Enter / focus loss, key steps and reset
  prop_slider_f(id, label, &mut v, &rf, default) -> EV   the same for an f64 (None = no
       reset button).  Parts: slider = id, number box = part_id(id, 1), reset =
       part_id(id, 2); the label selects the slider in scripts.
  angle(id, &mut deg, flags) -> EV          angle dial (f64 degrees, -180 .. 180 or ANG_360
       0 .. 360, counter-clockwise, 0 = right): drag sets the angle, Shift snaps to 15
       degrees; keys: arrows 1 (Shift 15), PgUp / PgDn 15, Home 0.  Natural 64 DIP.
       Semantic value = degrees * 100.
  pan(id, &mut x, &mut y, thumb, ver, flags) -> EV   pan control: a thumbnail (surface or
       None, ver = its version) with a crosshair; drag sets the point (f64, -1 .. 1,
       PAN_UNIT 0 .. 1; y down); arrows move 1 % (Shift 10 %), Home centres.  Semantic
       value = x * 1000, max = y * 1000.
  part_id(id, k) -> id                      id of part k (0..15) of a composite widget
  fmt_f64(&v, decimals) -> String           "-12,50" with the decimal separator
  parse_f64(s) -> Some(v) / None            accepts ',' and '.' as decimal separator
  decimal_sep() / set_decimal_sep(c)        separator shown (default ',')
Shared with the styles and ui_color / ui_wheel: grad_at, px_mix, deg_atan2, deg_sincos,
Ui::cmd_track (the cmd_custom of a gradient track: track_cb / track_hash of the asm),
Ui::slider_track_draw; internal: rf_fix, rf_scaled, rf_t16, sld_*, vl_state, f_round.

No per-window state: everything lives in the app's variables and in state slots.  The
decimal separator (ui_decimal_sep) and the cache of gradient track drawings are shared.
/// prop_slider: no reset button
NO_DEFAULT: i32 = i32::MIN
  • struct RangeF RANGE_F min, max, step, decimals, flags -- descriptor of an f64 value
    • min: f64
    • max: f64
    • step: f64
    • dec: u32
    • flags: u32

impl RangeF

  • const fn new(min: f64, max: f64, step: f64, dec: u32, flags: u32) -> RangeF

  • struct Track TRACK -- the colour gradient of track_slider: TK_* flags and 1..TK_MAXN straight-ARGB stops; with TK_CUSTOM the track is drawn by custom (draw object, user value, version: bump it when the drawing changes) instead

    • flags: u32
    • n: u32
    • stops: [u32; TK_MAXN]
    • custom: Option<(DrawRef, usize, u32)>

impl Track

  • fn new(flags: u32, stops: &[u32]) -> Track TRACK flags, argb0, argb1, ... (at most TK_MAXN stops)

  • fn part_id(id: u32, k: u32) -> u32 ui_part_id(id, k) -> PART_BASE | (id << 4 | k) & 0x0FFFFFFF

  • fn deg_atan2(y: f64, x: f64) -> f64 deg_atan2(y, x) -> degrees in (-180, 180] (x87 fpatan)

  • fn deg_sincos(d: f64) -> (f64, f64) deg_sincos(degrees) -> (cos, sin) (x87 fsincos)

  • fn grad_at(tk: &Track, t: i32) -> u32 grad_at(track, t) -> colour (straight ARGB) of the gradient at t (0..65536)

  • fn px_mix(dst: u32, src: u32, k: u32) -> u32 px_mix(dst, src, k) -> per channel (dst * (255 - k) + src * k) / 255 of 0x..RRGGBB (alpha byte 0)

impl Ui

  • fn cmd_track(&mut self, x: i32, y: i32, w: i32, h: i32, tk: &Track) cmd_custom of a value slider's gradient track over (x, y, w, h): the track's own drawing (TK_CUSTOM) or the gradient (track_cb, version = track_hash) [styles' value.s]
  • fn decimal_sep(&self) -> u32 ui_decimal_sep: the separator fmt_f64 shows (and parse_f64 accepts besides ',' / '.')
  • fn set_decimal_sep(&mut self, c: u32) set ui_decimal_sep (a code point)
  • fn fmt_f64(&self, v: f64, decimals: u32) -> String ui_fmt_f64(&v, decimals) -> fixed decimals with the decimal separator; -0 is shown as 0
  • fn parse_f64(&self, s: &str) -> Option<f64> ui_parse_f64(s) -> the value, or None when s has no digits. Blanks, a sign, digits, one ',' or '.' (or the decimal separator when ASCII), digits.
  • fn slider_f(&mut self, id: u32, v: &mut f64, rf: &RangeF) -> u32 ui_slider_f(id, &mut v, &rf) -> EV_*
  • fn track_slider(&mut self, id: u32, v: &mut i32, rg: &Range, track: Option<&Track>) -> u32 ui_track_slider(id, &mut v, &rg, track) -> EV_*: i32 slider with a gradient track (None = the standard look)
  • fn prop_slider(&mut self, id: u32, label: &str, v: &mut i32, rg: &Range, default: i32) -> u32 ui_prop_slider(id, label, &mut v, &rg, default) -> EV_* (default NO_DEFAULT: no reset button)
  • fn prop_slider_f(&mut self, id: u32, label: &str, v: &mut f64, rf: &RangeF, default: Option<f64>) -> u32 ui_prop_slider_f(id, label, &mut v, &rf, default) -> EV_* (default None: no reset button)
  • fn angle(&mut self, id: u32, deg: &mut f64, flags: u32) -> u32 ui_angle(id, &mut deg, flags) -> EV_*
  • fn pan(&mut self, id: u32, x: &mut f64, y: &mut f64, thumb: Option<&Rc<Surface>>, ver: u32, flags: u32) -> u32 ui_pan(id, &mut x, &mut y, thumb, ver, flags) -> EV_* (thumb: a surface or None; ver stands for its version, as in draw_image)

ui/color.rs#

Source: lib/ui/color.rs

color -- colour swatches, the colour picker and the HSV colour wheel
                                                    [src/ui/ui_color.s, src/ui/ui_wheel.s]

  swatch(id, argb, selected) -> EV        round colour well (22 DIP or next_size); alpha 0
       draws an empty slot; EV_ACT on click, EV_RCLICK on right click
  color_picker(id, &mut argb) -> EV       spectrum (saturation x value), hue slider, preview
       and hex text; EV_ACT while the colour changes, EV_COMMIT on release.  Uses the ids
       id + 0x20000000 (spectrum) and id + 0x10000000 (hue) for its parts.
  color_picker_ex(id, &mut argb, flags) -> EV   (U1) the same with CP_ALPHA: an alpha bar
       (id + 0x30000000, checkerboard) under the hue bar; CP_FIELDS: number boxes R G B (A)
       and H S V (part_id(id, 3..9)) and a hex text box (part_id(id, 10); RRGGBB,
       AARRGGBB with CP_ALPHA, taken on Enter / focus loss) instead of the hex text;
       CP_PIPETTE: a pipette button beside the preview (part_id(id, 11); only where the
       user can pick a colour anywhere on the screen, screen.rs): the picked colour (alpha
       kept) comes with EV_ACT | EV_COMMIT on the picker's next pass.
  color_wheel(id, &mut color, flags) -> EV  (U1) hue around the circle (0 = red at the
       right, counter-clockwise), saturation from the centre to the rim; the value is not
       part of the wheel (a separate track slider) but the wheel is drawn at that value.
       color: [0xAARRGGBB] (alpha kept; the HSV state lives in a state slot so greys keep
       their hue), or with CW_HSV an HSV record [h 0..3599, s 0..1000, v 0..1000].  Drag
       sets hue and saturation; keys: Left / Right hue -/+ 1 degree, Up / Down saturation
       +/- 1 % (Shift: x10).  EV_ACT while it changes, EV_COMMIT on release / keys.
       Natural size 160 DIP.  Semantic record: K_SLIDER, value = hue, max = saturation.
  color_menu(id, &ColorMenu) -> Option<(ColorPick, rgb)>   (JD11) the swatches of an Office
       colour menu, for a flyout the app opens: the design's colours in columns with five
       shades under each (color_shades), the variant's colours, fixed colours, the colours
       used last; the swatch of the colour now is marked.  The app maps the pick to its own
       value (a design colour follows the design, a fixed one does not) and adds its own
       items ("Keine Füllung", "Weitere Farben ...").  Part ids: id + 1 .. id + 0xA0.
  color_shades(rgb) -> [(percent, rgb); 5]  the shades under a design colour: a dark colour
       gets lighter ones (+90 +75 +50 +25 +10), a light one darker ones (-5 -15 -25 -35 -50),
       the others +80 +60 +40 -25 -50; lighter = luminance toward white by that much,
       darker = luminance times (100 - n) % (DrawingML lumMod / lumOff)
  hsv_to_rgb(h, s, v) -> 0xFFRRGGBB       h 0..3599 (tenths of a degree), s / v 0..1000
  rgb_to_hsv(rgb) -> (h, s, v)            inverse (same ranges)

The wheel image is cached per widget and window (WC_MAX entries, shared by all windows): a
premultiplied image at full value for the current size (antialiased rim), and the image
scaled to the current value; only a change of size or value re-renders it.  The fields of a
CP_FIELDS picker are kept per window (WinParts::color): a picker of the same id in two windows
edits its own hex text.
  • fn hsv_to_rgb(h: u32, s: u32, v: u32) -> u32 hsv_to_rgb(h, s, v) -> 0xFFRRGGBB (h 0..3599, s / v 0..1000)

  • fn rgb_to_hsv(rgb: u32) -> (u32, u32, u32) rgb_to_hsv(rgb) -> (h 0..3599, s 0..1000, v 0..1000)

impl Ui

  • fn swatch(&mut self, id: u32, argb: u32, selected: bool) -> u32 ui_swatch(id, argb, selected) -> EV_*: the swatches of one box are one Tab stop (the selected one; arrows move inside, Space / Enter act, the menu key is a right click); next_flags(ST_NOFOCUS): a picture only, no Tab stop

  • fn color_picker(&mut self, id: u32, argb: &mut u32) -> u32 ui_color_picker(id, &mut argb) -> EV_*

  • fn color_picker_ex(&mut self, id: u32, argb: &mut u32, flags: u32) -> u32 ui_color_picker_ex(id, &mut argb, flags) -> EV_* (CP_ALPHA, CP_FIELDS, CP_PIPETTE)

  • fn color_wheel(&mut self, id: u32, color: &mut [u32], flags: u32) -> u32 ui_color_wheel(id, &mut color, flags) -> EV_*: color = [argb], or [h, s, v] with CW_HSV

  • struct ColorMenu<'a> what a colour menu offers (Ui::color_menu)

    • theme: &'a [u32] -- the design's colours, a column each (Office shows ten)
    • theme_names: &'a [&'a str] -- their names (QuickInfo, screen reader)
    • variant: &'a [u32] -- the variant's colours (may be empty)
    • standard: &'a [u32] -- the app's fixed colours
    • recent: &'a [u32] -- the colours picked last (may be empty)
    • captions: [&'a str; 4] -- the captions of the sections: design, variant, fixed, last used
    • current: Option<u32> -- the colour now (0xRRGGBB): its swatch is marked
  • enum ColorPick a swatch picked in a colour menu

    • Theme(u8, u8) -- design colour col; shade 0 the colour itself, 1 .. 5 the shades of color_shades
    • Variant(u8) -- a variant colour
    • Standard(u8) -- a fixed colour
    • Recent(u8) -- a colour used last
  • fn color_shades(rgb: u32) -> [(i32, u32); 5] the five shades under a design colour (see the file header): (percent, 0xRRGGBB)

impl Ui

  • fn color_menu(&mut self, id: u32, m: &ColorMenu) -> Option<(ColorPick, u32)> ui_color_menu(id, menu) -> the swatch picked (see the file header)

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