Moar dockumentashun
parent
b24b7f81d1
commit
844d406763
|
@ -7,4 +7,3 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
crossterm = "0.22.1"
|
||||
futures = "*"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{rect::Rect, size::Size, vec2::Vec2, Data, Point, box_constraints::BoxConstraints};
|
||||
use crate::{box_constraints::BoxConstraints, rect::Rect, size::Size, vec2::Vec2, Data, Point};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum Axis {
|
||||
|
@ -79,7 +79,7 @@ impl Axis {
|
|||
}
|
||||
|
||||
/// Generate constraints with new values on the major axis.
|
||||
pub(crate) fn constraints(
|
||||
pub(super) fn constraints(
|
||||
self,
|
||||
bc: &BoxConstraints,
|
||||
min_major: usize,
|
||||
|
|
|
@ -319,9 +319,11 @@ impl<T: Data> Widget<T> for Flex<T> {
|
|||
widget,
|
||||
alignment: _,
|
||||
} => {
|
||||
// Get size of child (unbounded on major axis)
|
||||
let child_bc = self.direction.constraints(&loosened_bc, 0, usize::MAX);
|
||||
let child_size = widget.layout(&child_bc);
|
||||
|
||||
// Increment measurements
|
||||
major_non_flex += self.direction.major(child_size);
|
||||
minor = minor.max(self.direction.minor(child_size));
|
||||
}
|
||||
|
@ -332,9 +334,10 @@ impl<T: Data> Widget<T> for Flex<T> {
|
|||
Child::Flex { flex, .. } | Child::FlexedSpacer(flex, _) => flex_sum += *flex,
|
||||
}
|
||||
}
|
||||
|
||||
// Get the amount of space on the major axis
|
||||
let total_major = self.direction.major(bc.max());
|
||||
let remaining = (total_major - major_non_flex).max(0);
|
||||
// Calculate the amount of space left on major axis (total - total-non-flex)
|
||||
let remaining = total_major.saturating_sub(major_non_flex);
|
||||
let mut remainder = 0.0;
|
||||
|
||||
let mut major_flex = 0.0;
|
||||
|
@ -343,19 +346,25 @@ impl<T: Data> Widget<T> for Flex<T> {
|
|||
for child in &mut self.children {
|
||||
match child {
|
||||
Child::Flex { widget, flex, .. } => {
|
||||
// This thing's flex represents a multiple of the number of chars per flex
|
||||
let desired_major = (*flex) * chars_per_flex + remainder;
|
||||
// Convert messy measurement to neat measurement
|
||||
let actual_major = desired_major.round();
|
||||
// Take difference of messy - neat and save it for next time
|
||||
remainder = desired_major - actual_major;
|
||||
|
||||
// Get size of child (unbounded on major axis)
|
||||
let child_bc = self
|
||||
.direction
|
||||
.constraints(&loosened_bc, 0, actual_major as usize);
|
||||
// WidgetPods (which this child should be) cache their size.
|
||||
let child_size = widget.layout(&child_bc);
|
||||
|
||||
// Increment measurements
|
||||
major_flex += self.direction.major(child_size) as f64;
|
||||
minor = minor.max(self.direction.minor(child_size));
|
||||
}
|
||||
Child::FlexedSpacer(flex, calculated_size) => {
|
||||
// Do the same calculation as above (ie, decrement the amount of space left and increment the measurement)
|
||||
let desired_major = (*flex) * chars_per_flex + remainder;
|
||||
*calculated_size = desired_major.round();
|
||||
remainder = desired_major - *calculated_size;
|
||||
|
@ -367,7 +376,7 @@ impl<T: Data> Widget<T> for Flex<T> {
|
|||
|
||||
// figure out if we have extra space on major axis, and if so how to use it
|
||||
let extra = if self.fill_major_axis {
|
||||
(remaining - major_flex as usize).max(0)
|
||||
remaining.saturating_sub(major_flex as usize)
|
||||
} else {
|
||||
// if we are *not* expected to fill our available space this usually
|
||||
// means we don't have any extra, unless dictated by our constraints.
|
||||
|
@ -383,8 +392,6 @@ impl<T: Data> Widget<T> for Flex<T> {
|
|||
// Unlike the 'minor' var, this ignores the incoming constraints.
|
||||
let minor_dim = minor;
|
||||
|
||||
let _extra_height = minor - minor_dim.min(minor);
|
||||
|
||||
let mut major = spacing.next().unwrap_or(0);
|
||||
let mut child_paint_rect = Rect::ZERO;
|
||||
|
||||
|
@ -394,6 +401,7 @@ impl<T: Data> Widget<T> for Flex<T> {
|
|||
| Child::Flex {
|
||||
widget, alignment, ..
|
||||
} => {
|
||||
// Get the child's origin, origin + size rectangle
|
||||
let child_size = widget.layout_rect().size();
|
||||
let alignment = alignment.unwrap_or(self.cross_alignment);
|
||||
let child_minor_offset = match alignment {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{box_constraints::BoxConstraints, Data, DataWrapper, Point, Size, Widget, Event};
|
||||
use crate::{box_constraints::BoxConstraints, Data, DataWrapper, Event, Point, Size, Widget};
|
||||
|
||||
pub struct Text<T: Data> {
|
||||
text: Box<dyn Fn(&DataWrapper<T>) -> String>,
|
||||
|
@ -48,6 +48,9 @@ impl<T: Data> Widget<T> for Text<T> {
|
|||
) {
|
||||
if ch == '\n' {
|
||||
break;
|
||||
} else if ch == '\t' {
|
||||
// TODO: Figure out a way to handle this.
|
||||
*spot = ch;
|
||||
} else {
|
||||
*spot = ch;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ impl<T: Data, W: Widget<T>> Widget<T> for WidgetPod<T, W> {
|
|||
new_size
|
||||
}
|
||||
|
||||
fn paint(&mut self, buf: &mut [char], origin: Point, size: &Size) {
|
||||
self.inner.paint(buf, origin + self.origin, size)
|
||||
fn paint(&mut self, buf: &mut [char], origin: Point, _: &Size) {
|
||||
self.inner.paint(buf, origin + self.origin, &self.size)
|
||||
}
|
||||
fn event(&mut self, data: &mut DataWrapper<T>, event: &Event) {
|
||||
self.inner.event(data, event)
|
||||
|
|
Loading…
Reference in New Issue