JFLib

ui/ribbon.rs#

Source: lib/ui/ribbon.rs

Ribbon groups and typography tiles. Additive native UI component by office_ribbon;
no legacy counterpart. Uses normal focus, semantics, popups and style tokens.
  • struct RibbonSample Explicit typography for a document sample, independent of the application's theme. Sizes and baseline displacement are 24.8 DIP; positive displacement moves downwards.

    • font: u32
    • size: i32
    • color: u32
    • highlight: Option<u32>
    • baseline_shift: i32
    • underline: bool
    • strike: bool
  • struct RibbonMetrics Style-owned ribbon geometry in DIP. A scrolling ribbon keeps every group's original arrangement; a collapsing ribbon can use the compact/flyout layouts.

    • content_height: i32
    • caption_height: i32
    • group_gap: i32
    • content_gap: i32
    • inset_x: i32 -- Zero uses the style's existing uniform ribbon_padding.
    • inset_y: i32
    • collapse_groups: bool
  • struct RibbonGroup<'a> One ribbon group. Reserve id..=id + 3 for its box, overflow and popup.

    • id: u32 -- Stable base ID, unique across the window.
    • label: &'a str -- Visible group caption and accessible overflow name.
    • width: i32 -- Preferred group width in DIP.
    • compact_width: i32 -- Smallest width that still displays all controls, in DIP.

impl<'a> RibbonGroup<'a>

  • const fn new(id: u32, label: &'a str, width: i32, compact_width: i32) -> Self Construct a group with a preferred and compact content width.

  • enum RibbonGroupMode Presentation of an open ribbon group; pass it to ribbon_group_end.

    • Inline(i32) -- Preferred or compact inline width in DIP.
    • Flyout(i32) -- Group shown in a popup at its preferred width in DIP.

impl RibbonGroupMode

  • fn width(self) -> i32 Actual width available to the controls, in DIP.

  • struct RibbonLayout Per-frame ribbon layout: shrink groups before moving them into labeled flyouts.

impl RibbonLayout

  • fn new(available_width: i32, groups: &[RibbonGroup<'_>]) -> Self Compute group presentation for an available inner width in DIP. Groups collapse from right to left; extremely narrow windows can scroll.
  • fn with_metrics( available_width: i32, groups: &[RibbonGroup<'_>], metrics: RibbonMetrics, ) -> Self Compute a layout using the active style's sizing and overflow policy.
  • fn is_collapsed(&self, index: usize) -> bool Whether a group is reachable through its labeled overflow button.
  • fn group_width(&self, index: usize) -> Option<i32> Width occupied by a group in the ribbon, in DIP.

impl Ui

  • fn ribbon_begin(&mut self, id: u32, groups: &[RibbonGroup<'_>]) -> RibbonLayout Start a style-sized ribbon (110 DIP by default). Pair with ribbon_end. All groups remain keyboard reachable; a scroll strip is the final fallback.
  • fn ribbon_group_begin( &mut self, layout: &RibbonLayout, index: usize, group: &RibbonGroup<'_>, ) -> Option<RibbonGroupMode> Begin a group's controls when visible, or render its overflow button. Only call ribbon_group_end when this returns Some.
  • fn ribbon_group_end(&mut self, mode: RibbonGroupMode, label: &str) Finish controls and draw the inline group caption; closes overflow when appropriate. Flyouts already have their named opener, so no trailing caption is painted over a nested action menu emitted while building their controls.
  • fn ribbon_group_end_launcher( &mut self, mode: RibbonGroupMode, label: &str, id: u32, action_label: &str, flags: u32, ) -> u32 Finish a group with a separately focusable dialog-launch button in its caption. id is an additional unique widget ID; action_label is its full semantic name. Activation is returned to the app, which opens its existing dialog. Disabled launchers retain their label and cannot be invoked through keyboard or agents.
  • fn ribbon_end(&mut self) Finish the ribbon begun with ribbon_begin.
  • fn ribbon_button_width(&mut self, label: &str, icon: u32, flags: u32) -> i32 Natural action width in DIP, including the style's icon, label and menu spacing. Measuring neither consumes next_* hints nor creates a widget. Use it when composing translated ribbon columns before ribbon_begin.
  • fn ribbon_button(&mut self, id: u32, label: &str, icon: u32, flags: u32) -> u32 Compact ribbon action with clipped drawing, native focus and a full tooltip. ST_ICON_ONLY, ST_LARGE, ST_CHECKED and ST_DISABLED are supported.
  • fn ribbon_large_button(&mut self, id: u32, label: &str, icon: u32, flags: u32) -> u32 Large ribbon action: the style draws its icon above a visible caption. It is one normal focusable, inspectable button. Use next_size to override its natural style size; checked/disabled flags keep their ordinary meaning.
  • fn ribbon_menu_button(&mut self, id: u32, label: &str, icon: u32, flags: u32) -> u32 Ribbon-styled menu opener. id is also the popup identifier. Its natural dimensions, icon, menu indicator and enabled state come from the style.
  • fn ribbon_stacked_split_button( &mut self, id: u32, menu_id: u32, label: &str, menu_label: &str, icon: u32, flags: u32, ) -> u32 Large split action with an icon hit area above its menu caption. Both parts remain independently focusable and discoverable through semantics. Pair the menu_id with a normal flyout. Alt+Down/F4 opens the caption menu.
  • fn ribbon_split_button( &mut self, id: u32, menu_id: u32, label: &str, menu_label: &str, icon: u32, flags: u32, ) -> u32 A large primary action beside an independently focusable dropdown. id identifies the primary action; menu_id identifies both the dropdown button and its popup. Both IDs must be unique. menu_label is a full semantic name, not an unlabeled chevron. Pair with flyout_begin(menu_id, ..) and flyout_end immediately afterwards to provide actual secondary actions. Returns primary EV_* flags plus EV_OPEN while the dropdown popup is open. Tab reaches both parts; Enter/Space activate the focused part. Alt+Down or unbound F4 on the main part forwards to the existing dropdown keyboard path.
  • fn ribbon_tile( &mut self, id: u32, label: &str, preview: &str, typography: u32, selected: bool, ) -> u32 Typography preview tile for a style gallery; selection is exposed semantically. typography is a TS_* style; use next_size to set a compact gallery width.
  • fn ribbon_font_tile(&mut self, id: u32, label: &str, preview: &str, typography: u32, selected: bool, face: Option<(u32, i32, u32)>) -> u32 A gallery tile with an optional document font, 24.8-DIP size and ARGB ink. The surrounding control follows the application theme; the sample stays document-colored.
  • fn ribbon_sample_tile(&mut self, id: u32, label: &str, preview: &str, typography: u32, selected: bool, sample: Option<RibbonSample>) -> u32 Style-gallery tile with explicit highlight, baseline and text decorations.

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