`UiScalar` was `Len` without the `leftover` weight, which is the separation canonical `main` already had as `Len` beside `LayoutLen` and this branch collapsed. It is needed back for the queued clamp: a cap may not contain a share, because a cap has to read the report a rule otherwise makes moot, and a share puts the container's division into the same equation -- two self-consistent assignments, which is the multiple-fixed-point failure generated seed 13 punished for orthogonal sizing. `min(report, cap)` is not a `LayoutLen` either: it is a sum of parts, and the smaller of two of them is not one. So `UiScalar` is `Len`, what was `Len` is `LayoutLen`, and the two say in their docs which is which: a `Len` is pixels plus a fraction of a box -- a position being the length from the box's start, which is why a span is two of them -- and a `LayoutLen` is a `Len` plus a claim only a container dividing its room can answer. `From<Len> for LayoutLen` is the one-way step between them. Names only; the shader's `UiScalar` is renamed with them. Checked: fmt, clippy, 105 tests, and `tabs`, `minimal`, `view`, `text` and `random` byte-identical at 1920x1200. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
84 lines
2.1 KiB
Rust
84 lines
2.1 KiB
Rust
use crate::{Axis, LayoutLen, Painter, Size};
|
|
use std::any::Any;
|
|
|
|
mod data;
|
|
mod handle;
|
|
mod like;
|
|
mod size_rule;
|
|
mod tag;
|
|
mod view;
|
|
mod widgets;
|
|
|
|
pub use data::*;
|
|
pub use handle::*;
|
|
pub use like::*;
|
|
pub use size_rule::*;
|
|
pub use tag::*;
|
|
pub use view::*;
|
|
pub use widgets::*;
|
|
|
|
pub trait Widget: Any {
|
|
/// Draws the widget, and returns what it used of the box it was given.
|
|
fn draw(&mut self, painter: &mut Painter) -> Size;
|
|
|
|
/// An exact length the widget can give without a painter or its children.
|
|
/// Optional, and saves a draw rather than changing one: a hint that
|
|
/// disagrees with the eventual draw fails a debug assertion.
|
|
fn size_hint(&self, _axis: Axis) -> Option<LayoutLen> {
|
|
None
|
|
}
|
|
}
|
|
|
|
impl Widget for () {
|
|
/// A gap: nothing drawn, at the default length, so a span gives it a share.
|
|
fn draw(&mut self, _: &mut Painter) -> Size {
|
|
Size::default()
|
|
}
|
|
|
|
fn size_hint(&self, _axis: Axis) -> Option<LayoutLen> {
|
|
Some(LayoutLen::default())
|
|
}
|
|
}
|
|
|
|
impl dyn Widget {
|
|
pub fn as_any(&self) -> &dyn Any {
|
|
self
|
|
}
|
|
|
|
pub fn as_any_mut(&mut self) -> &mut dyn Any {
|
|
self
|
|
}
|
|
}
|
|
|
|
/// A function that returns a widget given a UI.
|
|
/// Useful for defining trait functions on widgets that create a parent widget so that the children
|
|
/// don't need to be IDs yet
|
|
pub trait WidgetFn<State, W: Widget + ?Sized>: FnOnce(&mut State) -> W {}
|
|
impl<State, W: Widget + ?Sized, F: FnOnce(&mut State) -> W> WidgetFn<State, W> for F {}
|
|
|
|
pub struct WidgetArr<const LEN: usize> {
|
|
pub arr: [StrongWidget; LEN],
|
|
}
|
|
|
|
impl<const LEN: usize> WidgetArr<LEN> {
|
|
pub fn new(arr: [StrongWidget; LEN]) -> Self {
|
|
Self { arr }
|
|
}
|
|
}
|
|
|
|
pub trait WidgetOption<State> {
|
|
fn get(self, state: &mut State) -> Option<StrongWidget>;
|
|
}
|
|
|
|
impl<State> WidgetOption<State> for () {
|
|
fn get(self, _: &mut State) -> Option<StrongWidget> {
|
|
None
|
|
}
|
|
}
|
|
|
|
impl<State, F: FnOnce(&mut State) -> Option<StrongWidget>> WidgetOption<State> for F {
|
|
fn get(self, state: &mut State) -> Option<StrongWidget> {
|
|
self(state)
|
|
}
|
|
}
|