mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
A panel or group floated out of the dock opens at its docked width and at the height its group measures at in a floating window's room, at most size.float.height. Content that fills its body opens at that height. - Proposal::Size measures a component as it is shown at a rect of that size, with no share of the parent body's room. - drag::amend lets a host change a drag's payload in the frame the drag started. The dock area measures the dragged panel there and puts the size on PanelDrag::source / GroupDrag::source. The Float command and a tab torn out of the window measure where they run. - DockGroupOutput::drag_started also reports tab drags. - FloatSpace::size_of caps a panel's, group's or column's height at the default float height. FloatSpace::record and its contents are gone.
110 lines
3.6 KiB
Rust
110 lines
3.6 KiB
Rust
//! `Proposal`, `Metrics` and `ControlMetrics`: what a measure call is asked and what a style gives it to add.
|
|
|
|
use crate::flow::Insets;
|
|
use craft_theme::{BySize, ControlSize};
|
|
use emath::Vec2;
|
|
|
|
/// The question one measure call answers.
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub enum Proposal {
|
|
/// The size the content wants, unwrapped.
|
|
Ideal,
|
|
/// The smallest size the content can take.
|
|
Min,
|
|
/// The height at this width.
|
|
Width(f32),
|
|
/// The size in a room this wide and tall, as the component takes it shown at a rect of that size: it takes no share
|
|
/// of the room of the body it is measured in. A container's content that fills the room takes it; other content
|
|
/// its own size.
|
|
Size(Vec2),
|
|
}
|
|
|
|
/// What the pipeline adds around a component's measured content.
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub struct Metrics {
|
|
/// Space between the component's edge and its content.
|
|
pub padding: Insets,
|
|
/// The least size of the component.
|
|
pub min_size: Vec2,
|
|
/// The wrap width of text.
|
|
pub max_width: Option<f32>,
|
|
/// Space between content parts.
|
|
pub gap: f32,
|
|
/// The least text width before eliding.
|
|
pub min_text: f32,
|
|
/// The width the component takes where its room allows, though its content needs less: its ideal measure is at
|
|
/// least this wide, up to the room it is offered, and its least measure is its content's.
|
|
pub ideal_width: f32,
|
|
}
|
|
|
|
impl Metrics {
|
|
/// No padding, no minimum, no wrap width.
|
|
pub const fn new() -> Self {
|
|
Metrics { padding: Insets::new(0.0, 0.0, 0.0, 0.0), min_size: Vec2::ZERO, max_width: None, gap: 0.0, min_text: 0.0, ideal_width: 0.0 }
|
|
}
|
|
|
|
/// Sets the padding.
|
|
pub const fn padding(mut self, padding: Insets) -> Self {
|
|
self.padding = padding;
|
|
self
|
|
}
|
|
|
|
/// Sets the least size.
|
|
pub const fn min_size(mut self, min_size: Vec2) -> Self {
|
|
self.min_size = min_size;
|
|
self
|
|
}
|
|
|
|
/// Sets the wrap width.
|
|
pub const fn max_width(mut self, width: f32) -> Self {
|
|
self.max_width = Some(width);
|
|
self
|
|
}
|
|
|
|
/// Sets the gap between content parts.
|
|
pub const fn gap(mut self, gap: f32) -> Self {
|
|
self.gap = gap;
|
|
self
|
|
}
|
|
|
|
/// Sets the least text width.
|
|
pub const fn min_text(mut self, width: f32) -> Self {
|
|
self.min_text = width;
|
|
self
|
|
}
|
|
|
|
/// Sets the width the component takes where its room allows.
|
|
pub const fn ideal_width(mut self, width: f32) -> Self {
|
|
self.ideal_width = width;
|
|
self
|
|
}
|
|
}
|
|
|
|
/// The sizes a control takes from its `ControlSize`: height, icon side, horizontal padding and gap.
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
|
#[non_exhaustive]
|
|
pub struct ControlMetrics {
|
|
/// The control's height.
|
|
pub height: f32,
|
|
/// The side of an icon inside the control.
|
|
pub icon: f32,
|
|
/// The padding at the start and the end.
|
|
pub pad_x: f32,
|
|
/// The gap between content parts.
|
|
pub gap: f32,
|
|
}
|
|
|
|
impl ControlMetrics {
|
|
/// The entries of the four tables at `size`.
|
|
pub fn at(size: ControlSize, height: &BySize<f32>, icon: &BySize<f32>, pad_x: &BySize<f32>, gap: &BySize<f32>) -> Self {
|
|
ControlMetrics { height: height.get(size), icon: icon.get(size), pad_x: pad_x.get(size), gap: gap.get(size) }
|
|
}
|
|
|
|
/// The `Metrics` of a control of this height: horizontal padding, the height as the least height, the gap.
|
|
pub const fn metrics(&self) -> Metrics {
|
|
Metrics::new().padding(Insets::horizontal(self.pad_x)).min_size(Vec2::new(0.0, self.height)).gap(self.gap)
|
|
}
|
|
}
|