Forge's app switcher needs two layouts the existing widget set didn't cover. The desktop grid wants a partial last row centred under the rows above (3 tiles → row 1: two, row 2: one centred) so a 7-of-9 leftover band reads balanced rather than left-aligned. The mobile variant wants a horizontal carousel where the focused tile sits centred in the viewport at a configurable fraction of its width and its neighbours peek out on the sides at a fixed gap.
Extend `WrapGrid` with `centre_last_row( bool )`. When set, layout offsets a row that has fewer than `columns` children by `(missing * (cell_w + spacing)) / 2` so it stays centred inside the content rect. Defaults to false; every existing call site continues to land tiles flush-left. Covered by three layout tests (centred partial row, full row no-op, off-by-default).
Add the `Carousel` widget at `src/widget/carousel/`. It is a pure layout primitive: `focused_width_frac` (0.05–1.0, clamped), `gap` and `offset` are owned by the caller, leaving drag / inertia / snap policy to the host so the compositor can plug in its existing touch pipeline. Each child gets a rect at `base_x + idx * (child_w + gap)` and the full viewport height; `snap_offset( viewport_w, idx )` translates index to centring offset and `focused_index( viewport_w )` rounds the current offset back to the nearest tile. Plumbed into `Element::Carousel` with the matching arms in `widget/element.rs` and walker in `draw/layout.rs`; re-exported as `ltk::{ Carousel, carousel }`. Covered by nine unit tests (layout, offset shift, snap / focus round-trip, frac clamp, child height) plus a `cargo run --example carousel` demo with Prev / Next / arrow-key navigation against an external offset state. The example is wired into the `examples` Makefile target.
Updates the widget catalogue and the `widget/mod.rs` landing comment to list the carousel under "Clipping wrappers" and to mention `centre_last_row` in the grid section.
56 lines
1.8 KiB
Makefile
56 lines
1.8 KiB
Makefile
REGISTRY ?= /usr/share/cargo/registry/ltk
|
|
DOCDIR ?= /usr/share/doc/libltk-doc/html
|
|
|
|
# Targets are recipes, not files. Listing them as PHONY tells make to
|
|
# ignore filesystem entries with the same name — without this `examples`
|
|
# silently no-ops because the `examples/` directory exists, and `doc`
|
|
# would do the same once `target/doc` is around.
|
|
.PHONY: all test doctest-md audit doc install examples clean distclean
|
|
|
|
all:
|
|
cargo build --release
|
|
|
|
test:
|
|
cargo test
|
|
|
|
# Typecheck the `no_run` snippets in docs/*.md by feeding each markdown
|
|
# file to `rustdoc --test`. Catches API drift in cookbook + widget
|
|
# reference: drops a renamed builder, removed function, etc. surface
|
|
# here just like `cargo test --doc` does for in-source doctests.
|
|
doctest-md:
|
|
./scripts/doctest-md.sh
|
|
|
|
audit:
|
|
@command -v cargo-audit >/dev/null 2>&1 || cargo install cargo-audit --locked
|
|
cargo audit
|
|
|
|
doc:
|
|
cargo doc --no-deps
|
|
|
|
install: doc
|
|
install -d $(REGISTRY)
|
|
cp -r src Cargo.toml liberux.toml $(REGISTRY)/
|
|
cp debian/cargo-checksum.json $(REGISTRY)/.cargo-checksum.json
|
|
install -d $(DOCDIR)
|
|
cp -r target/doc/* $(DOCDIR)/
|
|
|
|
examples:
|
|
LTK_THEMES_DIR=themes cargo run --release --example showcase
|
|
LTK_THEMES_DIR=themes cargo run --release --example inputs
|
|
LTK_THEMES_DIR=themes cargo run --release --example scroll
|
|
LTK_THEMES_DIR=themes cargo run --release --example sliders
|
|
LTK_THEMES_DIR=themes cargo run --release --example combo
|
|
LTK_THEMES_DIR=themes cargo run --release --example mini_shell
|
|
LTK_THEMES_DIR=themes cargo run --release --example widgets
|
|
LTK_THEMES_DIR=themes cargo run --release --example pickers
|
|
LTK_THEMES_DIR=themes cargo run --release --example dialog
|
|
LTK_THEMES_DIR=themes cargo run --release --example carousel
|
|
|
|
clean:
|
|
dh_clean
|
|
cargo clean
|
|
rm -rf target
|
|
|
|
distclean: clean
|
|
rm -f Cargo.lock
|