Widgets et mise en page
Une application décrit son interface dans une seule fonction. JFLib s’occupe de la mise en page, des saisies, du focus et du dessin.
Boutons
Boutons standard, accentués, à icône et boutons partagés.
if ui.accent_button(ID_SAVE, "Save") & EV_ACT != 0 { self.save(); } ui.button(ID_CANCEL, "Cancel"); ui.icon_button(ID_SHARE, IC_SHARE, "Share"); // the label becomes the tooltip if ui.split_button(ID_EXPORT, "Export") & EV_ACT != 0 { self.export("pdf"); // the main part; the arrow opens the flyout } if ui.flyout_begin(ID_EXPORT, FL_BELOW) { if ui.menu_item(ID_EXPORT_PNG, "As a picture") & EV_ACT != 0 { self.export("png"); } } ui.flyout_end();
Choix
Cases à cocher, boutons radio et interrupteurs.
ui.checkbox(ID_GRID, "Show the grid", &mut self.grid); for (i, name) in ["Red", "Green", "Blue"].iter().enumerate() { ui.radio(ID_COLOR + i as u32, name, &mut self.color, i as i32); } ui.switch(ID_WIFI, "Wi-Fi", &mut self.wifi);
Valeurs
Curseurs et barres de progression.
const SIZE: Range = Range::new(1, 100, 1, 0); // min, max, step, flags ui.next_size(200, 0); // 200 wide, natural height if ui.slider(ID_SIZE, &mut self.size, &SIZE) & EV_COMMIT != 0 { self.redraw(); // the slider was let go } ui.progress(ID_PROGRESS, self.done, self.total);
Saisie de texte
Champs de texte, champs de mot de passe et champs numériques.
const PORT: Range = Range::new(1, 65535, 1, 0); ui.textbox(ID_NAME, Some("Your name"), &mut self.name, 64); // at most 64 bytes ui.textbox(ID_PASSWORD, Some("Password"), &mut self.password, 128 | TB_PASSWORD); ui.number_box(ID_PORT, &mut self.port, &PORT); ui.next_size(-1, 120); ui.textbox(ID_NOTE, None, &mut self.note, 4096 | TB_MULTI | TB_WRAP);
Listes et onglets
Listes, onglets et zones de défilement.
ui.tabs(ID_TABS, &mut self.tab, &["Files", "About"]); if self.tab == 0 { ui.next_size(-1, 200); let count = self.files.len() as i32; let (first, end) = ui.list_begin(ID_LIST, &mut self.sel, count, 0); for i in first..end { // only the rows in view if ui.list_item(i, &self.files[i as usize]) & EV_DOUBLE != 0 { ui.cmd_run(CMD_OPEN, i as u32); } } ui.list_end(&mut self.sel); } else { ui.next_size(-1, -1); ui.scroll_begin(ID_ABOUT, SC_V); ui.text(TS_BODY | TX_WRAP, ABOUT); ui.scroll_end(); }
Barres d’outils et rubans
Barres d’outils simples et rubans Office complets, avec touches d’accès et Backstage.
// a toolbar: a row of buttons for commands ui.box_begin(0, BOX_H | BOX_LAYER | BOX_XCENTER | PAD_4, 4); ui.cmd_button(CMD_OPEN, ST_ICON_ONLY | ST_SUBTLE); ui.cmd_button(CMD_SAVE, ST_ICON_ONLY | ST_SUBTLE); ui.box_end(); // a ribbon: tabs, and groups that shrink and fold away when the window gets narrow ui.ribbon_tabs(ID_RTABS, &mut self.rtab, &[RibbonTab::new("Home"), RibbonTab::new("Insert")]); let groups = [ RibbonGroup::new(ID_CLIPBOARD, "Clipboard", 120, 60), // width, narrow width RibbonGroup::new(ID_FONT, "Font", 160, 80), ]; let layout = ui.ribbon_begin(ID_RIBBON, &groups); for (i, group) in groups.iter().enumerate() { let Some(mode) = ui.ribbon_group_begin(&layout, i, group) else { continue }; if i == 0 { if ui.ribbon_large_button(ID_PASTE, "Paste", IC_PASTE, 0) & EV_ACT != 0 { self.paste(); } } else { ui.ribbon_button(ID_BOLD, "Bold", IC_BOLD, 0); } ui.ribbon_group_end(mode, group.label); } ui.ribbon_end();
Grille de disposition
Disposez les widgets en lignes et en colonnes.
// three columns: as wide as the widest label, the rest, 120 ui.gridbox_begin(ID_FORM, &[0, -1, 120], BOX_CARD | pad(16), 8); ui.text(TS_BODY, "Name"); ui.textbox(ID_NAME, None, &mut self.name, 64); ui.button(ID_PICK, "Choose…"); ui.text(TS_BODY, "Note"); ui.next_span(2, 1); // the field takes the last two columns ui.textbox(ID_NOTE, None, &mut self.note, 256); ui.gridbox_end();
Ancrage
Panneaux en groupes d’onglets et fenêtres d’outils flottantes, avec des repères de dépôt pendant le glissement. La disposition est conservée.
let panels = [ DockPanel::new(P_FILES, "Files", IC_FOLDER).at(DOCK_LEFT, 0), DockPanel::new(P_PROPS, "Properties", IC_SETTINGS).at(DOCK_RIGHT, 0), DockPanel::new(P_OUTPUT, "Output", IC_DOCUMENT).at(DOCK_BOTTOM, 0), ]; ui.dock_begin(ID_DOCK, &mut self.dock, &panels); while let Some(panel) = ui.dock_next(&mut self.dock) { match panel { DOCK_CENTER => self.document(ui), // the middle comes first P_FILES => self.files(ui), _ => {} } } if ui.dock_end(&mut self.dock) { self.layout = self.dock.save(); // DockState::load brings it back at the next start }
Popups et infobulles
Ils peuvent sortir de la fenêtre, comme leurs équivalents natifs.
ui.dropdown_button(ID_VIEW, "View"); if ui.flyout_begin(ID_VIEW, FL_BELOW) { // may reach beyond the window ui.checkbox(ID_RULER, "Ruler", &mut self.ruler); ui.checkbox(ID_GRID, "Grid", &mut self.grid); } ui.flyout_end(); ui.tooltip("What the document shows"); // of the widget before it
Mise à l’échelle
Les tailles sont indépendantes du périphérique : une interface reste nette sur tous les écrans.
ui.next_size(240, 32); // device-independent: 480 x 64 pixels at 200 % ui.button(ID_OK, "OK"); // own drawing works in pixels, ui.dp() converts let [x, y, w, h] = ui.last_rect(); let accent = ui.color(T_ACCENT); ui.draw_color(accent); ui.draw_rect(x, y + h, w, ui.dp(2));
