mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
Merge branch 'pdf-port/sync-fw-widgets' into pdf-port/sync
This commit is contained in:
51 files changed
+299
-831
No files matched your search
@@ -298,17 +298,6 @@ impl Component for Button<'_> {
|
||||
if self.loading { Sense::FOCUS } else { Sense::CLICK | Sense::FOCUS }
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A loading button declares the slot of its spinner, which paints as the face of its part.
|
||||
fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
if !self.loading {
|
||||
return;
|
||||
}
|
||||
let (content, rtl) = (cx.content_rect, cx.flow.is_rtl());
|
||||
let spinner = face::spinner_rect(cx, &self.spec(cx.resolved.label), &cx.style.face, cx.style.icon.side, content, rtl);
|
||||
if let Some(rect) = spinner {
|
||||
cx.part(SPINNER, rect);
|
||||
=======
|
||||
/// A loading button declares the slot of its spinner, which paints as the face of that part; any other button with
|
||||
/// a picture declares the picture's box, where `paint` shows it.
|
||||
fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
@@ -322,7 +311,6 @@ impl Component for Button<'_> {
|
||||
&& let Some(rect) = face::lead_rect(cx, &self.spec(cx.resolved.label, cx.style), &cx.style.face, cx.style.icon.side, area, rtl)
|
||||
{
|
||||
cx.part(PICTURE, rect);
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,9 @@ use crate::contract::MemoProps;
|
||||
use crate::runtime::env::EnvValue;
|
||||
|
||||
pub use button::{Button, ButtonOutput, ButtonStyle};
|
||||
<<<<<<< HEAD
|
||||
pub use command_search::{CommandSearch, CommandSearchStyle};
|
||||
pub use icon_button::{IconButton, IconButtonStyle, PopupMark, PressFocus};
|
||||
=======
|
||||
pub use face::Arrangement;
|
||||
pub use icon_button::{IconButton, IconButtonStyle, PopupMark};
|
||||
>>>>>>> origin/next
|
||||
pub use icon_button::{IconButton, IconButtonStyle, PopupMark, PressFocus};
|
||||
pub use link::{Link, LinkStyle};
|
||||
pub use split_button::{SplitButton, SplitButtonStyle, SplitMenu, SplitOutput};
|
||||
pub use toggle_button::{ToggleButton, ToggleButtonStyle};
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
//! Stories of the buttons.
|
||||
|
||||
<<<<<<< HEAD
|
||||
use super::{Button, CommandSearch, IconButton, Link, PressFocus, SplitButton, ToggleButton};
|
||||
use crate::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Validity};
|
||||
use crate::display::{Shade, Text};
|
||||
use crate::layout_components::{Grid, Row};
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::env::Message;
|
||||
use crate::style::DataColor;
|
||||
=======
|
||||
use super::{Arrangement, Button, ControlPlace, GroupLevel, IconButton, Link, SplitButton, SplitMenu, ToggleButton};
|
||||
use crate::contract::{BodyCx, Entry, LeastWidth, Props as _, Show as _, ShowContainer as _, Sizing, Validity};
|
||||
use super::{Arrangement, Button, CommandSearch, ControlPlace, GroupLevel, IconButton, Link, PressFocus, SplitButton, SplitMenu, ToggleButton};
|
||||
use crate::contract::{Bind, BodyCx, Entry, LeastWidth, Props as _, Show as _, ShowContainer as _, Sizing, Validity};
|
||||
use crate::display::{Picture, Shade, Text};
|
||||
use crate::layout_components::{Grid, Row, Stack};
|
||||
use crate::list::ThumbAspect;
|
||||
@@ -20,7 +11,6 @@ use crate::runtime::commands::EditCommands;
|
||||
use crate::runtime::env::{Message, with_env};
|
||||
use crate::style::{DataColor, SurfaceKind};
|
||||
use crate::testing::pictures::sample_picture;
|
||||
>>>>>>> origin/next
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use craft_behavior::{ColumnWidth, IconId, Mixed, Proposal};
|
||||
use craft_theme::{ControlSize, Variant};
|
||||
|
||||
@@ -312,12 +312,9 @@ impl<T: Value + 'static> Component for Swatch<T> {
|
||||
}
|
||||
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
<<<<<<< HEAD
|
||||
let fill = if self.icon.is_some() { WellFill::Empty } else { well_fill(self.color) };
|
||||
paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), fill, self.icon.as_ref(), self.marked);
|
||||
=======
|
||||
paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), self.color, self.marked, self.shape);
|
||||
>>>>>>> origin/next
|
||||
let face = WellFace { fill, glyph: self.icon.as_ref(), shape: self.shape };
|
||||
paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), face, self.marked);
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> SwatchOutput {
|
||||
@@ -329,7 +326,6 @@ impl<T: Value + 'static> Component for Swatch<T> {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// What the well of a swatch of `color` shows: the colour, the "no colour" diagonal, or the mixed dash.
|
||||
fn well_fill(color: Mixed<Option<Srgba>>) -> WellFill {
|
||||
match color {
|
||||
@@ -339,32 +335,32 @@ fn well_fill(color: Mixed<Option<Srgba>>) -> WellFill {
|
||||
}
|
||||
}
|
||||
|
||||
/// The one swatch face painter: the well `fill` in `well` (a checkerboard behind a translucent colour, the dash of a
|
||||
/// mixed one, the diagonal of none), the `glyph` of an icon cell in the text colour, then the outline ring, the mark
|
||||
/// What a swatch's well shows, and its shape.
|
||||
struct WellFace<'a> {
|
||||
fill: WellFill,
|
||||
/// The glyph of an icon cell, over the empty well.
|
||||
glyph: Option<&'a IconId>,
|
||||
shape: SwatchShape,
|
||||
}
|
||||
|
||||
/// The one swatch face painter: the well `face.fill` in `well` (a checkerboard behind a translucent colour, the dash of
|
||||
/// a mixed one, the diagonal of none), the glyph of an icon cell in the text colour, then the outline ring, the mark
|
||||
/// when `marked`, and the selection ring, in `state`.
|
||||
fn paint_face(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, fill: WellFill, glyph: Option<&IconId>, marked: bool) {
|
||||
let shape = PaintShape::Rect(well, style.radius);
|
||||
draw.swatch_well(well, style.radius, fill);
|
||||
if let Some(glyph) = glyph {
|
||||
let side = style.glyph.min(well.width()).min(well.height());
|
||||
draw.icon(Rect::from_center_size(well.center(), Vec2::splat(side)), &IconSpec::svg(glyph.clone()).color(style.mark));
|
||||
}
|
||||
draw.stroke(&shape, StrokeWidth::Thin, state.resolve(&style.edge));
|
||||
=======
|
||||
/// The one swatch face painter: the well of `color` in `well` (a checkerboard behind a translucent colour, the dash
|
||||
/// of a mixed one), then the outline ring, the mark when `marked`, and the selection ring, in `state`.
|
||||
fn paint_face(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, color: Mixed<Srgba>, marked: bool, shape: SwatchShape) {
|
||||
let outline = |rect: Rect| match shape {
|
||||
fn paint_face(draw: &Draw<'_>, well: Rect, style: &SwatchStyle, state: &StateSet, face: WellFace<'_>, marked: bool) {
|
||||
let outline = |rect: Rect| match face.shape {
|
||||
SwatchShape::Square => PaintShape::Rect(rect, style.radius),
|
||||
SwatchShape::Hexagon => PaintShape::Polygon(hexagon(rect)),
|
||||
};
|
||||
let edge = outline(well);
|
||||
match shape {
|
||||
SwatchShape::Square => draw.swatch_well(well, style.radius, color.same().copied()),
|
||||
SwatchShape::Hexagon => draw.swatch_polygon_well(&hexagon(well), color.same().copied()),
|
||||
match face.shape {
|
||||
SwatchShape::Square => draw.swatch_well(well, style.radius, face.fill),
|
||||
SwatchShape::Hexagon => draw.swatch_polygon_well(&hexagon(well), face.fill),
|
||||
}
|
||||
if let Some(glyph) = face.glyph {
|
||||
let side = style.glyph.min(well.width()).min(well.height());
|
||||
draw.icon(Rect::from_center_size(well.center(), Vec2::splat(side)), &IconSpec::svg(glyph.clone()).color(style.mark));
|
||||
}
|
||||
draw.stroke(&edge, StrokeWidth::Thin, state.resolve(&style.edge));
|
||||
>>>>>>> origin/next
|
||||
if marked {
|
||||
let inside = outline(well.shrink(draw.width(StrokeWidth::Thin)));
|
||||
draw.stroke(&inside, StrokeWidth::Thin, style.mark);
|
||||
@@ -421,10 +417,7 @@ impl SwatchFace {
|
||||
let style = resolve_style(&scope, key, cx.painter.ctx(), Swatch::<()>::style);
|
||||
let (flags, on) = if self.selected { (Flags::SELECTED, 1.0) } else { (Flags::empty(), 0.0) };
|
||||
let state = StateSet::new(State::Rest, flags, StateMix::new(0.0, 0.0, on));
|
||||
<<<<<<< HEAD
|
||||
cx.with_draw(|draw| paint_face(draw, rect, &style, &state, well_fill(self.color), None, false));
|
||||
=======
|
||||
cx.with_draw(|draw| paint_face(draw, rect, &style, &state, self.color, false, SwatchShape::Square));
|
||||
>>>>>>> origin/next
|
||||
let face = WellFace { fill: well_fill(self.color), glyph: None, shape: SwatchShape::Square };
|
||||
cx.with_draw(|draw| paint_face(draw, rect, &style, &state, face, false));
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,13 @@
|
||||
use super::swatch::hexagon;
|
||||
use super::{Swatch, SwatchMetrics, SwatchShape};
|
||||
use crate::contract::{
|
||||
<<<<<<< HEAD
|
||||
ActivateOn, Bind, BindMut, Collection, CollectionEvent, CollectionProps, Common, Component, ContainerProps, Cx, LeadOnOpen, NoValue, Outcome,
|
||||
Props, Role, SelectMode, ShowCollection as _, Sizing,
|
||||
=======
|
||||
ActivateOn, Bind, BindMut, Collection, CollectionEvent, CollectionProps, Common, Component, ContainerProps, Cx, NoValue, Outcome, Props,
|
||||
Remember as _, Role, SelectMode, ShowCollection as _, Sizing,
|
||||
>>>>>>> origin/next
|
||||
Props, Remember as _, Role, SelectMode, ShowCollection as _, Sizing,
|
||||
};
|
||||
use crate::list::RowTest;
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
<<<<<<< HEAD
|
||||
use craft_behavior::{DisplayOrder, IconId, ItemSource, Metrics, Selection, TileLayout};
|
||||
=======
|
||||
use craft_behavior::{DisplayOrder, ItemLayout, ItemSource, Metrics, NavShape, Preview, ScrollPos, Selection, TileLayout};
|
||||
>>>>>>> origin/next
|
||||
use craft_behavior::{DisplayOrder, IconId, ItemLayout, ItemSource, Metrics, NavShape, Preview, ScrollPos, Selection, TileLayout};
|
||||
use craft_theme::Srgba;
|
||||
use egui::{Pos2, Rect, Response, Ui, Vec2};
|
||||
|
||||
@@ -381,15 +372,12 @@ pub struct SwatchTable<'a> {
|
||||
/// Whether the cells are wells at the control height, as a palette's swatches are, instead of small touching cells.
|
||||
#[prop]
|
||||
wells: bool,
|
||||
<<<<<<< HEAD
|
||||
/// The icon cell after the entries: its name and glyph.
|
||||
trailing: Option<(Label, IconId)>,
|
||||
=======
|
||||
/// How the cells lie: a square grid, or touching hexagons. A honeycomb ignores `per_row`, `span` and `wells`: its
|
||||
/// rows follow the count of entries and its cells are `size.icon.md` wide.
|
||||
#[prop]
|
||||
arrangement: SwatchArrangement,
|
||||
>>>>>>> origin/next
|
||||
/// The icon cell after the entries: its name and glyph.
|
||||
trailing: Option<(Label, IconId)>,
|
||||
}
|
||||
|
||||
impl<'a> SwatchTable<'a> {
|
||||
@@ -417,11 +405,8 @@ impl<'a> SwatchTable<'a> {
|
||||
marked: None,
|
||||
tips: false,
|
||||
wells: false,
|
||||
<<<<<<< HEAD
|
||||
trailing: None,
|
||||
=======
|
||||
arrangement: SwatchArrangement::default(),
|
||||
>>>>>>> origin/next
|
||||
trailing: None,
|
||||
}
|
||||
.label(label)
|
||||
}
|
||||
@@ -451,7 +436,6 @@ impl<'a> SwatchTable<'a> {
|
||||
let (swatches, tips, wells) = (self.swatches, self.tips, self.wells);
|
||||
let shape = if self.arrangement == SwatchArrangement::Honeycomb { SwatchShape::Hexagon } else { SwatchShape::Square };
|
||||
let marked = self.marked.take();
|
||||
<<<<<<< HEAD
|
||||
// A clone, not a take: `ideal_width` reads the trailing cell while the table shows.
|
||||
let trailing = self.trailing.clone();
|
||||
let rows = match &trailing {
|
||||
@@ -465,12 +449,7 @@ impl<'a> SwatchTable<'a> {
|
||||
// The rows name no key past the trailing cell; a mixed well keeps the closure total without a panic.
|
||||
(None, None) => (Label::Empty, Swatch::new(Label::Empty, craft_behavior::Mixed::<Srgba>::Mixed)),
|
||||
};
|
||||
let cell = cell.cell();
|
||||
=======
|
||||
self.show_items(ui, &SwatchRows::new(swatches), &mut |key, _| {
|
||||
let (name, color) = &swatches[*key];
|
||||
let cell = Swatch::new(name.clone(), *color).cell().shape(shape);
|
||||
>>>>>>> origin/next
|
||||
let cell = cell.cell().shape(shape);
|
||||
let cell = if wells { cell.well() } else { cell };
|
||||
let cell = if marked.as_ref().is_some_and(|test| test.passes(key)) { cell.marked() } else { cell };
|
||||
if tips { cell.tooltip(name) } else { cell }
|
||||
@@ -529,17 +508,12 @@ impl Collection for SwatchTable<'_> {
|
||||
|
||||
/// Where the table takes its width from its content it asks for every cell in one row, or its count per row: the
|
||||
/// room it is offered then wraps the cells, as it does where it is given the width.
|
||||
<<<<<<< HEAD
|
||||
fn ideal_width(&self, _item: Option<Vec2>, cx: &StyleCx<'_>) -> f32 {
|
||||
let cells = self.cells();
|
||||
let columns = self.per_row.map_or(cells, |columns| columns.max(1).min(cells));
|
||||
=======
|
||||
fn ideal_width(&self, _item: Option<Vec2>, _rows: usize, cx: &StyleCx<'_>) -> f32 {
|
||||
let cells = self.cells();
|
||||
if self.arrangement == SwatchArrangement::Honeycomb {
|
||||
return HoneycombLayout::new(self.swatches.len(), self.cell(cx)).columns() as f32 * self.cell(cx) + 0.5;
|
||||
return HoneycombLayout::new(cells, self.cell(cx)).columns() as f32 * self.cell(cx) + 0.5;
|
||||
}
|
||||
let columns = self.per_row.map_or(self.swatches.len(), |columns| columns.max(1).min(self.swatches.len()));
|
||||
>>>>>>> origin/next
|
||||
let columns = self.per_row.map_or(cells, |columns| columns.max(1).min(cells));
|
||||
// Half a point over, so the division that counts the columns back never rounds below `columns`.
|
||||
columns as f32 * self.cell(cx) + 0.5
|
||||
}
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
use super::{SwatchArrangement, SwatchTable, SwatchTableOutput};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
<<<<<<< HEAD
|
||||
use craft_behavior::{IconId, Selection};
|
||||
=======
|
||||
use craft_behavior::{Preview, Selection};
|
||||
>>>>>>> origin/next
|
||||
use craft_behavior::{IconId, Preview, Selection};
|
||||
use craft_theme::Srgba;
|
||||
use egui::Ui;
|
||||
|
||||
|
||||
@@ -52,13 +52,8 @@ pub struct DisclosureGlyph {
|
||||
pub stroke: StrokeWidth,
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// The arrow of a field or picker: the small filled triangle pointing down.
|
||||
static DROPDOWN: DisclosureGlyph = DisclosureGlyph::new(1.0);
|
||||
=======
|
||||
/// The arrow of a field or picker.
|
||||
const DROPDOWN: DisclosureGlyph = DisclosureGlyph::dropdown_form();
|
||||
>>>>>>> origin/next
|
||||
const DROPDOWN: DisclosureGlyph = DisclosureGlyph::new(1.0);
|
||||
/// The arrow of a button that opens a menu.
|
||||
const MENU_BUTTON: DisclosureGlyph = DisclosureGlyph { open: 1.0, form: ArrowForm::Dropdown, stroke: StrokeWidth::Medium };
|
||||
/// The submenu arrow.
|
||||
|
||||
@@ -4,23 +4,16 @@
|
||||
use super::display_sense;
|
||||
use crate::contract::{Access, Common, Component, Cx, DisabledLook, MeasureCx, PaintUi, Props as _, Role};
|
||||
use crate::list::{ThumbAspect, ThumbSize};
|
||||
<<<<<<< HEAD
|
||||
use crate::primitives::{ContentPainterCx, Revision, TextureState, TextureStore, TextureStoreOptions, fit_rect, svg_tree};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
use craft_behavior::{Metrics, Sense};
|
||||
use egui::{Color32, ColorImage, Id, Pos2, Rect, Response, Vec2};
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
=======
|
||||
use crate::primitives::{
|
||||
ContentPainterCx, Priority, Revision, TextureStore, TextureStoreOptions, ThumbPaint, ThumbRequest, ThumbSource, Thumbnails, fit_rect,
|
||||
ContentPainterCx, Priority, Revision, TextureState, TextureStore, TextureStoreOptions, ThumbPaint, ThumbRequest, ThumbSource, Thumbnails,
|
||||
fit_rect, svg_tree,
|
||||
};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
use craft_behavior::{Metrics, Sense};
|
||||
use egui::{ColorImage, Id, Rect, Response, Vec2};
|
||||
>>>>>>> origin/next
|
||||
use egui::{Color32, ColorImage, Id, Rect, Response, Vec2};
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
#[cfg(feature = "suite")]
|
||||
pub(crate) mod stories;
|
||||
@@ -61,13 +54,10 @@ enum Source<'a> {
|
||||
Image { key: u64, image: &'a dyn Fn() -> ColorImage },
|
||||
/// A content painter that paints into the picture's rect.
|
||||
Painter(Paint<'a>),
|
||||
<<<<<<< HEAD
|
||||
/// An SVG asset, rasterised at the picture's drawn size.
|
||||
Svg(&'static [u8]),
|
||||
=======
|
||||
/// A picture rendered off the frame by a thumbnail source, shown pending until it arrives.
|
||||
Rendered { key: u64, thumbnails: &'a Thumbnails<u64>, source: &'a dyn ThumbSource<u64> },
|
||||
>>>>>>> origin/next
|
||||
/// An SVG asset, rasterised at the picture's drawn size.
|
||||
Svg(&'static [u8]),
|
||||
}
|
||||
|
||||
/// A picture of an image the caller makes (`new`), of what a content painter paints (`painter`) or of an SVG asset
|
||||
@@ -108,12 +98,6 @@ impl<'a> Picture<'a> {
|
||||
Picture::from_source(label, Source::Painter(Box::new(paint))).aspect(aspect)
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A picture of the SVG asset `svg`, rasterised through `craft-svg` at the picture's drawn size; a malformed or
|
||||
/// oversized SVG draws nothing. `label` names it for a screen reader; an empty one leaves it decorative.
|
||||
pub fn svg(label: impl Into<Label>, svg: &'static [u8]) -> Self {
|
||||
Picture::from_source(label, Source::Svg(svg))
|
||||
=======
|
||||
/// A picture made off the frame by `source` for `key`: pending, with the framework's placeholder, until the
|
||||
/// source's picture arrives, then fitted as `new`'s texture is. `label` names it for a screen reader.
|
||||
/// The source's picture is asked through [`Thumbnails::state`] at the picture's rect and the screen's density,
|
||||
@@ -121,7 +105,12 @@ impl<'a> Picture<'a> {
|
||||
/// source's, not the `revision` prop.
|
||||
pub fn rendered(label: impl Into<Label>, key: u64, thumbnails: &'a Thumbnails<u64>, source: &'a dyn ThumbSource<u64>) -> Self {
|
||||
Picture::from_source(label, Source::Rendered { key, thumbnails, source })
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
/// A picture of the SVG asset `svg`, rasterised through `craft-svg` at the picture's drawn size; a malformed or
|
||||
/// oversized SVG draws nothing. `label` names it for a screen reader; an empty one leaves it decorative.
|
||||
pub fn svg(label: impl Into<Label>, svg: &'static [u8]) -> Self {
|
||||
Picture::from_source(label, Source::Svg(svg))
|
||||
}
|
||||
|
||||
fn from_source(label: impl Into<Label>, source: Source<'a>) -> Self {
|
||||
@@ -193,7 +182,12 @@ impl Component for Picture<'_> {
|
||||
ui.content_painter(cx).picture(texture.id, target, texture.uv(), 0.0);
|
||||
}
|
||||
Source::Painter(paint) => paint(&ui.content_painter(cx), cx.content_rect),
|
||||
<<<<<<< HEAD
|
||||
Source::Rendered { key, thumbnails, source } => {
|
||||
let rect = cx.content_rect;
|
||||
let request = ThumbRequest::for_cell(rect.width().max(rect.height()), cx.ctx.pixels_per_point());
|
||||
let state = thumbnails.state(&cx.ctx, *source, key, &request, Priority::VISIBLE);
|
||||
thumbnails.paint(&ui.content_painter(cx), rect, &state, &ThumbPaint::default());
|
||||
}
|
||||
Source::Svg(svg) => {
|
||||
let ppp = cx.ctx.pixels_per_point();
|
||||
let size = cx.content_rect.size() * ppp;
|
||||
@@ -203,7 +197,7 @@ impl Component for Picture<'_> {
|
||||
}
|
||||
// A side past the cap is refused below; the saturating cast keeps that refusal for absurd sizes.
|
||||
let (width, height) = (width as u32, height as u32);
|
||||
let store = TextureStore::<(Id, u64)>::in_context(&cx.ctx, "picture", TextureStoreOptions::thumbnails());
|
||||
let store = store(&cx.ctx);
|
||||
let key = (cx.resolved.id, svg_key(*svg, width, height));
|
||||
let texture = match store.state(&cx.ctx, &key, self.revision) {
|
||||
TextureState::Ready(texture) => texture,
|
||||
@@ -218,15 +212,8 @@ impl Component for Picture<'_> {
|
||||
},
|
||||
};
|
||||
let target = fit_rect(cx.content_rect, texture.size_vec2());
|
||||
let whole = Rect::from_min_max(Pos2::ZERO, Pos2::new(1.0, 1.0));
|
||||
ui.content_painter(cx).picture(texture.id, target, whole, 0.0);
|
||||
=======
|
||||
Source::Rendered { key, thumbnails, source } => {
|
||||
let rect = cx.content_rect;
|
||||
let request = ThumbRequest::for_cell(rect.width().max(rect.height()), cx.ctx.pixels_per_point());
|
||||
let state = thumbnails.state(&cx.ctx, *source, key, &request, Priority::VISIBLE);
|
||||
thumbnails.paint(&ui.content_painter(cx), rect, &state, &ThumbPaint::default());
|
||||
>>>>>>> origin/next
|
||||
// The store packs, so the texture is the picture's part of a shared page.
|
||||
ui.content_painter(cx).picture(texture.id, target, texture.uv(), 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,7 +223,12 @@ impl Component for Picture<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// The pictures' store of `ctx`: packed, so many small pictures (style tiles, font samples, SVG assets) share a few
|
||||
/// page textures; a larger picture takes a texture of its own.
|
||||
fn store(ctx: &egui::Context) -> TextureStore<(Id, u64)> {
|
||||
TextureStore::in_context(ctx, "picture", TextureStoreOptions::thumbnails().packed_small())
|
||||
}
|
||||
|
||||
/// The longest side, in physical pixels, an SVG picture rasterises at; past it the picture draws nothing.
|
||||
const MAX_SVG_SIDE: u32 = 4096;
|
||||
/// Bytes drawing one SVG picture may allocate, its target included.
|
||||
@@ -286,10 +278,4 @@ fn rasterise_svg(svg: &[u8], width: u32, height: u32) -> Option<ColorImage> {
|
||||
}))
|
||||
.ok()
|
||||
.flatten()
|
||||
=======
|
||||
/// The pictures' store of `ctx`: packed, so many small pictures (style tiles, font samples) share a few page
|
||||
/// textures; a larger picture takes a texture of its own.
|
||||
fn store(ctx: &egui::Context) -> TextureStore<(Id, u64)> {
|
||||
TextureStore::in_context(ctx, "picture", TextureStoreOptions::thumbnails().packed_small())
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -35,7 +35,17 @@ fn picture_thumbnail(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
.into()
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A picture made off the frame: its source renders as a `Later` job, so the picture shows the placeholder until the
|
||||
/// job lands on the loader's lanes, then the picture. The job runs inline, so the picture lands in the next frame and
|
||||
/// not whenever a thread ends: the suite's settled frames are the same on every run.
|
||||
#[story(Picture<'static>, covers = [], drive = Drive::Never)]
|
||||
fn picture_rendered(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let options = ThumbnailOptions::new().jobs(Arc::new(InlineJobs));
|
||||
let thumbnails = Thumbnails::<u64>::in_context(ui.ctx(), "craft_ui::stories::picture_rendered", options);
|
||||
let source = FakeThumbSource::<u64>::new().later(true).opaque(true);
|
||||
Picture::rendered("Rendered", 1, &thumbnails, &source).extent(PictureSize::Thumb(ThumbSize::Large)).show(ui).into()
|
||||
}
|
||||
|
||||
/// An original mark: a teal disc with an amber diamond, so the SVG's own colours and its fit show.
|
||||
const MARK: &[u8] = br##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="11" fill="#1f8a8a"/><path d="M12 4 L19 12 L12 20 L5 12 Z" fill="#f2b233"/></svg>"##;
|
||||
|
||||
@@ -65,17 +75,6 @@ fn picture_wide_svg(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
#[story(Picture<'static>, covers = [], drive = Drive::Never)]
|
||||
fn picture_svg_invalid(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
Picture::svg("Broken", NOT_SVG).extent(PictureSize::Thumb(ThumbSize::Small)).show(ui).into()
|
||||
=======
|
||||
/// A picture made off the frame: its source renders as a `Later` job, so the picture shows the placeholder until the
|
||||
/// job lands on the loader's lanes, then the picture. The job runs inline, so the picture lands in the next frame and
|
||||
/// not whenever a thread ends: the suite's settled frames are the same on every run.
|
||||
#[story(Picture<'static>, covers = [], drive = Drive::Never)]
|
||||
fn picture_rendered(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let options = ThumbnailOptions::new().jobs(Arc::new(InlineJobs));
|
||||
let thumbnails = Thumbnails::<u64>::in_context(ui.ctx(), "craft_ui::stories::picture_rendered", options);
|
||||
let source = FakeThumbSource::<u64>::new().later(true).opaque(true);
|
||||
Picture::rendered("Rendered", 1, &thumbnails, &source).extent(PictureSize::Thumb(ThumbSize::Large)).show(ui).into()
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
#[story(Picture<'static>, covers = [], drive = Drive::Never)]
|
||||
|
||||
@@ -97,13 +97,9 @@ impl Text {
|
||||
role: TypeRole::Body,
|
||||
elide: Elide::Off,
|
||||
spans: Vec::new(),
|
||||
<<<<<<< HEAD
|
||||
italic: false,
|
||||
numeric: None,
|
||||
=======
|
||||
styled: Vec::new(),
|
||||
italic: false,
|
||||
>>>>>>> origin/next
|
||||
numeric: None,
|
||||
}
|
||||
.label(text)
|
||||
}
|
||||
@@ -220,20 +216,15 @@ impl Component for Text {
|
||||
};
|
||||
}
|
||||
let role = cx.style.text.role;
|
||||
<<<<<<< HEAD
|
||||
// Rows reserve the widest word, up to an enclosing reading-width cap.
|
||||
// A line breaks between words, never inside one: a wrapped text is never narrower than its widest word, up to
|
||||
// an enclosing reading-width cap.
|
||||
let widest = || {
|
||||
cx.resolved
|
||||
.label
|
||||
.split_whitespace()
|
||||
.map(|word| cx.layout_at(&self.run(role, word), f32::INFINITY).size().x)
|
||||
self.word_runs(role, cx.resolved.label)
|
||||
.iter()
|
||||
.map(|word| cx.layout_at(word, f32::INFINITY).size().x)
|
||||
.fold(0.0, f32::max)
|
||||
.min(cx.wrap_limit().unwrap_or(f32::INFINITY))
|
||||
};
|
||||
=======
|
||||
// A line breaks between words, never inside one: a wrapped text is never narrower than its widest word.
|
||||
let widest = || self.word_runs(role, cx.resolved.label).iter().map(|word| cx.layout_at(word, f32::INFINITY).size().x).fold(0.0, f32::max);
|
||||
>>>>>>> origin/next
|
||||
if cx.proposal == Proposal::Min && self.elide == Elide::Off {
|
||||
let widest = widest();
|
||||
return Vec2::new(widest, cx.layout_at(&self.run(role, cx.resolved.label), widest).size().y);
|
||||
|
||||
@@ -21,13 +21,8 @@ pub use findings::{Finding, Findings, FindingsList, FindingsListStyle, FindingsS
|
||||
pub use predicate::{DropTest, RowTest, RowText};
|
||||
pub(crate) use row::RowThumb;
|
||||
pub use row::{
|
||||
<<<<<<< HEAD
|
||||
CellStatus, HueTarget, ListRow, ListRowStyle, RowDragSpot, RowEvent, RowInk, RowLines, RowOutput, RowStyleCx, ThumbAspect, ThumbPaint, ThumbSize,
|
||||
ThumbTarget, ThumbTargets, TrailingFace, TrailingPart, label_color_label, tree_steps,
|
||||
=======
|
||||
ListRow, ListRowStyle, RowDragSpot, RowEvent, RowInk, RowOutput, RowStyleCx, ThumbAspect, ThumbPaint, ThumbSize, ThumbTarget, ThumbTargets,
|
||||
TrailingFace, TrailingPart, TreeLeaves, label_color_label, tree_steps,
|
||||
>>>>>>> origin/next
|
||||
ThumbTarget, ThumbTargets, TrailingFace, TrailingPart, TreeLeaves, label_color_label, tree_steps,
|
||||
};
|
||||
pub use toggle::{ToggleCell, ToggleFace, ToggleState};
|
||||
pub use tree::OpenSet;
|
||||
|
||||
@@ -11,11 +11,7 @@ use super::toggle::ToggleCell;
|
||||
use super::view::DocumentRows;
|
||||
use super::words::ListWords;
|
||||
use crate::contract::{Common, OpenChange, RowHeight, RowPressed, RowState, Show};
|
||||
<<<<<<< HEAD
|
||||
use crate::primitives::{ContentPainterCx, HAlign, IconSpec, Span, TextRun};
|
||||
=======
|
||||
use crate::primitives::{ContentPainterCx, HAlign, IconSpec, Span};
|
||||
>>>>>>> origin/next
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::DataColor;
|
||||
use craft_behavior::{ColumnKey, Cursor};
|
||||
|
||||
@@ -186,7 +186,6 @@ impl ListRow<'_> {
|
||||
if !self.renaming && !self.label_has_field() {
|
||||
let muted = self.label_column(&self.cells).is_some_and(|column| self.muted.contains(column));
|
||||
let look = if muted { &style.cell_muted } else { &style.text };
|
||||
<<<<<<< HEAD
|
||||
let ink = hue.unwrap_or_else(|| cx.resolve(&look.color));
|
||||
let width = (label.width() - beside).max(0.0);
|
||||
match (self.document_run(cx.resolved.label, ink.egui()), document, &self.document) {
|
||||
@@ -198,16 +197,10 @@ impl ListRow<'_> {
|
||||
draw.doc(Rect::from_min_size(Pos2::new(label.left(), top + (sizes.label_line - height) / 2.0), Vec2::new(width, height)), &text);
|
||||
}
|
||||
_ => {
|
||||
let mut span = Span::new(cx.resolved.label);
|
||||
span.italic = self.italic;
|
||||
let run = TextRun::spans(vec![span]).role(look.role).color(ink).elide();
|
||||
let run = self.label_run(cx.resolved.label).role(look.role).color(ink).elide();
|
||||
draw.text(Rect::from_min_size(Pos2::new(label.left(), top), Vec2::new(width, sizes.label_line)), &run);
|
||||
}
|
||||
}
|
||||
=======
|
||||
let run = self.label_run(cx.resolved.label).role(look.role).color(cx.resolve(&look.color)).elide();
|
||||
draw.text(Rect::from_min_size(Pos2::new(label.left(), top), Vec2::new((label.width() - beside).max(0.0), sizes.label_line)), &run);
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
top += sizes.label_line;
|
||||
if let Some(detail) = self.detail.as_ref().filter(|_| !self.heading) {
|
||||
|
||||
@@ -180,11 +180,7 @@ impl Component for ListRow<'_> {
|
||||
if cx.proposal == Proposal::Min {
|
||||
return Vec2::new(probe_min, height);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
let label = document.map_or_else(|| cx.layout(&TextRun::new(cx.resolved.label).role(cx.style.text.role)).size().x, |size| size.x);
|
||||
=======
|
||||
let label = cx.layout(&self.label_run(cx.resolved.label).role(cx.style.text.role)).size().x;
|
||||
>>>>>>> origin/next
|
||||
let label = document.map_or_else(|| cx.layout(&self.label_run(cx.resolved.label).role(cx.style.text.role)).size().x, |size| size.x);
|
||||
// The label band holds the detail line under the label, so it is as wide as the wider of the two.
|
||||
let label = match self.detail.as_ref().filter(|_| self.detail_line()) {
|
||||
Some(detail) => label.max(cx.layout(&TextRun::new(detail.as_str()).role(cx.style.detail.role)).size().x),
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
//! The look of a row: ListRowStyle, the fill and ink rules of its flags.
|
||||
|
||||
use super::placement::Sizes;
|
||||
<<<<<<< HEAD
|
||||
use crate::style::{ComponentStyle, DataColor, Flags, IconLook, StyleColor, StyleCx, SurfaceLook, TextLook};
|
||||
=======
|
||||
use crate::display::divider::SeparatorRule;
|
||||
use crate::style::{ComponentStyle, Flags, IconLook, StyleColor, StyleCx, SurfaceLook, TextLook};
|
||||
>>>>>>> origin/next
|
||||
use crate::style::{ComponentStyle, DataColor, Flags, IconLook, StyleColor, StyleCx, SurfaceLook, TextLook};
|
||||
use craft_behavior::Metrics;
|
||||
use craft_theme::{Contrast, Rgba, Stateful, States, contrast_ratio, identifiable_outline, over};
|
||||
|
||||
|
||||
@@ -2,15 +2,10 @@
|
||||
|
||||
use super::{CellStatus, HueTarget, ListRow, RowInk, TrailingFace, TrailingPart};
|
||||
use crate::contract::Show as _;
|
||||
<<<<<<< HEAD
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::primitives::{IconSpec, Span};
|
||||
use crate::runtime::env::Env;
|
||||
use crate::style::DataColor;
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, show_as_only_item, show_as_only_item_across, story};
|
||||
=======
|
||||
use crate::primitives::{IconSpec, Span};
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, show_as_only_item, story};
|
||||
>>>>>>> origin/next
|
||||
use craft_behavior::{ColumnKey, IconId};
|
||||
use craft_theme::variant::Tone;
|
||||
use egui::{Pos2, Rangef, Rect, Ui};
|
||||
|
||||
@@ -281,11 +281,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for List<'_, K> {
|
||||
}
|
||||
|
||||
fn dress<'r>(&self, row: Self::Item<'r>, state: &RowState) -> Self::Item<'r> {
|
||||
<<<<<<< HEAD
|
||||
let row = row.rows(self.items.row_height).sub_row(state).document(self.document.clone());
|
||||
=======
|
||||
let row = row.rows(self.items.row_height).sub_row(state).leaves(self.tree_leaves);
|
||||
>>>>>>> origin/next
|
||||
let row = row.rows(self.items.row_height).sub_row(state).leaves(self.tree_leaves).document(self.document.clone());
|
||||
if self.row_menu { row.row_menu() } else { row }
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,8 @@ use crate::popover::Popover;
|
||||
use crate::primitives::{ContentPainterCx, IconSpec, Span};
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::style::{Corners, SurfaceKind};
|
||||
<<<<<<< HEAD
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, EditEvent, IconId, ItemSource, Selection};
|
||||
=======
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, ValueAt, story};
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, IconId, ItemSource, Selection};
|
||||
>>>>>>> origin/next
|
||||
use craft_behavior::{ColumnKey, ColumnWidth, DisplayOrder, EditEvent, IconId, ItemSource, Selection};
|
||||
use craft_keymap::{Chord, Key, Mods};
|
||||
use egui::{Rect, Ui};
|
||||
use std::borrow::Cow;
|
||||
@@ -454,27 +449,12 @@ fn list_tree_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(List<'static, usize>, covers = [], drive = Drive::Never)]
|
||||
fn list_row_menu(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let names = names(4);
|
||||
<<<<<<< HEAD
|
||||
let out = List::<usize>::new("Layers")
|
||||
.rename(true)
|
||||
.row_menu()
|
||||
.selection(Bind::bound(data.value("selection", Selection::single(1_usize))))
|
||||
.show_items(ui, &Names(&names), &mut |key, _| ListRow::new(names[*key].clone()));
|
||||
if let Some(row) = out.menu.as_ref().map(|request| request.key) {
|
||||
=======
|
||||
let out = List::<usize>::new("Layers").rename(true).row_menu().selection(data.bind("selection", Selection::single(1_usize))).show_items(
|
||||
ui,
|
||||
&Names(&names),
|
||||
&mut |key, _| ListRow::new(names[*key].clone()),
|
||||
);
|
||||
let menu_row = data.value("menu", None::<usize>);
|
||||
for event in &out.events {
|
||||
if let CollectionEvent::ContextMenu(request) = event {
|
||||
*menu_row = Some(request.key);
|
||||
}
|
||||
}
|
||||
if let Some(row) = *menu_row {
|
||||
>>>>>>> origin/next
|
||||
if let Some(row) = out.menu.as_ref().map(|request| request.key) {
|
||||
let entries = [
|
||||
Entry::new(String::from("rename"), "Rename"),
|
||||
Entry::new(String::from("duplicate"), "Duplicate"),
|
||||
|
||||
@@ -83,11 +83,12 @@ impl RowInput {
|
||||
RowInput { moving, hovered, focused, keyboard, gained, started }
|
||||
}
|
||||
|
||||
/// Makes the row `id` the level's active row when it `runs` and the pointer moved over it or the keyboard landed
|
||||
/// on it. The focused row of a menu the pointer opened is not active until then.
|
||||
/// Makes the row `id` the level's active row when it `runs` and the keyboard landed on it. The pointer's row is
|
||||
/// made active by its `Menu` before the rows run (`MenuLevel::follow_pointer`); the focused row of a menu the
|
||||
/// pointer opened is not active until the keyboard lands on it.
|
||||
pub(crate) fn activate(&self, ctx: &Context, id: Id, level: &MenuLevel, runs: bool) {
|
||||
let landed = self.focused && self.keyboard && (self.gained || self.started);
|
||||
if runs && ((self.hovered && self.moving) || landed) && level.activate_row(id) {
|
||||
if runs && landed && level.activate_row(id) {
|
||||
frame::request_repaint(ctx);
|
||||
}
|
||||
}
|
||||
@@ -598,21 +599,12 @@ impl Component for MenuItem<'_> {
|
||||
let heading = level.aimed(cx.id);
|
||||
let rested = {
|
||||
let rest = cx.memory::<Rest>();
|
||||
<<<<<<< HEAD
|
||||
if hovered && !moving {
|
||||
now - *rest.since.get_or_insert(now)
|
||||
=======
|
||||
let gained = focused && !rest.focused;
|
||||
rest.focused = focused;
|
||||
let started = keyboard && !rest.keyboard;
|
||||
rest.keyboard = keyboard;
|
||||
// The rest starts at the pointer's last move over the row.
|
||||
if hovered && moving {
|
||||
rest.since = Some(now);
|
||||
(0.0, gained, started)
|
||||
0.0
|
||||
} else if hovered {
|
||||
(now - *rest.since.get_or_insert(now), gained, started)
|
||||
>>>>>>> origin/next
|
||||
now - *rest.since.get_or_insert(now)
|
||||
} else {
|
||||
rest.since = None;
|
||||
0.0
|
||||
@@ -621,13 +613,7 @@ impl Component for MenuItem<'_> {
|
||||
let takes_over = hovered && (!heading || rested >= AIM_REST);
|
||||
// The focused row of a menu that the pointer opened is not active: the keyboard makes it so when focus lands on
|
||||
// it or the keyboard starts driving the menu.
|
||||
<<<<<<< HEAD
|
||||
input.activate(&ctx, cx.id, &level, enabled);
|
||||
=======
|
||||
if enabled && focused && keyboard && (focus_gained || key_started) && level.activate_row(cx.id) {
|
||||
frame::request_repaint(&ctx);
|
||||
}
|
||||
>>>>>>> origin/next
|
||||
// A disabled row is never active.
|
||||
self.active = enabled && level.is_active(cx.id);
|
||||
// A crossed row waits for the rest to end: one pass when it does.
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
//! Menu presets with `MenuItem` rows, menu-bar keys and mnemonics.
|
||||
|
||||
pub mod bar;
|
||||
<<<<<<< HEAD
|
||||
mod edit;
|
||||
mod icon_row;
|
||||
=======
|
||||
pub(crate) mod edit;
|
||||
>>>>>>> origin/next
|
||||
mod icon_row;
|
||||
pub(crate) mod item;
|
||||
#[doc(hidden)]
|
||||
pub mod level;
|
||||
@@ -20,12 +16,8 @@ mod words;
|
||||
pub use bar::{MenuBar, MenuBarOutput, MenuBarStyle, MenuHelp, MenuTitle};
|
||||
pub(crate) use edit::text_menu;
|
||||
pub use edit::{EditMenu, EditMenuOutput};
|
||||
<<<<<<< HEAD
|
||||
pub use icon_row::{MenuIcon, MenuIconRow, MenuIconRowOutput};
|
||||
pub use item::{MenuItem, MenuItemOutput, MenuItemStyle};
|
||||
=======
|
||||
pub use item::{MenuItem, MenuItemOutput, MenuItemStyle, MenuSamplePaint, MenuShortcut};
|
||||
>>>>>>> origin/next
|
||||
pub use panel::{GroupItem, PanelMenu, PanelMenuOutput, PanelRow};
|
||||
#[doc(hidden)]
|
||||
pub use popup::entry_rows;
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
//! Stories of the menu rows and the menu.
|
||||
|
||||
<<<<<<< HEAD
|
||||
use super::{Menu, MenuIcon, MenuIconRow, MenuItem};
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
=======
|
||||
use super::{Menu, MenuItem};
|
||||
use crate::buttons::{Button, IconButton};
|
||||
use crate::contract::{Entry, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
>>>>>>> origin/next
|
||||
use crate::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Trigger};
|
||||
use crate::display::Divider;
|
||||
use crate::layout_components::{Row, Stack};
|
||||
use crate::primitives::ContentPainterCx;
|
||||
|
||||
@@ -590,17 +590,12 @@ impl Component for Notice<'_> {
|
||||
detail,
|
||||
line,
|
||||
more,
|
||||
<<<<<<< HEAD
|
||||
icon: if key.layout == NoticeLayout::Centred {
|
||||
// An empty state's picture: large and quiet above its message.
|
||||
IconLook::new(cx.tokens.size.icon.lg * EMPTY_ICON_IN_LARGE, stateful(muted))
|
||||
} else {
|
||||
IconLook::new(control.icon, stateful(tone))
|
||||
},
|
||||
card_width: cx.tokens.size.notice.width,
|
||||
=======
|
||||
icon: IconLook::new(control.icon, stateful(tone)),
|
||||
>>>>>>> origin/next
|
||||
reading_width: cx.tokens.typography.get(TypeRole::Body).size * READING_IN_BODY_SIZES,
|
||||
}
|
||||
}
|
||||
@@ -614,12 +609,8 @@ impl Component for Notice<'_> {
|
||||
// that hosts content (a progress bar) has no text width of its own and takes the card width.
|
||||
(NoticeLayout::Card | NoticeLayout::Toast, room) => {
|
||||
let padding = cx.style.metrics.padding;
|
||||
<<<<<<< HEAD
|
||||
let cap = cx.style.card_width - padding.start - padding.end;
|
||||
let cap = CARD_WIDTH - padding.start - padding.end;
|
||||
let width = if self.content_sizes.is_empty() { natural.min(cap) } else { cap };
|
||||
=======
|
||||
let width = CARD_WIDTH - padding.start - padding.end;
|
||||
>>>>>>> origin/next
|
||||
room.map_or(width, |room| width.min(room))
|
||||
}
|
||||
(NoticeLayout::Centred, None) => natural.min(cx.style.reading_width),
|
||||
|
||||
@@ -7,14 +7,9 @@
|
||||
|
||||
pub(crate) mod calendar;
|
||||
mod codec;
|
||||
<<<<<<< HEAD
|
||||
mod popover;
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
=======
|
||||
#[cfg(feature = "suite")]
|
||||
pub(crate) mod stories;
|
||||
>>>>>>> origin/next
|
||||
|
||||
pub use calendar::{Calendar, CalendarOutput, CalendarStyle, CalendarView, local_month_grid, month_grid};
|
||||
pub use codec::DateCodec;
|
||||
@@ -23,15 +18,9 @@ pub use popover::{CalendarPopover, CalendarPopoverStyle};
|
||||
use super::words::PickerWords;
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::{
|
||||
<<<<<<< HEAD
|
||||
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Input, MeasureCx, Overlay, OverlayUi, Overlays as _, PaintUi, PartsCx,
|
||||
Props as _, Remember as _, Role, WordSetCx as _,
|
||||
=======
|
||||
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Entry, Input, MeasureCx, Overlay, OverlayUi, Overlays as _, PaintUi,
|
||||
PartsCx, Props as _, Remember as _, Role, Show as _, ShowContainer as _, WordSetCx as _, clicked,
|
||||
>>>>>>> origin/next
|
||||
};
|
||||
use crate::layout_components::Row;
|
||||
use crate::primitives::{IconSpec, TextKey, TextOptions, TextRun};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::text::{Adornment, FieldStyle, place, reserve};
|
||||
@@ -331,7 +320,6 @@ impl Component for DatePicker<'_> {
|
||||
};
|
||||
let today = self.today.or_else(|| cx.env.today().and_then(PickedDate::from_calendar_date));
|
||||
let name = cx.label();
|
||||
<<<<<<< HEAD
|
||||
let at = CalendarAt {
|
||||
current,
|
||||
settled,
|
||||
@@ -345,63 +333,6 @@ impl Component for DatePicker<'_> {
|
||||
name: &name,
|
||||
};
|
||||
let chosen = ui.show(popup, Overlay::popover(), |ui, body| calendar_body(ui, body, at));
|
||||
=======
|
||||
let chosen = ui.show(popup, Overlay::popover(), |ui, body| {
|
||||
let mut view = (*body.memory::<Option<CalendarView>>()).unwrap_or_else(|| CalendarView::open(current, today, precisions, &dates));
|
||||
if precisions.len() > 1 {
|
||||
let entries: Vec<Entry<DatePrecision>> = precisions
|
||||
.iter()
|
||||
.map(|precision| {
|
||||
let label = match precision {
|
||||
DatePrecision::Year => &words.date_year,
|
||||
DatePrecision::Month => &words.date_month,
|
||||
_ => &words.date_day,
|
||||
};
|
||||
Entry::new(*precision, label.clone())
|
||||
})
|
||||
.collect();
|
||||
let mut precision = view.precision;
|
||||
Segmented::new(words.date_precision.clone(), Bind::bound(&mut precision), &entries).show(ui);
|
||||
if precision != view.precision {
|
||||
view = view.switched(precision, &dates);
|
||||
view = view.landed(current, today, &dates);
|
||||
}
|
||||
}
|
||||
let mut calendar = Calendar::new(name.clone(), view, current);
|
||||
if let Some(min) = min {
|
||||
calendar = calendar.min(min);
|
||||
}
|
||||
if let Some(max) = max {
|
||||
calendar = calendar.max(max);
|
||||
}
|
||||
if let Some(today) = today {
|
||||
calendar = calendar.today(today);
|
||||
}
|
||||
let page = calendar.show(ui);
|
||||
if let Some(next) = page.moved {
|
||||
view = next;
|
||||
}
|
||||
let mut pick = page.picked.map(Some);
|
||||
let _ = Row::new().show(ui, |ui, _| {
|
||||
let at_precision = today.map(|today| match view.precision {
|
||||
DatePrecision::Day => today,
|
||||
DatePrecision::Month => PickedDate::month(today.year, today.month.unwrap_or(1)),
|
||||
_ => PickedDate::year(today.year),
|
||||
});
|
||||
if let Some(today) = at_precision {
|
||||
let allowed = today.in_bounds(min.as_ref(), max.as_ref());
|
||||
if clicked(&Link::new(words.date_today.clone()).enabled(allowed).show(ui)) {
|
||||
pick = Some(Some(today));
|
||||
}
|
||||
}
|
||||
if clicked(&Link::new(words.date_clear.clone()).enabled(current.is_some()).show(ui)) {
|
||||
pick = Some(None);
|
||||
}
|
||||
});
|
||||
*body.memory::<Option<CalendarView>>() = Some(view);
|
||||
Chosen { hovered: page.hovered, pick }
|
||||
});
|
||||
>>>>>>> origin/next
|
||||
let Some(chosen) = chosen else { return };
|
||||
match chosen.pick {
|
||||
Some(date) => {
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
//! Stories of `DatePicker` and `Calendar`.
|
||||
|
||||
<<<<<<< HEAD
|
||||
use super::{Calendar, CalendarPopover, CalendarView, DatePicker, DatePrecision, PickedDate};
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::overlay::Anchor;
|
||||
use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _, Validity, clicked};
|
||||
use crate::display::Text;
|
||||
use crate::layout_components::Stack;
|
||||
=======
|
||||
use super::{Calendar, CalendarView, DatePicker, DatePrecision, PickedDate};
|
||||
use crate::contract::{Props as _, Show as _, Validity};
|
||||
>>>>>>> origin/next
|
||||
use crate::runtime::env::Message;
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use craft_behavior::Mixed;
|
||||
|
||||
@@ -80,12 +80,12 @@ impl<'a> PopupList<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// The field the popup hangs from. The popup closes when the opener is no longer shown.
|
||||
#[must_use]
|
||||
pub fn opened_by(self, opener: &Response) -> Self {
|
||||
self.overlay(|overlay| overlay.opened_by(opener, Trigger::Manual))
|
||||
=======
|
||||
}
|
||||
|
||||
/// The caller's `List`, by the id it is shown with: it takes the opener's list keys while the popup is open.
|
||||
#[must_use]
|
||||
pub fn list(mut self, list: Id) -> Self {
|
||||
@@ -95,7 +95,6 @@ impl<'a> PopupList<'a> {
|
||||
};
|
||||
self.props = self.props.mount(Mount::Layer(overlay.list(list)));
|
||||
self
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
|
||||
use super::{PopupList, PopupListKind};
|
||||
use crate::buttons::Button;
|
||||
<<<<<<< HEAD
|
||||
use crate::contract::overlay::Anchor;
|
||||
use crate::contract::{Bind, Show as _, ShowCollection as _, ShowContainer as _, clicked};
|
||||
use crate::contract::{Bind, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked};
|
||||
use crate::fonts::FontRef;
|
||||
=======
|
||||
use crate::contract::{Props as _, Show as _, ShowCollection as _, ShowContainer as _};
|
||||
>>>>>>> origin/next
|
||||
use crate::layout_components::Stack;
|
||||
use crate::list::{DocumentRows, List, ListRow};
|
||||
use crate::primitives::HAlign;
|
||||
|
||||
@@ -68,19 +68,11 @@ pub enum OverflowMenu {
|
||||
}
|
||||
|
||||
impl TabKind {
|
||||
<<<<<<< HEAD
|
||||
/// How tab widths are fitted: whole titles for text tabs, shrinking for document and panel tabs.
|
||||
/// How tab widths are fitted: whole titles for text and ribbon tabs, shrinking for document and panel tabs.
|
||||
pub fn fit_mode(self) -> FitMode {
|
||||
match self {
|
||||
Self::Text => FitMode::Whole,
|
||||
Self::Document | Self::Panel => FitMode::Shrink,
|
||||
=======
|
||||
/// How tab widths are fitted: whole titles for document, text and ribbon tabs, shrinking for panel tabs.
|
||||
pub fn fit_mode(self) -> FitMode {
|
||||
match self {
|
||||
Self::Document | Self::Text | Self::Ribbon => FitMode::Whole,
|
||||
Self::Panel => FitMode::Shrink { keep_selected: self.keeps_active_width() },
|
||||
>>>>>>> origin/next
|
||||
Self::Text | Self::Ribbon => FitMode::Whole,
|
||||
Self::Document | Self::Panel => FitMode::Shrink { keep_selected: self.keeps_active_width() },
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ pub struct StripLayout {
|
||||
width: f32,
|
||||
height: f32,
|
||||
/// Space between document tabs; included in the fit budget but not in their hit rectangles.
|
||||
gap: f32,
|
||||
tab_gap: f32,
|
||||
measured_height: bool,
|
||||
fitting: Fitting,
|
||||
shown: Vec<bool>,
|
||||
@@ -216,19 +216,15 @@ pub struct StripLayout {
|
||||
}
|
||||
|
||||
impl StripLayout {
|
||||
<<<<<<< HEAD
|
||||
fn new(count: usize, size: Vec2, gap: f32, selected: usize, mode: FitMode, report: Arc<Mutex<Report>>, ctx: egui::Context) -> Self {
|
||||
fn new(count: usize, size: Vec2, tab_gap: f32, fitting: Fitting, report: Arc<Mutex<Report>>, ctx: egui::Context) -> Self {
|
||||
let (width, height) = (size.x, size.y);
|
||||
=======
|
||||
fn new(count: usize, width: f32, height: f32, fitting: Fitting, report: Arc<Mutex<Report>>, ctx: egui::Context) -> Self {
|
||||
>>>>>>> origin/next
|
||||
let each = if count == 0 { 0.0 } else { width / count as f32 };
|
||||
let mut layout = StripLayout {
|
||||
ideal: vec![each; count],
|
||||
min: vec![0.0; count],
|
||||
width,
|
||||
height,
|
||||
gap,
|
||||
tab_gap,
|
||||
measured_height: false,
|
||||
fitting,
|
||||
shown: Vec::new(),
|
||||
@@ -249,7 +245,9 @@ impl StripLayout {
|
||||
if ends.is_empty() {
|
||||
return (0.0, Vec::new());
|
||||
}
|
||||
let natural = self.ideal.iter().sum::<f32>() + ghosts.iter().map(|ghost| ghost.width).sum::<f32>();
|
||||
let places = self.ideal.len() + ghosts.len();
|
||||
let natural =
|
||||
self.ideal.iter().sum::<f32>() + ghosts.iter().map(|ghost| ghost.width).sum::<f32>() + self.tab_gap * places.saturating_sub(1) as f32;
|
||||
let fit = fit_items(ends, self.width - natural - gap, *gap, *gap, 0.0);
|
||||
let sized: Vec<(usize, f32, bool)> = fit
|
||||
.shown
|
||||
@@ -279,30 +277,9 @@ impl StripLayout {
|
||||
/// of its width, so the row holds still until its exit ends.
|
||||
fn refit(&mut self) {
|
||||
let count = self.ideal.len();
|
||||
<<<<<<< HEAD
|
||||
let minimum = self.min.iter().copied().fold(0.0, f32::max);
|
||||
// Give every fitted tab a trailing gap, then return the last gap to the available width.
|
||||
// This keeps the spaces in the shrink and overflow budget without adding one after the last tab.
|
||||
let padded: Vec<f32> = self.ideal.iter().map(|width| width + self.gap).collect();
|
||||
let fit = self.mode.fit(&padded, self.selected, self.width + self.gap, minimum + self.gap, self.height);
|
||||
self.shown = vec![false; count];
|
||||
self.left = vec![self.width; count];
|
||||
self.wide = vec![0.0; count];
|
||||
let mut at = 0.0;
|
||||
let mut placed = Vec::with_capacity(fit.shown.len());
|
||||
for &(index, padded_width) in &fit.shown {
|
||||
let width = (padded_width - self.gap).max(0.0);
|
||||
self.shown[index] = true;
|
||||
self.left[index] = at;
|
||||
self.wide[index] = width;
|
||||
placed.push((index, at, width));
|
||||
at += width + self.gap;
|
||||
}
|
||||
if !placed.is_empty() {
|
||||
at -= self.gap;
|
||||
=======
|
||||
let (ends_room, ends) = self.fit_ends();
|
||||
let StripLayout { ideal, min, width, height, fitting, shown, left, wide, report, ctx, .. } = self;
|
||||
let StripLayout { ideal, min, width, height, tab_gap, fitting, shown, left, wide, report, ctx, .. } = self;
|
||||
let tab_gap = *tab_gap;
|
||||
let Fitting { selected, mode, kept, ghosts, departed, .. } = &*fitting;
|
||||
let mut lane = Vec::with_capacity(count + ghosts.len());
|
||||
for at in 0..=count {
|
||||
@@ -311,12 +288,15 @@ impl StripLayout {
|
||||
lane.push(Lane::Tab(at));
|
||||
}
|
||||
}
|
||||
let natural: Vec<f32> = lane
|
||||
// Every place in the lane takes a trailing gap, and the last gap goes back to the available width: the spaces
|
||||
// are in the shrink and overflow budget without one after the last tab.
|
||||
let padded: Vec<f32> = lane
|
||||
.iter()
|
||||
.map(|place| match *place {
|
||||
Lane::Tab(at) => ideal.get(at).copied().unwrap_or(0.0),
|
||||
Lane::Ghost(k) => ghosts.get(k).map_or(0.0, |ghost| ghost.width),
|
||||
})
|
||||
.map(|width| width + tab_gap)
|
||||
.collect();
|
||||
let held: Vec<bool> = lane
|
||||
.iter()
|
||||
@@ -327,14 +307,15 @@ impl StripLayout {
|
||||
.collect();
|
||||
let selected = lane.iter().position(|place| matches!(*place, Lane::Tab(at) if at == *selected)).unwrap_or(usize::MAX);
|
||||
let minimum = min.iter().copied().fold(0.0, f32::max);
|
||||
let fit = mode.fit(&natural, selected, &held, (*width - ends_room).max(0.0), minimum, *height);
|
||||
let fit = mode.fit(&padded, selected, &held, (*width - ends_room).max(0.0) + tab_gap, minimum + tab_gap, *height);
|
||||
*shown = vec![false; count];
|
||||
*left = vec![*width; count];
|
||||
*wide = vec![0.0; count];
|
||||
let mut at = 0.0;
|
||||
let mut placed = Vec::with_capacity(fit.shown.len());
|
||||
let mut slots: Vec<Option<(f32, f32)>> = vec![None; *departed];
|
||||
for &(position, extent) in &fit.shown {
|
||||
for &(position, padded_extent) in &fit.shown {
|
||||
let extent = (padded_extent - tab_gap).max(0.0);
|
||||
match lane.get(position) {
|
||||
Some(&Lane::Tab(index)) => {
|
||||
shown[index] = true;
|
||||
@@ -349,8 +330,10 @@ impl StripLayout {
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
at += extent;
|
||||
>>>>>>> origin/next
|
||||
at += extent + tab_gap;
|
||||
}
|
||||
if !fit.shown.is_empty() {
|
||||
at -= tab_gap;
|
||||
}
|
||||
let hidden: Vec<usize> = fit
|
||||
.overflow
|
||||
@@ -398,7 +381,7 @@ impl ItemLayout for StripLayout {
|
||||
return false;
|
||||
}
|
||||
let rect = self.rect(at, offset);
|
||||
point.y >= rect.top() && point.y <= rect.bottom() && point.x >= rect.left() - self.gap && point.x < rect.left()
|
||||
point.y >= rect.top() && point.y <= rect.bottom() && point.x >= rect.left() - self.tab_gap && point.x < rect.left()
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -537,16 +520,13 @@ pub struct TabStrip<'a, K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + '
|
||||
/// Which tabs may be dragged.
|
||||
#[prop(func = "Fn(&K) -> bool")]
|
||||
can_drag: Option<RowTest<'a, K>>,
|
||||
<<<<<<< HEAD
|
||||
/// Which tabs a middle click closes, where the kind closes on one (`TabKind::middle_click_closes`): every tab
|
||||
/// when unset. A host with tabs that cannot close (`Tab::closable(false)`) names the ones that can.
|
||||
#[prop(func = "Fn(&K) -> bool")]
|
||||
can_close: Option<RowTest<'a, K>>,
|
||||
=======
|
||||
/// The role of each tab, an input of the fit: contextual tabs are kept ahead of plain tabs.
|
||||
#[prop(func = "Fn(&K) -> TabRole")]
|
||||
roles: Option<TabRoles<'a, K>>,
|
||||
>>>>>>> origin/next
|
||||
/// What the strip takes from drags that did not start in it, in order.
|
||||
drops: Vec<DropKind<'a, K>>,
|
||||
/// Where the strip's own drag may land: the test gets the drag, the tab under the pointer and the position before which the
|
||||
@@ -601,11 +581,8 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> TabStri
|
||||
tear_off: false,
|
||||
wheel_selects: false,
|
||||
can_drag: None,
|
||||
<<<<<<< HEAD
|
||||
can_close: None,
|
||||
=======
|
||||
roles: None,
|
||||
>>>>>>> origin/next
|
||||
drops: Vec::new(),
|
||||
accepts: None,
|
||||
trailing: &[],
|
||||
@@ -1017,18 +994,6 @@ impl<K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> Collection
|
||||
let count = source.len();
|
||||
*self.texts.borrow_mut() = (0..count).map(|at| (source.key(at), source.text(at).map(|text| text.into_owned()).unwrap_or_default())).collect();
|
||||
let selected = self.shown.as_ref().and_then(|key| source.index_of(key)).unwrap_or(usize::MAX);
|
||||
<<<<<<< HEAD
|
||||
let gap = if self.kind == TabKind::Document { cx.tokens.space.gap.inline } else { 0.0 };
|
||||
StripLayout::new(
|
||||
count,
|
||||
Vec2::new(width, cx.tokens.size.bar.tab),
|
||||
gap,
|
||||
selected,
|
||||
self.kind.fit_mode(),
|
||||
self.report.clone(),
|
||||
cx.frame_ctx().clone(),
|
||||
)
|
||||
=======
|
||||
let keys: Vec<K> = (0..count).map(|at| source.key(at)).collect();
|
||||
// The roles are inputs of the fit: it runs here, before any tab is built.
|
||||
let kept = match &self.roles {
|
||||
@@ -1039,8 +1004,9 @@ impl<K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> Collection
|
||||
// Each end item is measured in this pass, with its label and icon only.
|
||||
let ends = self.trailing.iter().map(|end| end.fit_item(cx)).collect();
|
||||
let fitting = Fitting { selected, mode: self.kind.fit_mode(), kept, ends, gap: cx.tokens.space.gap.inline, ghosts, departed };
|
||||
StripLayout::new(count, width, cx.tokens.size.bar.tab, fitting, self.report.clone(), cx.frame_ctx().clone())
|
||||
>>>>>>> origin/next
|
||||
// Document tabs stand apart by the inline gap; the other kinds touch.
|
||||
let tab_gap = if self.kind == TabKind::Document { cx.tokens.space.gap.inline } else { 0.0 };
|
||||
StripLayout::new(count, Vec2::new(width, cx.tokens.size.bar.tab), tab_gap, fitting, self.report.clone(), cx.frame_ctx().clone())
|
||||
}
|
||||
|
||||
/// Every tab takes the strip's kind and size.
|
||||
|
||||
@@ -19,13 +19,8 @@ use crate::contract::{
|
||||
use crate::display::Progress;
|
||||
use crate::primitives::{IconSpec, PaintShape, RectSide, StrokeWidth, TextRun, Wrap};
|
||||
use crate::runtime::env::Label;
|
||||
<<<<<<< HEAD
|
||||
use crate::style::{ComponentStyle, Flags, IconLook, RuleKind, StyleColor, StyleCx, SurfaceLook, TextLook};
|
||||
use craft_behavior::{Flow, IconId, Insets, Metrics, PartKey, Proposal, Sense};
|
||||
=======
|
||||
use crate::style::{ComponentStyle, Flags, IconLook, RuleKind, StyleColor, StyleCx, SurfaceLook, TextLook, UiTokens};
|
||||
use craft_behavior::{Flow, IconId, Insets, Metrics, PartKey, PointerButton, PressPhase, Proposal, Sense};
|
||||
>>>>>>> origin/next
|
||||
use craft_behavior::{Flow, IconId, Insets, Metrics, PartKey, Proposal, Sense};
|
||||
use craft_theme::{Contrast, Rgba, Stateful, States, TypeRole};
|
||||
use egui::{Pos2, Rect, Response, Vec2};
|
||||
|
||||
@@ -79,15 +74,8 @@ const TEXT: PartKey = PartKey::new("text");
|
||||
const CLOSE: PartKey = PartKey::new("close");
|
||||
const PROGRESS: PartKey = PartKey::new("progress");
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
/// How many of a title's first letters a shrunk tab still shows.
|
||||
const MIN_LETTERS: usize = 3;
|
||||
|
||||
/// The modified mark.
|
||||
const MARK: &str = "*";
|
||||
|
||||
>>>>>>> origin/next
|
||||
const CLOSE_REASON: &str = "The Close command closes the focused tab";
|
||||
|
||||
/// The padding on each side of a ribbon tab's label: the strip insets its sliding underline by it, so the underline
|
||||
@@ -158,18 +146,12 @@ struct Placed {
|
||||
icon: Option<Rect>,
|
||||
label: Rect,
|
||||
detail: Option<Rect>,
|
||||
<<<<<<< HEAD
|
||||
/// The marker dot, after the last text: a modified tab's too.
|
||||
marker: Option<Rect>,
|
||||
progress: Option<Rect>,
|
||||
=======
|
||||
/// The modified mark, right after the last text.
|
||||
mark: Option<Rect>,
|
||||
/// The band the label, detail and mark share.
|
||||
/// The band the label, detail and marker share.
|
||||
band: Rect,
|
||||
/// Whether the band cuts the label or the detail.
|
||||
cut: bool,
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
/// One tab of a strip.
|
||||
@@ -195,7 +177,7 @@ pub struct Tab<'a> {
|
||||
/// An icon before the label.
|
||||
#[prop(into)]
|
||||
icon: Option<IconSpec<'a>>,
|
||||
/// Unsaved changes: a `*` after the detail, or after the label without one.
|
||||
/// Unsaved changes: the marker dot after the detail, or after the label without one.
|
||||
#[prop(flag)]
|
||||
modified: bool,
|
||||
/// Whether the tab can be closed; by default whether the kind shows a close button.
|
||||
@@ -283,10 +265,11 @@ impl<'a> Tab<'a> {
|
||||
let band = flow.rect();
|
||||
let label_natural = natural(&self.label_run(style, label));
|
||||
let detail_natural = self.detail_text().map_or(0.0, |text| natural(&TextRun::new(text).role(style.detail.role)));
|
||||
let mark_width = if self.modified { natural(&self.mark_run(style)) } else { 0.0 };
|
||||
// The marker keeps its room; the label is cut first, then the detail.
|
||||
let marker_width = if self.dotted() { sizes.gap + style.marker } else { 0.0 };
|
||||
let detail_gap = if detail_natural > 0.0 { sizes.gap } else { 0.0 };
|
||||
let label_width = label_natural.min((band.width() - mark_width - detail_gap - detail_natural).max(0.0));
|
||||
let detail_width = detail_natural.min((band.width() - mark_width - label_width - detail_gap).max(0.0));
|
||||
let label_width = label_natural.min((band.width() - marker_width - detail_gap - detail_natural).max(0.0));
|
||||
let detail_width = detail_natural.min((band.width() - marker_width - label_width - detail_gap).max(0.0));
|
||||
let line = |rect: Rect, height: f32| {
|
||||
let top = if sizes.text_only && !sizes.middle { content.top() } else { content.center().y - height / 2.0 };
|
||||
Rect::from_x_y_ranges(rect.x_range(), top..=top + height)
|
||||
@@ -298,10 +281,13 @@ impl<'a> Tab<'a> {
|
||||
} else {
|
||||
(None, rest)
|
||||
};
|
||||
let mark = self.modified.then(|| line(after.take_start(mark_width).0, sizes.label_line));
|
||||
let label = line(label, sizes.label_line);
|
||||
let marker = self.dotted().then(|| {
|
||||
let slot = after.take_start(sizes.gap).1.take_start(style.marker).0;
|
||||
Rect::from_center_size(Pos2::new(slot.center().x, label.center().y), Vec2::splat(style.marker))
|
||||
});
|
||||
let cut = label_width < label_natural || detail_width < detail_natural;
|
||||
Placed { close, icon, label, detail, mark, band, cut }
|
||||
Placed { close, icon, label, detail, marker, band, cut }
|
||||
}
|
||||
|
||||
fn name(&self, label: &str, words: &TabWords) -> String {
|
||||
@@ -410,15 +396,13 @@ impl Component for Tab<'_> {
|
||||
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
let sizes = &cx.style.sizes;
|
||||
<<<<<<< HEAD
|
||||
if cx.proposal == Proposal::Min && self.kind != TabKind::Document {
|
||||
return Vec2::new(sizes.min_content, sizes.label_line);
|
||||
=======
|
||||
if cx.proposal == Proposal::Min {
|
||||
// The first letters of the title: the least a shrunk tab shows.
|
||||
let letters = || {
|
||||
let first: String = cx.resolved.label.chars().take(MIN_LETTERS).collect();
|
||||
let letters = cx.layout_at(&self.label_run(cx.style, &first), f32::INFINITY).size().x;
|
||||
return Vec2::new(letters, sizes.label_line);
|
||||
>>>>>>> origin/next
|
||||
cx.layout_at(&self.label_run(cx.style, &first), f32::INFINITY).size().x
|
||||
};
|
||||
if cx.proposal == Proposal::Min && self.kind != TabKind::Document {
|
||||
return Vec2::new(letters(), sizes.label_line);
|
||||
}
|
||||
let width = |run: &TextRun<'_>| cx.layout_at(run, f32::INFINITY).size().x;
|
||||
let label_width = width(&self.label_run(cx.style, cx.resolved.label));
|
||||
@@ -446,7 +430,7 @@ impl Component for Tab<'_> {
|
||||
let end = cx.resolved.label.char_indices().nth(12).map_or(cx.resolved.label.len(), |(index, _)| index);
|
||||
let prefix = cx.resolved.label.get(..end).unwrap_or(cx.resolved.label);
|
||||
let readable = natural - capped + width(&self.label_run(cx.style, prefix));
|
||||
readable.max(sizes.min_content).min(natural)
|
||||
readable.max(letters()).min(natural)
|
||||
} else {
|
||||
natural
|
||||
};
|
||||
@@ -458,72 +442,19 @@ impl Component for Tab<'_> {
|
||||
}
|
||||
|
||||
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
<<<<<<< HEAD
|
||||
let sizes = cx.style.sizes;
|
||||
let rtl = cx.flow.is_rtl();
|
||||
let content = cx.content_rect;
|
||||
let mut flow = Flow::new(content, rtl);
|
||||
let mut close = None;
|
||||
if self.shows_close() {
|
||||
let at_start = cx.style.close_side == if rtl { CloseSide::Right } else { CloseSide::Left };
|
||||
let (slot, rest) = if at_start { flow.take_start(sizes.close_box) } else { flow.take_end(sizes.close_box) };
|
||||
close = Some(slot);
|
||||
flow = if at_start { rest.take_start(sizes.gap).1 } else { rest.take_end(sizes.gap).1 };
|
||||
}
|
||||
flow = flow.take_end(sizes.tail).1;
|
||||
let mut icon = None;
|
||||
if self.icon.is_some() {
|
||||
let (slot, rest) = flow.take_start(sizes.icon);
|
||||
icon = Some(Rect::from_center_size(slot.center(), Vec2::splat(sizes.icon)));
|
||||
flow = rest.take_start(sizes.gap).1;
|
||||
}
|
||||
let band = flow.rect();
|
||||
let natural = |run: &TextRun<'_>| cx.layout_at(run, f32::INFINITY).size().x;
|
||||
let label_natural = natural(&self.label_run(cx.style, cx.resolved.label));
|
||||
let detail_natural = self.detail_text().map_or(0.0, |text| natural(&TextRun::new(text).role(cx.style.detail.role)));
|
||||
let marker_width = if self.dotted() { sizes.gap + cx.style.marker } else { 0.0 };
|
||||
// The marker keeps its room; the label is cut first, then the detail.
|
||||
let kept = marker_width;
|
||||
let detail_gap = if detail_natural > 0.0 { sizes.gap } else { 0.0 };
|
||||
let label_width = label_natural.min((band.width() - kept - detail_gap - detail_natural).max(0.0));
|
||||
let detail_width = detail_natural.min((band.width() - kept - label_width - detail_gap).max(0.0));
|
||||
let line = |rect: Rect, height: f32| {
|
||||
let top = if sizes.text_only { content.top() } else { content.center().y - height / 2.0 };
|
||||
Rect::from_x_y_ranges(rect.x_range(), top..=top + height)
|
||||
};
|
||||
let (label, rest) = flow.take_start(label_width);
|
||||
let (detail, after) = if detail_width > 0.0 {
|
||||
let (detail, after) = rest.take_start(detail_gap).1.take_start(detail_width);
|
||||
(Some(line(detail, sizes.detail_line)), after)
|
||||
} else {
|
||||
(None, rest)
|
||||
};
|
||||
let label = line(label, sizes.label_line);
|
||||
let marker = self.dotted().then(|| {
|
||||
let slot = after.take_start(sizes.gap).1.take_start(cx.style.marker).0;
|
||||
Rect::from_center_size(Pos2::new(slot.center().x, label.center().y), Vec2::splat(cx.style.marker))
|
||||
});
|
||||
let cut = label_width < label_natural || detail_width < detail_natural;
|
||||
if cut {
|
||||
=======
|
||||
let placed = self.place(cx.style, cx.content_rect, cx.flow.is_rtl(), cx.resolved.label, |run| cx.layout_at(run, f32::INFINITY).size().x);
|
||||
if placed.cut {
|
||||
>>>>>>> origin/next
|
||||
let full = match self.detail_text() {
|
||||
Some(detail) => format!("{}, {detail}", cx.resolved.label),
|
||||
None => cx.resolved.label.to_owned(),
|
||||
};
|
||||
<<<<<<< HEAD
|
||||
// The text part's tooltip covers the tab's own over the text, so the tab's tooltip follows the full label
|
||||
// there; an uncut tab shows the tab's own tooltip alone.
|
||||
let full = match cx.resolved.tooltip_text(&cx.env) {
|
||||
Some(tip) if !tip.is_empty() => format!("{full}\n{tip}"),
|
||||
_ => full,
|
||||
};
|
||||
let _ = cx.part(TEXT, band).tooltip(full);
|
||||
=======
|
||||
let _ = cx.part(TEXT, placed.band).tooltip(full);
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
if let Some(slot) = placed.close {
|
||||
let name = self.close_label.clone();
|
||||
@@ -543,10 +474,6 @@ impl Component for Tab<'_> {
|
||||
if let Some(bar) = progress {
|
||||
let _ = cx.part(PROGRESS, bar);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
self.placed = Some(Placed { close, icon, label, detail, marker, progress });
|
||||
=======
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
|
||||
@@ -4,20 +4,12 @@ mod adorn;
|
||||
pub(crate) mod alt_text;
|
||||
pub(crate) mod chips;
|
||||
mod completions;
|
||||
<<<<<<< HEAD
|
||||
mod hex;
|
||||
mod linked;
|
||||
mod number;
|
||||
mod selectable_text;
|
||||
mod text_field;
|
||||
mod word_run;
|
||||
=======
|
||||
pub(crate) mod hex;
|
||||
pub(crate) mod linked;
|
||||
pub(crate) mod number;
|
||||
pub(crate) mod selectable_text;
|
||||
pub(crate) mod text_field;
|
||||
>>>>>>> origin/next
|
||||
mod word_run;
|
||||
mod words;
|
||||
pub(crate) mod zoom_field;
|
||||
|
||||
|
||||
@@ -323,15 +323,14 @@ impl<'a, V: NumberValue + 'static> NumberField<'a, V> {
|
||||
value.and_then(NumberValue::number).map(|stored| self.to_shown(stored))
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// Whether the field counts percent: it shows one decimal and its sign right after the number.
|
||||
fn is_percent(&self) -> bool {
|
||||
self.codec.is_none() && self.unit_kind == Some(UnitKind::Percent)
|
||||
=======
|
||||
}
|
||||
|
||||
/// Whether the field uses the dash for a missing or invalid value.
|
||||
fn shows_blank(&self, shown: Option<&V>) -> bool {
|
||||
shown.is_none() || non_finite(shown) || (self.status_zoom && shown.and_then(NumberValue::number).is_none())
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
/// The field's codec: the one set, else the env's locale and the spellings of the unit kind (a length field
|
||||
@@ -574,13 +573,9 @@ impl<V: NumberValue + 'static> Component for NumberField<'_, V> {
|
||||
self.options.steps_value = self.presets.is_none() && self.popup_slider.is_none();
|
||||
let shown = cx.value();
|
||||
if self.options.placeholder.is_none() {
|
||||
<<<<<<< HEAD
|
||||
if self.mixed_word && shown.is_none() {
|
||||
self.options.placeholder = Some(cx.words::<TextWords>().mixed.clone());
|
||||
} else if shown.is_none() || non_finite(shown) {
|
||||
=======
|
||||
if self.shows_blank(shown) {
|
||||
>>>>>>> origin/next
|
||||
} else if self.shows_blank(shown) {
|
||||
self.options.placeholder = Some(BLANK.into());
|
||||
} else if self.automatic {
|
||||
self.options.placeholder = Some(cx.words::<TextWords>().automatic.clone());
|
||||
|
||||
@@ -9,11 +9,7 @@ use crate::contract::{
|
||||
Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, MeasureCx, OverlayUi, PaintUi, PartsCx, Pointer as _, Props as _, Role, Sizing,
|
||||
Styled as _, WordSetCx as _,
|
||||
};
|
||||
<<<<<<< HEAD
|
||||
use crate::primitives::{Completer, IconSpec, SubmitKey, TextOptions, TextRun};
|
||||
=======
|
||||
use crate::primitives::{Completer, IconSpec, TabKey, TextOptions, TextRun, Wrap};
|
||||
>>>>>>> origin/next
|
||||
use crate::primitives::{Completer, IconSpec, SubmitKey, TabKey, TextOptions, TextRun, Wrap};
|
||||
use crate::runtime::env::{Label, Message};
|
||||
use craft_behavior::{Codec, EditEvent, IconId, Mixed, PartKey, PlainText, Proposal, Sense};
|
||||
use egui::{Id, Rect, Vec2};
|
||||
|
||||
@@ -5,12 +5,8 @@ use crate::contract::LabelScheme;
|
||||
use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _, Sizing, Validity};
|
||||
use crate::display::{Shade, Text};
|
||||
use crate::form::{Field, FieldGroup};
|
||||
<<<<<<< HEAD
|
||||
use crate::primitives::{Completer, Completion, IconSpec, SubmitKey};
|
||||
=======
|
||||
use crate::layout_components::Stack;
|
||||
use crate::primitives::{Completer, Completion, IconSpec};
|
||||
>>>>>>> origin/next
|
||||
use crate::primitives::{Completer, Completion, IconSpec, SubmitKey};
|
||||
use crate::runtime::env::Message;
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use craft_behavior::{IconId, Mixed, PlainText};
|
||||
|
||||
@@ -32,7 +32,7 @@ pub struct ZoomField {
|
||||
stepper: bool,
|
||||
scrub: bool,
|
||||
enabled: bool,
|
||||
<<<<<<< HEAD
|
||||
status_bar: bool,
|
||||
scale: ZoomScale,
|
||||
}
|
||||
|
||||
@@ -56,16 +56,12 @@ impl ZoomScale {
|
||||
ZoomScale::Points => 1.0,
|
||||
}
|
||||
}
|
||||
=======
|
||||
status_bar: bool,
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
impl ZoomField {
|
||||
/// A zoom field named `label` over `view` (`None` when no view is known) of a document of `document` units.
|
||||
pub fn new(label: impl Into<Label>, view: Option<CanvasView>, document: Size) -> Self {
|
||||
<<<<<<< HEAD
|
||||
ZoomField { label: label.into(), view, document, stepper: false, scrub: false, enabled: true, scale: ZoomScale::Device }
|
||||
ZoomField { label: label.into(), view, document, stepper: false, scrub: false, enabled: true, status_bar: false, scale: ZoomScale::Device }
|
||||
}
|
||||
|
||||
/// What 100 % means: device pixels (the default) or document points.
|
||||
@@ -73,9 +69,6 @@ impl ZoomField {
|
||||
pub fn scale(mut self, scale: ZoomScale) -> Self {
|
||||
self.scale = scale;
|
||||
self
|
||||
=======
|
||||
ZoomField { label: label.into(), view, document, stepper: false, scrub: false, enabled: true, status_bar: false }
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
/// The arrow keys and the wheel step along the zoom ladder.
|
||||
@@ -137,17 +130,13 @@ impl ZoomField {
|
||||
if self.scrub {
|
||||
field = field.scrub_by_label();
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
if self.status_bar {
|
||||
field = field.status_zoom();
|
||||
}
|
||||
let shown = match rect {
|
||||
Some(rect) => field.show_at(ui, rect),
|
||||
None => field.show(ui),
|
||||
};
|
||||
=======
|
||||
if self.status_bar {
|
||||
field = field.status_zoom();
|
||||
}
|
||||
let shown = field.show(ui);
|
||||
>>>>>>> origin/next
|
||||
let invalid_zoom = range.filter(|_| shown.cut).map(|range| InvalidZoom { low: *range.start(), high: *range.end() });
|
||||
let view = match self.view {
|
||||
Some(current) => shown
|
||||
|
||||
@@ -11,11 +11,7 @@ pub(crate) mod stories;
|
||||
use super::headers::Outline;
|
||||
use super::layout::{Around, ArrangeSpacing, GridLayout, Recipe, Slot, TailRow, TileGroup, Tiling, arrange, aspects_of, slot_at};
|
||||
use super::tile::AroundPicture;
|
||||
<<<<<<< HEAD
|
||||
use super::{CaptionPlace, Tile, TileActionPlace, TilePartEvent, TileZoom, ZoomStep};
|
||||
=======
|
||||
use super::{CaptionPlace, CardText, Tile, TilePartEvent, ZoomStep};
|
||||
>>>>>>> origin/next
|
||||
use super::{CaptionPlace, CardText, Tile, TileActionPlace, TilePartEvent, TileZoom, ZoomStep};
|
||||
use crate::contract::{
|
||||
Access, Bind, BindMut, Collection, CollectionEvent, CollectionProps, CollectionResponse, ColumnKind, ColumnSpec, Common, Component,
|
||||
ContainerProps, Cx, DropKind, EditResponse, Focus as _, ListDrag, Meta as _, NoValue, Notch, Outcome, PaintUi, PartsCx, Pointer as _, Props as _,
|
||||
@@ -184,21 +180,13 @@ struct GridSizes {
|
||||
}
|
||||
|
||||
impl GridSizes {
|
||||
<<<<<<< HEAD
|
||||
fn of(cx: &StyleCx<'_>, card: bool, rows: RowHeight, action_place: TileActionPlace) -> GridSizes {
|
||||
=======
|
||||
fn of(cx: &StyleCx<'_>, card: bool, text: CardText, rows: RowHeight, regular_card_padding: bool) -> GridSizes {
|
||||
>>>>>>> origin/next
|
||||
fn of(cx: &StyleCx<'_>, card: bool, text: CardText, rows: RowHeight, regular_card_padding: bool, action_place: TileActionPlace) -> GridSizes {
|
||||
let spacing =
|
||||
ArrangeSpacing::new(if card { cx.tokens.space.gap.section } else { cx.tokens.space.gap.stack }, cx.tokens.space.gap.inline, rows.of(cx));
|
||||
GridSizes {
|
||||
card: cx.tokens.size.thumb.card,
|
||||
thumbs: [cx.tokens.size.thumb.sm, cx.tokens.size.thumb.md, cx.tokens.size.thumb.lg],
|
||||
<<<<<<< HEAD
|
||||
around: Tile::around(cx, card, action_place),
|
||||
=======
|
||||
around: Tile::around(cx, card, text, regular_card_padding),
|
||||
>>>>>>> origin/next
|
||||
around: Tile::around(cx, card, text, regular_card_padding, action_place),
|
||||
spacing,
|
||||
// Bare tiles sit with no gap between them: the room around each picture keeps them apart.
|
||||
bare_spacing: if card { spacing } else { ArrangeSpacing { gap: 0.0, ..spacing } },
|
||||
@@ -500,11 +488,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> TileGrid<'a, K> {
|
||||
/// The layout of this pass: `previous` when it was made from the same recipe, else a new arrangement. A card is
|
||||
/// the picture plus what the tile adds around it in every tiling.
|
||||
fn laid_out(&self, previous: Option<GridLayout>, source: &dyn ItemSource<K>, width: f32, item: Option<Vec2>, cx: &StyleCx<'_>) -> GridLayout {
|
||||
<<<<<<< HEAD
|
||||
let style = GridSizes::of(cx, self.card, self.items.row_height, self.action_place);
|
||||
=======
|
||||
let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding);
|
||||
>>>>>>> origin/next
|
||||
let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding, self.action_place);
|
||||
let spacing = style.spacing(self.caption);
|
||||
let around = style.around.get(self.caption, self.detail_line);
|
||||
// A card never outgrows the grid: in a column narrower than a card the card takes the column.
|
||||
@@ -1002,11 +986,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
|
||||
fn dress_inputs(&self) -> u64 {
|
||||
use std::hash::{Hash as _, Hasher as _};
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
<<<<<<< HEAD
|
||||
(self.caption, self.detail_line, self.card, self.action_place, self.checks).hash(&mut hasher);
|
||||
=======
|
||||
(self.caption, self.detail_line, self.card, self.card_text, self.regular_card_padding).hash(&mut hasher);
|
||||
>>>>>>> origin/next
|
||||
(self.caption, self.detail_line, self.card, self.card_text, self.regular_card_padding, self.action_place, self.checks).hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
||||
@@ -1015,11 +995,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
|
||||
if self.card_columns == 0 {
|
||||
return 0.0;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
let style = GridSizes::of(cx, self.card, self.items.row_height, self.action_place);
|
||||
=======
|
||||
let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding);
|
||||
>>>>>>> origin/next
|
||||
let style = GridSizes::of(cx, self.card, self.card_text, self.items.row_height, self.regular_card_padding, self.action_place);
|
||||
let aspect = if self.aspect.is_finite() && self.aspect > 0.0 { self.aspect } else { 1.0 };
|
||||
let around = style.around.get(self.caption, self.detail_line);
|
||||
let card = style.card(self.picture_side(&style, item, around), aspect, around).x;
|
||||
@@ -1043,15 +1019,10 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Collection for TileGrid<'_, K
|
||||
/// Every tile gets the grid's caption place, detail line and actions' place, the card look, and its row's rename
|
||||
/// state. Under `checks` a tile's check is its own selection, so the app keeps no second copy of it.
|
||||
fn dress<'r>(&self, tile: Self::Item<'r>, row: &RowState) -> Self::Item<'r> {
|
||||
<<<<<<< HEAD
|
||||
let tile =
|
||||
tile.caption(self.caption).detail_line(self.detail_line).action_place(self.action_place).renaming(row.renaming).selected(row.selected);
|
||||
let tile = if self.checks { tile.check(if row.selected { ToggleState::On } else { ToggleState::Off }) } else { tile };
|
||||
if self.card { tile.card() } else { tile }
|
||||
=======
|
||||
let tile = tile.caption(self.caption).detail_line(self.detail_line).renaming(row.renaming);
|
||||
if self.card { tile.card().card_text(self.card_text).regular_card_padding(self.regular_card_padding) } else { tile }
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
|
||||
fn can_rename(&self, key: &K) -> bool {
|
||||
|
||||
@@ -148,10 +148,9 @@ pub(super) struct AroundPicture {
|
||||
}
|
||||
|
||||
impl AroundPicture {
|
||||
<<<<<<< HEAD
|
||||
fn of(cx: &StyleCx<'_>, card: bool, action_place: TileActionPlace) -> AroundPicture {
|
||||
fn of(cx: &StyleCx<'_>, card: bool, text: CardText, regular_card_padding: bool, action_place: TileActionPlace) -> AroundPicture {
|
||||
let around = |place: CaptionPlace, detail: bool| {
|
||||
let sizes = Sizes::of(cx, card, place);
|
||||
let sizes = Sizes::of(cx, card, text, place, regular_card_padding);
|
||||
let mut around = sizes.around(place, detail);
|
||||
if action_place == TileActionPlace::Band {
|
||||
around.start = sizes.glyph + sizes.column(place);
|
||||
@@ -161,10 +160,6 @@ impl AroundPicture {
|
||||
}
|
||||
around
|
||||
};
|
||||
=======
|
||||
fn of(cx: &StyleCx<'_>, card: bool, text: CardText, regular_card_padding: bool) -> AroundPicture {
|
||||
let around = |place: CaptionPlace, detail: bool| Sizes::of(cx, card, text, place, regular_card_padding).around(place, detail);
|
||||
>>>>>>> origin/next
|
||||
AroundPicture {
|
||||
below: around(CaptionPlace::Below, false),
|
||||
below_detail: around(CaptionPlace::Below, true),
|
||||
@@ -579,13 +574,8 @@ impl<'a> Tile<'a> {
|
||||
}
|
||||
|
||||
/// What a tile adds around its picture for every caption arrangement.
|
||||
<<<<<<< HEAD
|
||||
pub(super) fn around(cx: &StyleCx<'_>, card: bool, action_place: TileActionPlace) -> AroundPicture {
|
||||
AroundPicture::of(cx, card, action_place)
|
||||
=======
|
||||
pub(super) fn around(cx: &StyleCx<'_>, card: bool, text: CardText, regular_card_padding: bool) -> AroundPicture {
|
||||
AroundPicture::of(cx, card, text, regular_card_padding)
|
||||
>>>>>>> origin/next
|
||||
pub(super) fn around(cx: &StyleCx<'_>, card: bool, text: CardText, regular_card_padding: bool, action_place: TileActionPlace) -> AroundPicture {
|
||||
AroundPicture::of(cx, card, text, regular_card_padding, action_place)
|
||||
}
|
||||
|
||||
/// Whether the caption band holds a detail line.
|
||||
@@ -793,9 +783,9 @@ impl Component for Tile<'_> {
|
||||
let (state, text) = (&colors.state, &colors.text);
|
||||
let clear = Rgba::TRANSPARENT;
|
||||
let c = |rgba: Rgba| cx.color(rgba);
|
||||
<<<<<<< HEAD
|
||||
let sizes = Sizes::of(cx, key.card, key.caption);
|
||||
// Band tiles use the collection's selection fill over the whole tile.
|
||||
let sizes = Sizes::of(cx, key.card, key.card_text, key.caption, key.regular_card_padding);
|
||||
// Band tiles use the collection's selection fill over the whole tile. Otherwise selection and hover are rings
|
||||
// around the picture; only a card has a fill of its own.
|
||||
let fill = if key.action_place == TileActionPlace::Band {
|
||||
Stateful::new(c(clear)).off(States::new(c(clear), c(state.hover), c(state.pressed), c(clear))).on(States::new(
|
||||
c(state.selected),
|
||||
@@ -804,11 +794,6 @@ impl Component for Tile<'_> {
|
||||
c(state.selected),
|
||||
))
|
||||
} else if key.card {
|
||||
=======
|
||||
let sizes = Sizes::of(cx, key.card, key.card_text, key.caption, key.regular_card_padding);
|
||||
// Selection and hover are rings around the picture; only a card has a fill of its own.
|
||||
let fill = if key.card {
|
||||
>>>>>>> origin/next
|
||||
let raised = colors.surface.raised;
|
||||
let (rest, hover, pressed) = (c(raised), c(over(state.hover, raised)), c(over(state.pressed, raised)));
|
||||
let on = if key.flat_thumbnail {
|
||||
@@ -1085,7 +1070,6 @@ impl Component for Tile<'_> {
|
||||
return;
|
||||
}
|
||||
let flat = CornerRadius::ZERO;
|
||||
<<<<<<< HEAD
|
||||
{
|
||||
let draw = ui.draw();
|
||||
for sheet in &placed.sheets {
|
||||
@@ -1093,10 +1077,9 @@ impl Component for Tile<'_> {
|
||||
draw.stroke(&PaintShape::Rect(*sheet, flat), StrokeWidth::Thin, style.sheet_edge);
|
||||
}
|
||||
}
|
||||
{
|
||||
=======
|
||||
// A card's picture is the sunken surface, which the placeholder's fill matches.
|
||||
let placeholder = if !style.sizes.card && cx.env.surface() == SurfaceKind::Sunken { style.placeholder_on_sunken } else { style.placeholder };
|
||||
if !self.flat_thumbnail {
|
||||
>>>>>>> origin/next
|
||||
// Filled from the outside in, under the picture, so the rings sit outside its edge.
|
||||
let (ring, halo) = (cx.resolve(&style.ring_width), cx.resolve(&style.halo_width));
|
||||
let draw = ui.draw();
|
||||
@@ -1106,31 +1089,15 @@ impl Component for Tile<'_> {
|
||||
if ring > 0.0 {
|
||||
draw.fill(&PaintShape::Rect(picture.expand(ring), flat), cx.resolve(&style.ring));
|
||||
}
|
||||
if style.sizes.card {
|
||||
ui.draw().surface(picture, SurfaceKind::Sunken, Corners::All);
|
||||
} else {
|
||||
let placeholder = if cx.env.surface() == SurfaceKind::Sunken { style.placeholder_on_sunken } else { style.placeholder };
|
||||
ui.draw().fill(&PaintShape::Rect(picture, flat), placeholder);
|
||||
// A band tile's selection fill covers the whole tile, picture included: no well over it.
|
||||
if self.action_place != TileActionPlace::Band {
|
||||
if style.sizes.card {
|
||||
ui.draw().surface(picture, SurfaceKind::Sunken, Corners::All);
|
||||
} else {
|
||||
ui.draw().fill(&PaintShape::Rect(picture, flat), placeholder);
|
||||
}
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
// A card's picture is the sunken surface, which the placeholder's fill matches.
|
||||
let placeholder = if !style.sizes.card && cx.env.surface() == SurfaceKind::Sunken { style.placeholder_on_sunken } else { style.placeholder };
|
||||
if self.action_place != TileActionPlace::Band {
|
||||
if style.sizes.card {
|
||||
ui.draw().surface(picture, SurfaceKind::Sunken, Corners::All);
|
||||
} else {
|
||||
ui.draw().fill(&PaintShape::Rect(picture, flat), placeholder);
|
||||
}
|
||||
}
|
||||
if let Some(paint) = self.first.take() {
|
||||
let _ = ui.child("picture", picture, RowThumb::new(paint));
|
||||
}
|
||||
let face_ink = match self.hue {
|
||||
Some(hue) => ui.with_style(cx.resolved.variant, |scx| scx.ink_of(hue, Rgba::from(placeholder.egui()))),
|
||||
None => cx.resolve(&style.face.color),
|
||||
};
|
||||
=======
|
||||
// Only over the sunken well: a flat thumbnail (a page outline on the card, as the New Document presets draw)
|
||||
// has no well and takes no frame.
|
||||
let framed = style.sizes.card && !self.flat_thumbnail && (self.first.is_some() || self.picture.is_some());
|
||||
@@ -1145,7 +1112,10 @@ impl Component for Tile<'_> {
|
||||
// frame goes over the picture so all four sides show.
|
||||
ui.draw().surface(picture, SurfaceKind::Frame, Corners::All);
|
||||
}
|
||||
>>>>>>> origin/next
|
||||
let face_ink = match self.hue {
|
||||
Some(hue) => ui.with_style(cx.resolved.variant, |scx| scx.ink_of(hue, Rgba::from(placeholder.egui()))),
|
||||
None => cx.resolve(&style.face.color),
|
||||
};
|
||||
{
|
||||
let draw = ui.draw();
|
||||
let face = self.icon.take().or_else(|| self.folder.then(|| IconSpec::svg(IconId::new("folder"))));
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//! The accessibility emitter: the label scope and merge rule, announcements, modal inertness, viewports.
|
||||
|
||||
<<<<<<< HEAD
|
||||
mod scroll_into_view;
|
||||
mod step_ends;
|
||||
pub(crate) mod scroll_into_view;
|
||||
pub(crate) mod step_ends;
|
||||
|
||||
use craft_ui::contract::{Bind, Show as _, ShowContainer as _};
|
||||
use craft_ui::form::{Field, Help};
|
||||
@@ -22,7 +21,3 @@ fn a_field_help_line_describes_its_control() {
|
||||
let field = fixture.by_label("Limit").expect("the field's control");
|
||||
assert_eq!(fixture.tree().description_of(field.node), Some(HINT));
|
||||
}
|
||||
=======
|
||||
pub(crate) mod scroll_into_view;
|
||||
pub(crate) mod step_ends;
|
||||
>>>>>>> origin/next
|
||||
@@ -450,7 +450,6 @@ fn a_labelled_check_box_in_a_row_in_a_bar_lays_out_under_rtl() {
|
||||
assert!(label.max.x <= alpha.min.x + SLACK, "the check box {label:?} follows Alpha {alpha:?} from the right");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A text tab strip in a tool bar's row, as a window's mode strip: the row gives it unbounded room, so it measures
|
||||
/// the natural length of its tabs and every tab shows, none in the overflow menu, and the strip ends before the
|
||||
/// bar's trailing group.
|
||||
@@ -487,7 +486,8 @@ fn a_tab_strip_in_a_bar_row_takes_its_tabs_natural_length() {
|
||||
let length: f32 = shown.iter().map(Rect::width).sum();
|
||||
assert!(strip.width() >= length - SLACK, "the strip is as long as its tabs: {dump}");
|
||||
assert!(strip.max.x <= trailing.min.x + SLACK, "and ends before the trailing group: {dump}");
|
||||
=======
|
||||
}
|
||||
|
||||
/// An icon-only button in an options bar draws its icon at the tool size, as the align strip's buttons do.
|
||||
#[trial]
|
||||
fn an_icon_button_in_an_options_bar_draws_its_icon_at_the_tool_size() {
|
||||
@@ -566,5 +566,4 @@ fn a_tool_bar_reports_set_positions_from_its_first_pass() {
|
||||
fixture.idle(1);
|
||||
let joined = places(&fixture);
|
||||
assert!(joined.len() == 4 && joined.iter().all(|(_, held)| *held == size + 1), "the set counts the new tool in the frame it joins: {joined:?}");
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
//! The command board: registry, state, the gate, firing and scoped delivery.
|
||||
|
||||
<<<<<<< HEAD
|
||||
mod panel_scope;
|
||||
pub(crate) mod panel_scope;
|
||||
|
||||
use craft_behavior::IconId;
|
||||
use craft_ui::buttons::{Button, IconButton};
|
||||
@@ -59,6 +58,3 @@ fn a_bound_commands_hint_is_the_tooltips_second_line() {
|
||||
let text = tooltip_of(HintCommand::Open, CommandState::new().hint(OPENS), |ui| Button::new("Open").command(HintCommand::Open).show(ui).rect);
|
||||
assert!(text.starts_with(&format!("{OPENS} (")) && text.ends_with(')') && !text.contains('\n'), "the hint alone, with the chord: {text:?}");
|
||||
}
|
||||
=======
|
||||
pub(crate) mod panel_scope;
|
||||
>>>>>>> origin/next
|
||||
@@ -146,7 +146,6 @@ fn arrows_move_through_a_radio_group_without_picking_and_enter_picks() {
|
||||
assert_eq!(picked.get(), 2, "Enter picks the focused radio");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A quiet check box (a thumbnail tile's) is a smaller box than the standard one.
|
||||
#[trial]
|
||||
fn a_quiet_check_box_is_smaller_than_the_standard_one() {
|
||||
@@ -161,7 +160,8 @@ fn a_quiet_check_box_is_smaller_than_the_standard_one() {
|
||||
shown.get().height()
|
||||
};
|
||||
assert!(side(true) < side(false), "quiet {} against standard {}", side(true), side(false));
|
||||
=======
|
||||
}
|
||||
|
||||
/// A click on a field's label focuses its one control when the control sits in an unlabelled row beside text that
|
||||
/// takes no focus (a unit after a number field). The row makes its node by its type's role but reports none, so the
|
||||
/// label scope must still see the number field. Before that, the scope saw no control and the click did nothing.
|
||||
@@ -197,5 +197,4 @@ fn a_click_on_a_label_focuses_its_control_inside_an_unlabelled_row() {
|
||||
let label = label.and_then(|key| fixture.target(key)).expect("the field's label node");
|
||||
fixture.access(AccessActionKind::Click, &label).settle();
|
||||
assert_eq!(fixture.focused_stop().map(|(id, _)| id), Some(field.get()), "the click on the label focuses the number field");
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -133,7 +133,6 @@ fn a_control_that_paints_no_label_shows_its_own_label_as_tooltip() {
|
||||
assert_eq!(glyph_label(Some("Leading (1/1000 em)")), ["Leading (1/1000 em)"], "a glyph label's tooltip replaces its name");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
const SPOT: craft_behavior::PartKey = craft_behavior::PartKey::new("spot");
|
||||
|
||||
/// A layer of pointer-only spots over content it does not paint (comments over a page): it takes no room of its own,
|
||||
@@ -183,7 +182,8 @@ fn a_part_tip_shows_on_a_rest_on_the_part() {
|
||||
});
|
||||
assert!(added.iter().any(|text| text.contains("Alpha")), "the spot's tip shows ({at:?}): {added:?}");
|
||||
}
|
||||
=======
|
||||
}
|
||||
|
||||
/// The command the hint trials bind: an app command with a chord.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)]
|
||||
#[command(prefix = "tooltipHintTrial")]
|
||||
@@ -288,5 +288,4 @@ fn a_tooltip_shown_from_inside_a_body_keeps_its_rect_frame_to_frame() {
|
||||
}
|
||||
let first = frames[0].1;
|
||||
assert!(first.is_some() && frames.iter().all(|(passes, rect)| *passes == 1 && *rect == first), "one pass a frame and one rect: {frames:?}");
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -1267,7 +1267,6 @@ fn a_row_dragged_to_the_edge_scrolls_the_list_and_rests_without_frames() {
|
||||
fixture.release_at(Pos2::new(grab.x, list.center().y));
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A right click on a row's button asks for the row's menu, as a right click elsewhere on the row does, and does not
|
||||
/// press the button: an attachment's Save button opens the attachment's menu.
|
||||
#[trial]
|
||||
@@ -1610,7 +1609,8 @@ fn a_revealed_part_is_exposed_only_while_its_row_shows_it() {
|
||||
fixture.frame(vec![pointer::moved(over)]).settle();
|
||||
assert!(fixture.by_label(MOVES[1]).is_some(), "the hovered row's part is exposed");
|
||||
assert!(fixture.by_label(MOVES[0]).is_none() && fixture.by_label(MOVES[2]).is_none(), "the other rows' parts stay hidden");
|
||||
=======
|
||||
}
|
||||
|
||||
/// Auto rows place by their measure in the first frame. In a column sized from its content along the height, where
|
||||
/// each pass runs the list's measuring run and its real run, the first frame runs once, measures each row once, builds each row at most
|
||||
/// twice, and places the rows and the list where the settled list has them. A click that selects a row and a rename
|
||||
@@ -1697,5 +1697,4 @@ fn page_down_on_a_control_in_a_row_pages_the_capped_list() {
|
||||
assert_eq!(craft_ui::testing::access::focused_key(fixture.tree()), segment.node, "the first row's segment took the focus");
|
||||
fixture.key(Key::PageDown, Modifiers::NONE).settle();
|
||||
assert!(!in_view(&fixture, "Layer 0") && in_view(&fixture, "Layer 8"), "PageDown on the row's control paged the rows");
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -6,32 +6,13 @@ extern crate craft_ui_widgets as craft_ui;
|
||||
pub(crate) mod access;
|
||||
pub(crate) mod bars;
|
||||
pub(crate) mod body;
|
||||
<<<<<<< HEAD
|
||||
mod commands;
|
||||
mod contract;
|
||||
mod disabled_fade;
|
||||
mod field_text_centred;
|
||||
mod focus_ring;
|
||||
mod keys;
|
||||
mod label;
|
||||
mod layer;
|
||||
mod layout;
|
||||
mod link;
|
||||
mod list;
|
||||
mod menu;
|
||||
mod notices;
|
||||
mod overlay;
|
||||
mod pickers;
|
||||
mod picture;
|
||||
mod popover;
|
||||
mod runtime;
|
||||
=======
|
||||
pub(crate) mod buttons;
|
||||
pub(crate) mod checkbox_sweep;
|
||||
pub(crate) mod commands;
|
||||
pub(crate) mod contract;
|
||||
pub(crate) mod disabled_fade;
|
||||
pub(crate) mod field_text_centred;
|
||||
pub(crate) mod focus_ring;
|
||||
pub(crate) mod keys;
|
||||
pub(crate) mod label;
|
||||
pub(crate) mod layer;
|
||||
@@ -41,12 +22,10 @@ pub(crate) mod list;
|
||||
pub(crate) mod menu;
|
||||
pub(crate) mod notices;
|
||||
pub(crate) mod overlay;
|
||||
|
||||
pub(crate) mod pickers;
|
||||
pub(crate) mod picture;
|
||||
pub(crate) mod popover;
|
||||
pub(crate) mod runtime;
|
||||
>>>>>>> origin/next
|
||||
|
||||
pub(crate) mod suite_rtl;
|
||||
pub(crate) mod suite_rules;
|
||||
|
||||
@@ -4,13 +4,9 @@ pub(crate) mod bar;
|
||||
|
||||
pub(crate) mod closed;
|
||||
|
||||
<<<<<<< HEAD
|
||||
mod icon_row;
|
||||
|
||||
mod native;
|
||||
=======
|
||||
pub(crate) mod companion;
|
||||
>>>>>>> origin/next
|
||||
|
||||
pub(crate) mod icon_row;
|
||||
|
||||
pub(crate) mod native;
|
||||
|
||||
|
||||
@@ -191,7 +191,6 @@ fn a_letter_no_row_takes_while_a_menu_is_open_does_not_reach_the_text_field_unde
|
||||
assert_eq!(*text.borrow(), "hello", "the letter does not reach the field");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A radio row that is not the choice shows an empty ring in its mark column, so the choices read as a group; the
|
||||
/// chosen one shows the dot.
|
||||
#[trial]
|
||||
@@ -208,7 +207,8 @@ fn an_unchosen_radio_row_shows_an_empty_ring() {
|
||||
_ => false,
|
||||
});
|
||||
assert!(ring, "an unchosen radio row paints a ring");
|
||||
=======
|
||||
}
|
||||
|
||||
/// The fills painted as rects inside `row`, a row's highlight among them.
|
||||
fn fills_in(shapes: &[egui::Shape], row: egui::Rect) -> Vec<egui::Color32> {
|
||||
shapes
|
||||
@@ -296,5 +296,4 @@ fn the_open_submenu_parent_keeps_the_accent_when_the_pointer_enters_its_child()
|
||||
assert_eq!(parent_state.get(), (false, true), "the parent remains open with the active row now in its submenu");
|
||||
assert_eq!(fills_in(&shapes, parent), accent, "the parent keeps its accent while its child is active at {scale}×");
|
||||
}
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -1,21 +1,12 @@
|
||||
//! Dropdown pickers.
|
||||
|
||||
<<<<<<< HEAD
|
||||
mod combo_list;
|
||||
mod date;
|
||||
mod select_arrow;
|
||||
mod select_list;
|
||||
mod select_steps;
|
||||
mod select_width;
|
||||
mod tree_list;
|
||||
=======
|
||||
pub(crate) mod combo_list;
|
||||
pub(crate) mod date;
|
||||
pub(crate) mod icon_picker;
|
||||
pub(crate) mod select_arrow;
|
||||
pub(crate) mod select_list;
|
||||
pub(crate) mod select_measure;
|
||||
pub(crate) mod select_steps;
|
||||
pub(crate) mod select_width;
|
||||
pub(crate) mod swatch_table;
|
||||
pub(crate) mod tree_list;
|
||||
>>>>>>> origin/next
|
||||
@@ -1,10 +1,12 @@
|
||||
<<<<<<< HEAD
|
||||
//! `Picture`'s SVG source on hostile input.
|
||||
//! `Picture`: its SVG source on hostile input, and sizing in device pixels.
|
||||
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::display::Picture;
|
||||
use craft_ui::display::{Picture, PictureSize};
|
||||
use craft_ui::runtime::env::Scale;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Rect, Shape, Vec2, pos2, vec2};
|
||||
use egui::{Color32, ColorImage, Rect, Shape, Vec2, pos2, vec2};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A small valid drawing.
|
||||
const MARK: &[u8] = br##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#2a7"/></svg>"##;
|
||||
@@ -75,16 +77,8 @@ fn a_malformed_or_oversized_svg_draws_nothing_and_never_panics() {
|
||||
}
|
||||
let marks = drawn.iter().filter(|picture| valid.expand(0.5).contains_rect(**picture)).count();
|
||||
assert_eq!(marks, 1, "frame {frame}: the valid mark draws one picture: {drawn:?}");
|
||||
=======
|
||||
//! `Picture` sized in device pixels.
|
||||
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::display::{Picture, PictureSize};
|
||||
use craft_ui::runtime::env::Scale;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Color32, ColorImage, Vec2};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
}
|
||||
}
|
||||
|
||||
/// The side, in texels, of the picture's image.
|
||||
const SIDE: usize = 32;
|
||||
@@ -110,6 +104,5 @@ fn a_device_pixel_picture_keeps_one_texel_to_a_pixel_at_every_scale() {
|
||||
(device.x - SIDE as f32).abs() < 0.01 && (device.y - SIDE as f32).abs() < 0.01,
|
||||
"at scale {scale} the picture is {device:?} device pixels, not {SIDE} square"
|
||||
);
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ fn document_tabs_leave_space_between_neighbours() {
|
||||
|
||||
#[trial]
|
||||
fn document_tabs_shrink_before_overflow() {
|
||||
let fit = TabKind::Document.fit_mode().fit(&[100.0, 100.0, 100.0], 0, 240.0, 50.0, 20.0);
|
||||
let fit = TabKind::Document.fit_mode().fit(&[100.0, 100.0, 100.0], 0, &[], 240.0, 50.0, 20.0);
|
||||
assert!(fit.overflow.is_empty(), "tabs that can shrink into the strip remain visible");
|
||||
assert!(fit.shown.iter().all(|(_, width)| *width < 100.0));
|
||||
}
|
||||
@@ -584,7 +584,6 @@ fn the_strip_reports_the_tab_under_the_pointer_while_another_root_holds_the_pres
|
||||
assert_eq!(*seen.borrow(), None, "the empty room has no tab");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A secondary click on a document tab asks for the tab's menu without showing the tab.
|
||||
#[trial]
|
||||
fn a_secondary_click_on_a_document_tab_asks_for_its_menu_without_showing_it() {
|
||||
@@ -595,7 +594,88 @@ fn a_secondary_click_on_a_document_tab_asks_for_its_menu_without_showing_it() {
|
||||
let keys = [0_usize, 1, 2];
|
||||
let source = keyed(&keys, |key: &usize| *key);
|
||||
let out = TabStrip::new("Documents").shown(now.get()).show_items(ui, &source, &mut |key, _| Tab::new(TITLES[*key]));
|
||||
=======
|
||||
for event in &out.response.events {
|
||||
if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event
|
||||
&& let Some(key) = keys.last()
|
||||
{
|
||||
now.set(*key);
|
||||
}
|
||||
}
|
||||
if out.menu.is_some() {
|
||||
asked.set(asked.get() + 1);
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let two = tab_rect(fixture.tree(), "Two").center();
|
||||
fixture.frame(vec![moved(two)]);
|
||||
fixture.frame(vec![secondary(two, true)]);
|
||||
fixture.frame(vec![secondary(two, false)]);
|
||||
fixture.settle();
|
||||
assert!(menus.get() > 0, "the secondary click asks for the tab's menu");
|
||||
assert_eq!(shown.get(), 0, "the secondary click does not show the tab");
|
||||
}
|
||||
|
||||
/// A modified document tab marks itself with the suite's dot, not an asterisk after its name: no `*` is painted and the
|
||||
/// tab is as wide as an unmodified one plus the dot's room.
|
||||
#[trial]
|
||||
fn a_modified_document_tab_shows_a_dot_and_no_asterisk() {
|
||||
use craft_ui::tabs::{DocumentTab, DocumentTabs};
|
||||
let tab = |modified: bool| {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let tabs = [DocumentTab::new(0, "Report.pdf").modified(modified)];
|
||||
let _ = DocumentTabs::new("Docs", &tabs).selected(0).show(ui);
|
||||
});
|
||||
fixture.room(egui::vec2(600.0, 100.0)).settle();
|
||||
let stars = fixture.texts().iter().filter(|run| run.text.contains('*')).count();
|
||||
let width = fixture.by_role(Role::TAB).first().map_or(0.0, |tab| tab.rect.width());
|
||||
(stars, width)
|
||||
};
|
||||
let (plain, modified) = (tab(false), tab(true));
|
||||
assert_eq!(modified.0, 0, "no asterisk is painted");
|
||||
assert!(modified.1 > plain.1, "the dot takes room beside the name: {} vs {}", modified.1, plain.1);
|
||||
}
|
||||
|
||||
/// Production shows the held tab in the strip and no filename badge by the pointer: while a document tab is dragged, its
|
||||
/// name is painted once.
|
||||
#[trial]
|
||||
fn a_dragged_document_tab_shows_no_badge() {
|
||||
use craft_ui::tabs::{DocumentTab, DocumentTabs};
|
||||
let tabs = [DocumentTab::new(0_usize, "Quarterly"), DocumentTab::new(1, "Other")];
|
||||
let mut frames = Frames::new();
|
||||
let mut show = |ui: &mut Ui| {
|
||||
let _ = DocumentTabs::new("Documents", &tabs).selected(0).reorderable(true).show(ui);
|
||||
};
|
||||
frames.idle(2, &mut show);
|
||||
let tree = frames.tree();
|
||||
let one = tab_rect(&tree, "Quarterly");
|
||||
let to = Pos2::new(one.center().x, one.center().y + 60.0);
|
||||
frames.frame(vec![moved(one.center())], &mut show);
|
||||
frames.frame(vec![press(one.center())], &mut show);
|
||||
for step in 1..=4 {
|
||||
frames.frame(vec![moved(one.center().lerp(to, step as f32 / 4.0))], &mut show);
|
||||
}
|
||||
frames.idle(2, &mut show);
|
||||
let shown = frames.texts().iter().filter(|text| text.text == "Quarterly").count();
|
||||
assert_eq!(shown, 1, "the name is painted once, by the held tab, with no badge beside the pointer");
|
||||
}
|
||||
|
||||
/// A very long document name does not stretch its tab across the strip: the tab stays near 22 characters wide and the
|
||||
/// next tab keeps its room.
|
||||
#[trial]
|
||||
fn a_very_long_document_name_is_cut_to_a_compact_tab() {
|
||||
use craft_ui::tabs::{DocumentTab, DocumentTabs};
|
||||
let long = "a-very-long-synthetic-document-file-name-for-truncation-test-1234567890.pdf";
|
||||
let tabs = [DocumentTab::new(0_usize, long), DocumentTab::new(1, "Short")];
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = DocumentTabs::new("Documents", &tabs).selected(0).show(ui);
|
||||
});
|
||||
fixture.idle(6);
|
||||
let tab = fixture.by_label(long).expect("the long tab").rect;
|
||||
let short = fixture.by_label("Short").expect("the next tab").rect;
|
||||
assert!(tab.width() < 320.0, "the long name is cut short, got {}", tab.width());
|
||||
assert!(short.left() >= tab.right(), "the next tab follows it");
|
||||
}
|
||||
|
||||
const PANELS: [&str; 6] = ["Layers", "Channels", "Properties", "Adjustments", "History", "Navigator"];
|
||||
|
||||
/// The widths of the panel tabs a strip shows in a room `room` wide, by title, with the second panel shown.
|
||||
@@ -723,7 +803,6 @@ fn the_ribbon_underline_retargets_from_its_shown_position_mid_motion() {
|
||||
let source = keyed(&keys, |key: &usize| *key);
|
||||
let strip = TabStrip::new("Ribbon").kind(TabKind::Ribbon).wheel_selects().shown(now.get());
|
||||
let out = strip.show_items(ui, &source, &mut |key, _| Tab::new(RIBBON[*key]));
|
||||
>>>>>>> origin/next
|
||||
for event in &out.response.events {
|
||||
if let CollectionEvent::Selection(SelectionChange::Set(keys)) = event
|
||||
&& let Some(key) = keys.last()
|
||||
@@ -731,81 +810,6 @@ fn the_ribbon_underline_retargets_from_its_shown_position_mid_motion() {
|
||||
now.set(*key);
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
if out.menu.is_some() {
|
||||
asked.set(asked.get() + 1);
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let two = tab_rect(fixture.tree(), "Two").center();
|
||||
fixture.frame(vec![moved(two)]);
|
||||
fixture.frame(vec![secondary(two, true)]);
|
||||
fixture.frame(vec![secondary(two, false)]);
|
||||
fixture.settle();
|
||||
assert!(menus.get() > 0, "the secondary click asks for the tab's menu");
|
||||
assert_eq!(shown.get(), 0, "the secondary click does not show the tab");
|
||||
}
|
||||
|
||||
/// A modified document tab marks itself with the suite's dot, not an asterisk after its name: no `*` is painted and the
|
||||
/// tab is as wide as an unmodified one plus the dot's room.
|
||||
#[trial]
|
||||
fn a_modified_document_tab_shows_a_dot_and_no_asterisk() {
|
||||
use craft_ui::tabs::{DocumentTab, DocumentTabs};
|
||||
let tab = |modified: bool| {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let tabs = [DocumentTab::new(0, "Report.pdf").modified(modified)];
|
||||
let _ = DocumentTabs::new("Docs", &tabs).selected(0).show(ui);
|
||||
});
|
||||
fixture.room(egui::vec2(600.0, 100.0)).settle();
|
||||
let stars = fixture.texts().iter().filter(|run| run.text.contains('*')).count();
|
||||
let width = fixture.by_role(Role::TAB).first().map_or(0.0, |tab| tab.rect.width());
|
||||
(stars, width)
|
||||
};
|
||||
let (plain, modified) = (tab(false), tab(true));
|
||||
assert_eq!(modified.0, 0, "no asterisk is painted");
|
||||
assert!(modified.1 > plain.1, "the dot takes room beside the name: {} vs {}", modified.1, plain.1);
|
||||
}
|
||||
|
||||
/// Production shows the held tab in the strip and no filename badge by the pointer: while a document tab is dragged, its
|
||||
/// name is painted once.
|
||||
#[trial]
|
||||
fn a_dragged_document_tab_shows_no_badge() {
|
||||
use craft_ui::tabs::{DocumentTab, DocumentTabs};
|
||||
let tabs = [DocumentTab::new(0_usize, "Quarterly"), DocumentTab::new(1, "Other")];
|
||||
let mut frames = Frames::new();
|
||||
let mut show = |ui: &mut Ui| {
|
||||
let _ = DocumentTabs::new("Documents", &tabs).selected(0).reorderable(true).show(ui);
|
||||
};
|
||||
frames.idle(2, &mut show);
|
||||
let tree = frames.tree();
|
||||
let one = tab_rect(&tree, "Quarterly");
|
||||
let to = Pos2::new(one.center().x, one.center().y + 60.0);
|
||||
frames.frame(vec![moved(one.center())], &mut show);
|
||||
frames.frame(vec![press(one.center())], &mut show);
|
||||
for step in 1..=4 {
|
||||
frames.frame(vec![moved(one.center().lerp(to, step as f32 / 4.0))], &mut show);
|
||||
}
|
||||
frames.idle(2, &mut show);
|
||||
let shown = frames.texts().iter().filter(|text| text.text == "Quarterly").count();
|
||||
assert_eq!(shown, 1, "the name is painted once, by the held tab, with no badge beside the pointer");
|
||||
}
|
||||
|
||||
/// A very long document name does not stretch its tab across the strip: the tab stays near 22 characters wide and the
|
||||
/// next tab keeps its room.
|
||||
#[trial]
|
||||
fn a_very_long_document_name_is_cut_to_a_compact_tab() {
|
||||
use craft_ui::tabs::{DocumentTab, DocumentTabs};
|
||||
let long = "a-very-long-synthetic-document-file-name-for-truncation-test-1234567890.pdf";
|
||||
let tabs = [DocumentTab::new(0_usize, long), DocumentTab::new(1, "Short")];
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = DocumentTabs::new("Documents", &tabs).selected(0).show(ui);
|
||||
});
|
||||
fixture.idle(6);
|
||||
let tab = fixture.by_label(long).expect("the long tab").rect;
|
||||
let short = fixture.by_label("Short").expect("the next tab").rect;
|
||||
assert!(tab.width() < 320.0, "the long name is cut short, got {}", tab.width());
|
||||
assert!(short.left() >= tab.right(), "the next tab follows it");
|
||||
=======
|
||||
});
|
||||
fixture.room(egui::Vec2::new(640.0, 120.0)).settle();
|
||||
let (first, third) = (tab_rect(fixture.tree(), RIBBON[0]), tab_rect(fixture.tree(), RIBBON[2]));
|
||||
@@ -1044,5 +1048,4 @@ fn a_contextual_tab_that_leaves_is_not_hit_or_listed_while_it_fades() {
|
||||
let back = fixture.by_label(RIBBON[TABLE]).expect("a contextual tab that enters has a node once listed");
|
||||
fixture.click(&back);
|
||||
assert_eq!(shown.get(), TABLE, "a click on the entering tab shows it");
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -5,26 +5,15 @@ pub(crate) mod edit_menu;
|
||||
pub(crate) mod fields;
|
||||
pub(crate) mod hex;
|
||||
mod kit;
|
||||
<<<<<<< HEAD
|
||||
mod linked;
|
||||
mod mixed_blank;
|
||||
mod number;
|
||||
mod number_length;
|
||||
mod rtl_paragraph;
|
||||
mod selectable;
|
||||
mod submit_key;
|
||||
mod text_field;
|
||||
mod widths;
|
||||
mod word_run;
|
||||
mod zoom_field;
|
||||
=======
|
||||
pub(crate) mod linked;
|
||||
pub(crate) mod mixed_blank;
|
||||
pub(crate) mod number;
|
||||
pub(crate) mod number_length;
|
||||
pub(crate) mod number_scrub_step;
|
||||
pub(crate) mod rtl_paragraph;
|
||||
pub(crate) mod selectable;
|
||||
pub(crate) mod submit_key;
|
||||
pub(crate) mod text_field;
|
||||
pub(crate) mod widths;
|
||||
pub(crate) mod word_run;
|
||||
pub(crate) mod zoom_field;
|
||||
>>>>>>> origin/next
|
||||
@@ -106,7 +106,6 @@ fn a_letter_typed_into_a_field_is_its_own() {
|
||||
assert!(!app_read.borrow().contains(&Key::T), "and the app reads no press of it");
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A field a click opens with a `Take` request, sent in that one pass, takes the typed keys at once: the press on
|
||||
/// the opening button does not take the focus back. A field shown later with a `WhenNone` request leaves the focus
|
||||
/// where it is.
|
||||
@@ -148,7 +147,8 @@ fn a_one_shot_focus_request_takes_the_keys_and_when_none_leaves_a_held_focus() {
|
||||
fixture.idle(2);
|
||||
assert_eq!(*inline.borrow(), "abcd", "the focused field keeps the keys");
|
||||
assert_eq!(*search.borrow(), "", "a `WhenNone` request takes no focus a field holds");
|
||||
=======
|
||||
}
|
||||
|
||||
/// A two-line field capped at four grows with each typed line past its two up to four, then keeps its height: the
|
||||
/// text scrolls inside it with the caret's line, the last, in view, and the wheel over it scrolls the text back.
|
||||
#[trial]
|
||||
@@ -274,5 +274,4 @@ fn a_bound_caret_moves_the_caret_and_follows_it() {
|
||||
fixture.key(Key::ArrowRight, Modifiers::NONE);
|
||||
fixture.idle(2);
|
||||
assert_eq!(caret.get(), 4, "the user's caret move past the two-byte \"é\" writes its byte offset back");
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
@@ -106,7 +106,6 @@ fn the_badge_bar_leaves_out_what_does_not_fit_and_never_overlaps() {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
/// A named hover action carries its tile in its accessible name, so the shown actions of different tiles are told
|
||||
/// apart; a selected tile shows its actions without the pointer, and the actions of a tile that does not show them
|
||||
/// stay out of the tree.
|
||||
@@ -150,7 +149,8 @@ fn a_selected_band_tile_is_outlined() {
|
||||
shapes.iter().filter(|shape| matches!(shape, Shape::Rect(rect) if rect.stroke.width > 0.0 && rect.stroke.color.a() > 0)).count()
|
||||
};
|
||||
assert!(edges(true) > edges(false), "selected {} against unselected {}", edges(true), edges(false));
|
||||
=======
|
||||
}
|
||||
|
||||
/// A card of a preset centres its name; a card of a file sets it at the reading start.
|
||||
#[trial]
|
||||
fn card_text_places_the_name_centred_for_presets_and_at_the_start_for_files() {
|
||||
@@ -170,5 +170,4 @@ fn card_text_places_the_name_centred_for_presets_and_at_the_start_for_files() {
|
||||
assert!((name.center().x - tile.center().x).abs() <= 1.0, "a preset's name is centred: {name:?} in {tile:?}");
|
||||
let (tile, name) = name_in(CardText::File);
|
||||
assert!(name.left() - tile.left() < tile.width() / 4.0, "a file's name starts at the tile's start edge: {name:?} in {tile:?}");
|
||||
>>>>>>> origin/next
|
||||
}
|
||||
Reference in new issue
Block a user