mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
font-manager: the details sheet's rows, sliders and texts fill its width; the filter column has one width
This commit is contained in:
@@ -45,8 +45,11 @@ pub fn install_interface_fonts(ctx: &Context, language: &str, craft_faces: &[Emb
|
||||
UiFonts::new(&I18nScripts).languages(LANGUAGES).ui_language(language).craft_faces(craft_faces).install(ctx);
|
||||
}
|
||||
|
||||
/// The filters column takes the width of its widest section; the list and toolbar take the rest.
|
||||
const PANES: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)];
|
||||
/// The filters column, whatever the list beside it shows; the list and toolbar take the rest.
|
||||
const PANES: [ColumnWidth; 2] = [ColumnWidth::Fixed(248.0), ColumnWidth::fill(1.0)];
|
||||
/// The panes of a panel less than [`WIDE_PANEL`] wide.
|
||||
const NARROW_PANES: [ColumnWidth; 2] = [ColumnWidth::Fixed(212.0), ColumnWidth::fill(1.0)];
|
||||
const WIDE_PANEL: f32 = 860.0;
|
||||
|
||||
/// Preview downloads: at most this much per file, and this many faces in a session.
|
||||
const PREVIEW_LIMITS: Limits = Limits { max_file_bytes: 64 << 20, max_faces_per_file: 512, max_added_faces: 20_000 };
|
||||
@@ -936,6 +939,7 @@ impl<'a> FontsPanelView<'a> {
|
||||
let search = ui.scope_id().with("search");
|
||||
let folder = env.folder();
|
||||
let wake = panel.jobs.waker();
|
||||
let panes = if ui.available_width() < WIDE_PANEL { &NARROW_PANES } else { &PANES };
|
||||
let mut begun = false;
|
||||
let mut shown = Stack::new().fill().label(words.panel.clone()).command_scope(FontsCommand::SCOPE).show(ui, |ui, root| {
|
||||
if !std::mem::replace(&mut begun, true) {
|
||||
@@ -946,11 +950,11 @@ impl<'a> FontsPanelView<'a> {
|
||||
}
|
||||
root.publish(FontsCommand::Find, CommandState::new());
|
||||
panel.top_bar(ui, &browse, texts.format, search);
|
||||
let panes = Grid::new(&PANES).fill().show(ui, |ui, _| {
|
||||
let shown = Grid::new(panes).fill().show(ui, |ui, _| {
|
||||
panel.filters(ui, &texts);
|
||||
panel.main(ui, &texts, &folder, host.as_ref())
|
||||
});
|
||||
panes.inner.flatten()
|
||||
shown.inner.flatten()
|
||||
});
|
||||
// A measuring run has no rows on screen, and a pass that runs again may have the wrong ones.
|
||||
let rerun = craft_ui::runtime::frame::will_rerun(ui.ctx());
|
||||
|
||||
@@ -18,7 +18,7 @@ use craft_ui::choice::{Checkbox, Radio, RadioGroup};
|
||||
use craft_ui::contract::{
|
||||
Access, ActivateOn, Bind, Collection, CollectionEvent, CollectionProps, CollectionResponse, Common, Component, ContainerProps, Cx, Entry,
|
||||
ItemOutput, MeasureCx, Name, NoValue, Outcome, PartsCx, Props as _, Role, Scroll, SelectMode, Show as _, ShowCollection as _, ShowContainer as _,
|
||||
Sizing, WrapWidth, clicked,
|
||||
Sizing, clicked,
|
||||
};
|
||||
use craft_ui::display::{Badge, Progress, Shade, Spinner, Text};
|
||||
use craft_ui::form::{SliderField, SliderFieldLayout};
|
||||
@@ -203,7 +203,7 @@ impl FontsPanel {
|
||||
|
||||
pub(crate) fn filters(&mut self, ui: &mut Ui, texts: &Texts<'_>) {
|
||||
let browse = texts.browse;
|
||||
Stack::new().scroll(Scroll::vertical()).wrap_width(WrapWidth::Column).label(browse.filters.clone()).show(ui, |ui, _| {
|
||||
Stack::new().fill().scroll(Scroll::vertical()).label(browse.filters.clone()).show(ui, |ui, _| {
|
||||
match self.tab {
|
||||
Tab::Catalogue => self.catalogue_filters(ui, texts),
|
||||
Tab::Installed => self.installed_filters(ui, texts),
|
||||
@@ -271,7 +271,7 @@ impl FontsPanel {
|
||||
.activate(ActivateOn::Click)
|
||||
.allow_empty(false)
|
||||
.header(false)
|
||||
.sizing(Sizing::Content)
|
||||
.sizing(Sizing::FillWidth)
|
||||
.natural_height(true)
|
||||
.selection(Bind::given(current))
|
||||
.show_items(ui, &CardKeys::new(&rows, |_| None), &mut |key, _| {
|
||||
|
||||
@@ -18,19 +18,22 @@ use craft_host::Host;
|
||||
use craft_theme::variant::{Emphasis, Tone};
|
||||
use craft_ui::buttons::{Button, Link, SplitButton};
|
||||
use craft_ui::contract::overlay::Outside;
|
||||
use craft_ui::contract::{Bind, CollectionEvent, Entry, NoValue, Outcome, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked};
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, Entry, NoValue, Outcome, Props as _, Show as _, ShowCollection as _, ShowContainer as _, Sizing, clicked,
|
||||
};
|
||||
use craft_ui::dialog::Dialog;
|
||||
use craft_ui::display::{Badge, Progress, Shade, Text};
|
||||
use craft_ui::layout_components::{Grid, Row, Stack};
|
||||
use craft_ui::notices::{Notice, NoticeAction};
|
||||
use craft_ui::primitives::Wrap;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::runtime::focus::Initial;
|
||||
use craft_ui::style::Variant;
|
||||
use craft_ui::text::TextField;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use self::rows::{Action, Lines, StyleLine, StyleList, StyleRow};
|
||||
use crate::axes::{AxisSliders, AxisValues, FontAxis, read_axes};
|
||||
use crate::axes::{AxisSliders, AxisValues, FontAxis, OpticalSize, read_axes, shown_axes};
|
||||
use crate::index::{Family, FontFile, Index, script_name, source_label};
|
||||
use crate::panel::app::{
|
||||
Detail, FontsPanel, FontsPanelWords, NotCopied, Pending, category_label, family_key, regular, source_name, style_count, style_name,
|
||||
@@ -50,8 +53,13 @@ const HERO_POINTS: f32 = 96.0;
|
||||
/// The most languages the sheet lists; the rest are counted.
|
||||
const LANGUAGES_SHOWN: usize = 60;
|
||||
|
||||
/// The lines of a licence or NOTICE text in view; the rest scrolls.
|
||||
/// The most lines of a licence or NOTICE text in view; the rest scrolls.
|
||||
const LEGAL_LINES: usize = 10;
|
||||
/// The lines its box has for a shorter text: the least of a multi-line field.
|
||||
const LEGAL_LEAST_LINES: usize = 2;
|
||||
|
||||
/// The sheet's sliders show the face's optical sizes, which its samples are drawn at.
|
||||
const OPTICAL_SIZE: OpticalSize = OpticalSize::Slider;
|
||||
|
||||
/// The facts' labels over their values.
|
||||
const FACT_COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)];
|
||||
@@ -396,14 +404,16 @@ impl<'a> DetailsSheet<'a> {
|
||||
let points = panel.settings.size.max(MIN_SAMPLE_POINTS);
|
||||
let mut todo: Vec<Do> = Vec::new();
|
||||
let mut open = true;
|
||||
// The sheet is for reading: no field of it takes the keyboard when it opens.
|
||||
let mut shown = Dialog::prompt(sheet.title.clone())
|
||||
.initial_focus(Initial::Keep)
|
||||
.overlay(|overlay| {
|
||||
let dismiss = overlay.dismiss.outside(Outside::Absorb);
|
||||
overlay.dismiss(dismiss)
|
||||
})
|
||||
.opened(Bind::bound(&mut open))
|
||||
.show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Stack::new().fill_width().show(ui, |ui, _| {
|
||||
sheet.header(ui, &env, &words, &mut todo);
|
||||
sheet.body(ui, &env, &words, points, &mut panel.detail_axes, &mut todo);
|
||||
});
|
||||
@@ -666,21 +676,16 @@ impl Sheet {
|
||||
out.chosen.map(Some).or_else(|| out.activated.then_some(None))
|
||||
}
|
||||
|
||||
/// The styles, and beside them (or below, when narrow) the facts and the languages.
|
||||
/// The styles, the axis sliders of each variable file under its name, the facts, the languages and the licence.
|
||||
fn body(&self, ui: &mut Ui, env: &Env, words: &DetailsWords, points: f32, axes: &mut HashMap<String, AxisValues>, todo: &mut Vec<Do>) {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
self.styles(ui, env, words, points, todo);
|
||||
for file in &self.axes {
|
||||
let values = axes.entry(file.sha256.clone()).or_default();
|
||||
AxisSliders::new(file.label.clone(), &file.axes, Bind::bound(values)).show(ui);
|
||||
}
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
self.side(ui, env, words);
|
||||
self.licence(ui, words, todo);
|
||||
});
|
||||
});
|
||||
self.styles(ui, env, words, points, todo);
|
||||
for file in &self.axes {
|
||||
Text::new(file.label.clone()).shade(Shade::Faint).show(ui);
|
||||
let values = axes.entry(file.sha256.clone()).or_default();
|
||||
AxisSliders::new(file.label.clone(), &file.axes, Bind::bound(values)).optical_size(OPTICAL_SIZE).show(ui);
|
||||
}
|
||||
self.side(ui, env, words);
|
||||
self.licence(ui, words, todo);
|
||||
}
|
||||
|
||||
fn styles(&self, ui: &mut Ui, env: &Env, words: &DetailsWords, points: f32, todo: &mut Vec<Do>) {
|
||||
@@ -750,8 +755,9 @@ impl Sheet {
|
||||
LegalShown::Text(text) => {
|
||||
Text::new(title.clone()).shade(Shade::Faint).show(ui);
|
||||
TextField::new(title.clone(), Bind::given(text.clone()))
|
||||
.lines(LEGAL_LINES)
|
||||
.lines(LEGAL_LEAST_LINES)
|
||||
.max_lines(LEGAL_LINES)
|
||||
.sizing(Sizing::FillWidth)
|
||||
.mono()
|
||||
.read_only(true)
|
||||
.show(ui);
|
||||
@@ -873,7 +879,8 @@ impl FamilyStyles<'_> {
|
||||
self.panel.subsets.detail_font(self.index, self.family, file, self.sample)
|
||||
}
|
||||
|
||||
/// The axes of the variable files among `files`: the subset's own once it is here, else the index's ranges.
|
||||
/// The axes of the variable files among `files` that have a slider: the subset's own once it is here, else the index's
|
||||
/// ranges.
|
||||
fn axes(&self, files: &[usize]) -> Vec<FileAxes> {
|
||||
files
|
||||
.iter()
|
||||
@@ -883,6 +890,7 @@ impl FamilyStyles<'_> {
|
||||
let own = self.subset(file).map(|font| read_axes(&font.bytes, 0)).filter(|axes| !axes.is_empty());
|
||||
FileAxes { sha256: file.sha256.clone(), label: file_label(file), axes: own.unwrap_or_else(|| index_axes(file)) }
|
||||
})
|
||||
.filter(|file| shown_axes(&file.axes, OPTICAL_SIZE).next().is_some())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,11 +105,11 @@ pub(super) struct StyleList {
|
||||
}
|
||||
|
||||
impl StyleList {
|
||||
/// A list named `label`; it is as tall as its rows, and shows `empty` while it has none.
|
||||
/// A list named `label`; it fills the width, is as tall as its rows, and shows `empty` while it has none.
|
||||
pub(super) fn new(label: impl Into<Label>, empty: impl Into<Label>) -> Self {
|
||||
StyleList {
|
||||
common: Common::new(),
|
||||
props: ContainerProps::new().sizing(Sizing::Content),
|
||||
props: ContainerProps::new().sizing(Sizing::FillWidth),
|
||||
items: CollectionProps::new().select(SelectMode::Single).natural_height(true).empty(empty),
|
||||
}
|
||||
.label(label)
|
||||
|
||||
@@ -53,14 +53,14 @@ fn lines(count: usize) -> Vec<StyleLine> {
|
||||
}
|
||||
|
||||
fn list(ui: &mut Ui, count: usize) -> StoryOutput {
|
||||
list_of(ui, &lines(count))
|
||||
list_of(ui, &lines(count), PANGRAM)
|
||||
}
|
||||
|
||||
fn list_of(ui: &mut Ui, lines: &[StyleLine]) -> StoryOutput {
|
||||
fn list_of(ui: &mut Ui, lines: &[StyleLine], sample: &str) -> StoryOutput {
|
||||
let words = Env::of(ui).words::<DetailsWords>();
|
||||
let source = Lines(lines);
|
||||
StyleList::new("Styles", words.no_styles.clone())
|
||||
.show_items(ui, &source, &mut |key, _| StyleRow::new(&lines[*key], "Hack", PANGRAM, POINTS, &words))
|
||||
.show_items(ui, &source, &mut |key, _| StyleRow::new(&lines[*key], "Hack", sample, POINTS, &words))
|
||||
.into()
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ fn style_list_variable(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let face = HeldFace::Subset(SubsetFont { key: "story/orbitron".to_owned(), bytes: VARIABLE.into() });
|
||||
let styles = [("Regular", 400.0), ("Bold", 700.0), ("Black", 900.0)];
|
||||
let lines = styles.map(|(name, weight)| StyleLine::new(name, Some(face.clone()), Action::None).at(vec![(*b"wght", weight)]));
|
||||
list_of(ui, &lines)
|
||||
list_of(ui, &lines, "Orbitron")
|
||||
}
|
||||
|
||||
#[story(StyleRow<'static>, covers = [Default], drive = Drive::Never)]
|
||||
|
||||
@@ -655,6 +655,8 @@ fn a_variable_family_draws_one_subset_at_every_axis_value() {
|
||||
assert!(rig.present(style), "no {style} row");
|
||||
}
|
||||
|
||||
rig.fx.type_text("9");
|
||||
assert!(rig.present("400"), "no field of the sheet has the keyboard when it opens");
|
||||
let weight = rig.named(Role::SLIDER, "Weight");
|
||||
assert!(rig.present("400") && !rig.present("401"));
|
||||
rig.fx.access(AccessActionKind::Increment, &weight);
|
||||
|
||||
Reference in New Issue
Block a user