ailloli_ui_widgets/layout/
split_pane.rs

1//! Two-child split layout with a draggable, bindable seam.
2
3use std::rc::Rc;
4
5use ailloli_ui_core::event::pointer::{MouseButton, PointerEvent};
6use ailloli_ui_core::event::Event;
7use ailloli_ui_core::geometry::{Constraints, Point, Rect, Size};
8use ailloli_ui_core::style::{FlexItemStyle, LayoutSizeHint, LayoutStyle};
9use ailloli_ui_core::{Offset, Theme};
10use ailloli_ui_runtime::component::{ComponentNode, Context, IntoView, Signal, View, Widget};
11use ailloli_ui_runtime::input::{ActivationPolicy, EventCtx, HoverCursorRole};
12use ailloli_ui_runtime::layout::{ChildLayout, LayoutChild, LayoutCtx, LayoutEngine, LayoutResult};
13use ailloli_ui_runtime::scene::PaintCtx;
14
15use super::layout_ext::{apply_layout_size, finish_view_sized};
16use super::resize_bar::{
17    axis_value, paint_resize_line, ResizeAxis, ResizeBarStyle, ResizeDragPhase, ResizeDragState,
18    SplitResizeEvent,
19};
20
21#[derive(Clone, Copy, Debug, PartialEq)]
22/// Styling for the seam shared with [`super::ResizeBar`].
23///
24/// # Examples
25///
26/// ```
27/// use ailloli_ui_widgets::layout::SplitPaneStyle;
28/// let style = SplitPaneStyle::default();
29/// assert_eq!(style.resize_bar.hit_thickness, 8.0);
30/// ```
31pub struct SplitPaneStyle {
32    /// Seam hit geometry, line geometry, and interaction colors.
33    pub resize_bar: ResizeBarStyle,
34}
35
36/// Derives split-pane styling from [`Theme::default`].
37impl Default for SplitPaneStyle {
38    fn default() -> Self {
39        Self::from_theme(Theme::default())
40    }
41}
42
43impl SplitPaneStyle {
44    /// Derives seam colors from `theme` and standard resize geometry.
45    ///
46    /// # Examples
47    ///
48    /// ```
49    /// use ailloli_ui_core::Theme;
50    /// use ailloli_ui_widgets::layout::SplitPaneStyle;
51    /// assert_eq!(SplitPaneStyle::from_theme(Theme::dark()).resize_bar.line_thickness, 2.0);
52    /// ```
53    pub fn from_theme(theme: Theme) -> Self {
54        Self {
55            resize_bar: ResizeBarStyle::from_theme(theme),
56        }
57    }
58}
59
60/// Shared retained callback invoked for seam drag events.
61type ResizeHandler<A> = Rc<dyn Fn(&mut EventCtx<A>, SplitResizeEvent)>;
62
63#[derive(Clone, Copy, Debug, PartialEq)]
64/// Initial seam distance measured from the start or end edge.
65enum SplitPaneInitialPosition {
66    /// Logical-pixel distance measured from the leading edge.
67    Start(f32),
68    /// Logical-pixel distance measured from the trailing edge.
69    End(f32),
70}
71
72/// Two-child layout split on x or y with a draggable seam.
73///
74/// Columns split on x; rows split on y. The default seam is centered, both
75/// minimum extents are zero, the pane fills both axes, and position is held in
76/// component-local state unless [`Self::bind_position`] supplies a signal.
77///
78/// # Examples
79///
80/// ```
81/// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
82/// let split: SplitPane<()> = SplitPane::columns(Text::new("left"), Text::new("right"));
83/// let _ = split;
84/// ```
85pub struct SplitPane<A = ()> {
86    /// Outer logical sizing policy inherited by the retained view.
87    pub(crate) layout: LayoutStyle,
88    /// Parent-flex participation metadata preserved during conversion.
89    pub(crate) flex_item: FlexItemStyle,
90    /// Physical axis along which the two children are divided.
91    axis: ResizeAxis,
92    /// Child occupying the leading side of the seam.
93    start: View<A>,
94    /// Child occupying the trailing side of the seam.
95    end: View<A>,
96    /// Optional initial seam distance used until retained state exists.
97    initial_position: Option<SplitPaneInitialPosition>,
98    /// Optional caller-owned seam distance in logical pixels from the start.
99    bound_position: Option<Signal<f32>>,
100    /// Minimum logical-pixel extent reserved for the leading child.
101    min_start: f32,
102    /// Minimum logical-pixel extent reserved for the trailing child.
103    min_end: f32,
104    /// Seam hit target and visual style.
105    style: SplitPaneStyle,
106    /// Optional callback receiving start, drag, and end resize events.
107    on_resize: Option<ResizeHandler<A>>,
108}
109
110crate::impl_layout_builders!(SplitPane);
111
112impl<A: 'static> SplitPane<A> {
113    /// Creates left/right panes separated by an x-axis seam.
114    ///
115    /// # Examples
116    ///
117    /// ```
118    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
119    /// let split: SplitPane<()> = SplitPane::columns(Text::new("left"), Text::new("right"));
120    /// let _ = split;
121    /// ```
122    pub fn columns(start: impl IntoView<A>, end: impl IntoView<A>) -> Self {
123        Self::new(ResizeAxis::X, start, end)
124    }
125
126    /// Creates top/bottom panes separated by a y-axis seam.
127    ///
128    /// # Examples
129    ///
130    /// ```
131    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
132    /// let split: SplitPane<()> = SplitPane::rows(Text::new("top"), Text::new("bottom"));
133    /// let _ = split;
134    /// ```
135    pub fn rows(start: impl IntoView<A>, end: impl IntoView<A>) -> Self {
136        Self::new(ResizeAxis::Y, start, end)
137    }
138
139    /// Creates a fill-sized split for an explicit axis and two required children.
140    ///
141    /// # Examples
142    ///
143    /// ```
144    /// use ailloli_ui_widgets::{layout::{ResizeAxis, SplitPane}, text::Text};
145    /// let split: SplitPane<()> = SplitPane::new(ResizeAxis::X, Text::new("a"), Text::new("b"));
146    /// let _ = split;
147    /// ```
148    pub fn new(axis: ResizeAxis, start: impl IntoView<A>, end: impl IntoView<A>) -> Self {
149        Self {
150            layout: LayoutStyle::default().fill(),
151            flex_item: FlexItemStyle::default(),
152            axis,
153            start: start.into_view(),
154            end: end.into_view(),
155            initial_position: None,
156            bound_position: None,
157            min_start: 0.0,
158            min_end: 0.0,
159            style: SplitPaneStyle::default(),
160            on_resize: None,
161        }
162    }
163
164    /// Sets initial seam distance from the start edge in logical pixels.
165    ///
166    /// Negative and `NaN` values become zero. A bound signal takes precedence,
167    /// and the resolved value is clamped by pane minima on layout.
168    ///
169    /// # Examples
170    ///
171    /// ```
172    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
173    /// let split: SplitPane<()> = SplitPane::columns(Text::new("a"), Text::new("b")).initial_position(160.0);
174    /// let _ = split;
175    /// ```
176    pub fn initial_position(mut self, position: f32) -> Self {
177        self.initial_position = Some(SplitPaneInitialPosition::Start(position.max(0.0)));
178        self
179    }
180
181    /// Sets initial end-pane extent in logical pixels.
182    ///
183    /// The seam is resolved as `available - position`, floored at zero, then
184    /// clamped by pane minima. Negative and `NaN` inputs become zero.
185    ///
186    /// # Examples
187    ///
188    /// ```
189    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
190    /// let split: SplitPane<()> = SplitPane::columns(Text::new("a"), Text::new("b")).initial_end_position(240.0);
191    /// let _ = split;
192    /// ```
193    pub fn initial_end_position(mut self, position: f32) -> Self {
194        self.initial_position = Some(SplitPaneInitialPosition::End(position.max(0.0)));
195        self
196    }
197
198    /// Binds seam position, measured from the start edge, to shared state.
199    ///
200    /// Binding has priority over initial and local positions and is updated
201    /// synchronously during drag. Its value is clamped for layout but is not
202    /// rewritten merely because constraints clamp it.
203    ///
204    /// # Examples
205    ///
206    /// ```
207    /// use ailloli_ui_runtime::component::State;
208    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
209    /// let position = State::new(120.0);
210    /// let split: SplitPane<()> = SplitPane::columns(Text::new("a"), Text::new("b")).bind_position(position);
211    /// let _ = split;
212    /// ```
213    pub fn bind_position(mut self, position: impl Into<Signal<f32>>) -> Self {
214        self.bound_position = Some(position.into());
215        self
216    }
217
218    /// Sets the minimum start-pane main extent in logical pixels.
219    ///
220    /// Negative and `NaN` inputs become zero. If both minima cannot fit, the
221    /// start minimum wins and the end pane may collapse to zero.
222    ///
223    /// # Examples
224    ///
225    /// ```
226    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
227    /// let split: SplitPane<()> = SplitPane::columns(Text::new("a"), Text::new("b")).min_start(80.0);
228    /// let _ = split;
229    /// ```
230    pub fn min_start(mut self, value: f32) -> Self {
231        self.min_start = value.max(0.0);
232        self
233    }
234
235    /// Sets the minimum end-pane main extent in logical pixels.
236    ///
237    /// Negative and `NaN` inputs become zero. Impossible combined minima use
238    /// the start-minimum precedence described by [`Self::min_start`].
239    ///
240    /// # Examples
241    ///
242    /// ```
243    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
244    /// let split: SplitPane<()> = SplitPane::columns(Text::new("a"), Text::new("b")).min_end(100.0);
245    /// let _ = split;
246    /// ```
247    pub fn min_end(mut self, value: f32) -> Self {
248        self.min_end = value.max(0.0);
249        self
250    }
251
252    /// Replaces all seam style values.
253    ///
254    /// # Examples
255    ///
256    /// ```
257    /// use ailloli_ui_widgets::{layout::{SplitPane, SplitPaneStyle}, text::Text};
258    /// let style = SplitPaneStyle::default();
259    /// let split: SplitPane<()> = SplitPane::columns(Text::new("a"), Text::new("b")).split_pane_style(style);
260    /// let _ = split;
261    /// ```
262    pub fn split_pane_style(mut self, style: SplitPaneStyle) -> Self {
263        self.style = style;
264        self
265    }
266
267    /// Maps each seam event into an application action.
268    ///
269    /// # Examples
270    ///
271    /// ```
272    /// use ailloli_ui_widgets::{layout::{SplitPane, SplitResizeEvent}, text::Text};
273    /// enum Action { Resize(SplitResizeEvent) }
274    /// let split: SplitPane<Action> = SplitPane::columns(Text::new("a"), Text::new("b")).on_resize(Action::Resize);
275    /// let _ = split;
276    /// ```
277    pub fn on_resize(mut self, f: impl Fn(SplitResizeEvent) -> A + 'static) -> Self {
278        self.on_resize = Some(Rc::new(move |ctx, event| ctx.dispatch(f(event))));
279        self
280    }
281
282    /// Handles seam events with mutable runtime event-context access.
283    ///
284    /// # Examples
285    ///
286    /// ```
287    /// use ailloli_ui_widgets::{layout::SplitPane, text::Text};
288    /// let split: SplitPane<()> = SplitPane::columns(Text::new("a"), Text::new("b")).on_resize_ctx(|_ctx, _event| {});
289    /// let _ = split;
290    /// ```
291    pub fn on_resize_ctx(
292        mut self,
293        f: impl Fn(&mut EventCtx<A>, SplitResizeEvent) + 'static,
294    ) -> Self {
295        self.on_resize = Some(Rc::new(f));
296        self
297    }
298}
299
300/// Retained builder snapshot used to allocate local position/drag state.
301struct SplitPaneComponent<A> {
302    /// Outer logical sizing policy.
303    layout: LayoutStyle,
304    /// Physical split axis.
305    axis: ResizeAxis,
306    /// Leading retained child.
307    start: View<A>,
308    /// Trailing retained child.
309    end: View<A>,
310    /// Initial seam distance before local or bound state takes precedence.
311    initial_position: Option<SplitPaneInitialPosition>,
312    /// Optional caller-owned seam distance.
313    bound_position: Option<Signal<f32>>,
314    /// Minimum leading-child extent in logical pixels.
315    min_start: f32,
316    /// Minimum trailing-child extent in logical pixels.
317    min_end: f32,
318    /// Seam hit target and visual style.
319    style: SplitPaneStyle,
320    /// Optional retained resize callback.
321    on_resize: Option<ResizeHandler<A>>,
322}
323
324/// Builds the split widget with exactly two retained children.
325impl<A: 'static> ComponentNode<A> for SplitPaneComponent<A> {
326    fn build(&self, context: &mut Context<A>) -> View<A> {
327        View::node(
328            SplitPaneWidget {
329                layout: self.layout,
330                axis: self.axis,
331                initial_position: self.initial_position,
332                bound_position: self.bound_position.clone(),
333                local_position: context.signal(None),
334                min_start: self.min_start,
335                min_end: self.min_end,
336                style: self.style,
337                on_resize: self.on_resize.clone(),
338                drag: context.signal(None),
339                hover_seam: context.signal(false),
340            },
341            vec![self.start.clone(), self.end.clone()],
342        )
343    }
344}
345
346#[derive(Debug, Clone, Copy, PartialEq)]
347/// Captured pointer and seam positions for incremental drag events.
348struct SplitPaneDragState {
349    /// Pointer start/current samples shared with standalone resize bars.
350    pointer: ResizeDragState,
351    /// Seam distance in logical pixels captured at press time.
352    start_position: f32,
353    /// Most recently emitted clamped seam distance.
354    last_position: f32,
355}
356
357/// Retained layout, seam-state, hover, and drag implementation.
358struct SplitPaneWidget<A> {
359    /// Outer logical sizing policy.
360    layout: LayoutStyle,
361    /// Physical split axis.
362    axis: ResizeAxis,
363    /// Initial seam distance before retained state takes precedence.
364    initial_position: Option<SplitPaneInitialPosition>,
365    /// Optional caller-owned seam distance.
366    bound_position: Option<Signal<f32>>,
367    /// Uncontrolled retained seam distance, absent before first write.
368    local_position: Signal<Option<f32>>,
369    /// Minimum leading-child extent in logical pixels.
370    min_start: f32,
371    /// Minimum trailing-child extent in logical pixels.
372    min_end: f32,
373    /// Seam hit target and visual style.
374    style: SplitPaneStyle,
375    /// Optional retained resize callback.
376    on_resize: Option<ResizeHandler<A>>,
377    /// Active pointer drag state, or `None` outside a captured gesture.
378    drag: Signal<Option<SplitPaneDragState>>,
379    /// Whether the pointer currently intersects the seam hit target.
380    hover_seam: Signal<bool>,
381}
382
383/// Implements tight two-pane layout and seam pointer capture/painting.
384impl<A: 'static> Widget<A> for SplitPaneWidget<A> {
385    fn debug_name(&self) -> &'static str {
386        "SplitPane"
387    }
388
389    fn layout(
390        &self,
391        engine: &mut LayoutEngine<'_, A>,
392        ctx: &mut LayoutCtx<'_>,
393        children: &mut [LayoutChild],
394        constraints: Constraints,
395    ) -> LayoutResult {
396        let fallback = constraints.max_size();
397        let intrinsic = Size::new(fallback.w.max(0.0), fallback.h.max(0.0));
398        let size = apply_layout_size(intrinsic, self.layout, constraints);
399        let available = main_extent(self.axis, size);
400        let position = self.current_position(available);
401
402        let start_size = size_with_main(self.axis, size, position);
403        let end_size = size_with_main(self.axis, size, (available - position).max(0.0));
404        let mut child_layouts = Vec::with_capacity(children.len());
405
406        if let Some(child) = children.get_mut(0) {
407            let _ = child.layout(engine, ctx, Constraints::tight(start_size.w, start_size.h));
408            let bounds = Rect::new(0.0, 0.0, start_size.w, start_size.h);
409            child_layouts.push(ChildLayout {
410                offset: Offset::new(0.0, 0.0),
411                size: start_size,
412                paint_bounds: bounds,
413                visual_bounds: bounds,
414            });
415        }
416        if let Some(child) = children.get_mut(1) {
417            let offset = match self.axis {
418                ResizeAxis::X => Offset::new(position, 0.0),
419                ResizeAxis::Y => Offset::new(0.0, position),
420            };
421            let _ = child.layout(engine, ctx, Constraints::tight(end_size.w, end_size.h));
422            let bounds = Rect::new(offset.x, offset.y, end_size.w, end_size.h);
423            child_layouts.push(ChildLayout {
424                offset,
425                size: end_size,
426                paint_bounds: bounds,
427                visual_bounds: bounds,
428            });
429        }
430
431        let paint_bounds = Rect::new(0.0, 0.0, size.w, size.h);
432        LayoutResult {
433            size,
434            children: child_layouts,
435            paint_bounds,
436            visual_bounds: paint_bounds,
437            overlay_hit_bounds: vec![self.seam_rect_for(size, position)],
438            clip: None,
439            is_window_root_clip: false,
440            artifact: None,
441        }
442    }
443
444    fn paint(&self, _ctx: &mut PaintCtx<'_>, _bounds: Rect, _layout: &LayoutResult) {}
445
446    fn paint_overlay(&self, ctx: &mut PaintCtx<'_>, bounds: Rect, layout: &LayoutResult) {
447        let dragging = self.drag.read().is_some();
448        let color = if dragging {
449            self.style.resize_bar.active_color
450        } else if self.hover_seam.read() {
451            self.style.resize_bar.hover_color
452        } else {
453            self.style.resize_bar.idle_color
454        };
455        paint_resize_line(
456            ctx,
457            self.seam_rect_abs(bounds, layout),
458            self.axis,
459            &self.style.resize_bar,
460            color,
461        );
462    }
463
464    fn event(&self, ctx: &mut EventCtx<A>, event: &Event, bounds: Rect, layout: &LayoutResult) {
465        match event {
466            Event::Pointer(PointerEvent::Moved { pos, .. }) => {
467                let seam_hover = self.seam_rect_abs(bounds, layout).contains(pos.x, pos.y);
468                if self.hover_seam.read() != seam_hover {
469                    self.hover_seam.set(seam_hover);
470                    ctx.request_repaint();
471                }
472                if let Some(drag) = self.drag.read() {
473                    let available = main_extent(self.axis, layout.size);
474                    let next = self.clamp_position(
475                        available,
476                        drag.start_position + axis_value(self.axis, *pos)
477                            - axis_value(self.axis, drag.pointer.start),
478                    );
479                    self.set_position(next);
480                    self.emit(
481                        ctx,
482                        ResizeDragPhase::Drag,
483                        next,
484                        next - drag.last_position,
485                        next - drag.start_position,
486                    );
487                    self.drag.set(Some(SplitPaneDragState {
488                        pointer: ResizeDragState {
489                            start: drag.pointer.start,
490                            last: *pos,
491                        },
492                        start_position: drag.start_position,
493                        last_position: next,
494                    }));
495                    ctx.request_repaint();
496                    ctx.stop_propagation();
497                }
498            }
499            Event::Pointer(PointerEvent::Button {
500                pos,
501                button: MouseButton::Left,
502                pressed: true,
503                ..
504            }) if self.seam_rect_abs(bounds, layout).contains(pos.x, pos.y) => {
505                let available = main_extent(self.axis, layout.size);
506                let position = self.current_position(available);
507                self.drag.set(Some(SplitPaneDragState {
508                    pointer: ResizeDragState {
509                        start: *pos,
510                        last: *pos,
511                    },
512                    start_position: position,
513                    last_position: position,
514                }));
515                self.hover_seam.set(true);
516                self.emit(ctx, ResizeDragPhase::Start, position, 0.0, 0.0);
517                ctx.request_repaint();
518                ctx.stop_propagation();
519            }
520            Event::Pointer(PointerEvent::Button {
521                pos,
522                button: MouseButton::Left,
523                pressed: false,
524                ..
525            }) => {
526                if let Some(drag) = self.drag.read() {
527                    let available = main_extent(self.axis, layout.size);
528                    let next = self.clamp_position(
529                        available,
530                        drag.start_position + axis_value(self.axis, *pos)
531                            - axis_value(self.axis, drag.pointer.start),
532                    );
533                    self.set_position(next);
534                    self.emit(
535                        ctx,
536                        ResizeDragPhase::End,
537                        next,
538                        next - drag.last_position,
539                        next - drag.start_position,
540                    );
541                    self.drag.set(None);
542                    self.hover_seam
543                        .set(self.seam_rect_abs(bounds, layout).contains(pos.x, pos.y));
544                    ctx.request_repaint();
545                    ctx.stop_propagation();
546                }
547            }
548            Event::Pointer(PointerEvent::Cancelled { .. }) if self.drag.read().is_some() => {
549                self.drag.set(None);
550                self.hover_seam.set(false);
551                ctx.request_repaint();
552                ctx.stop_propagation();
553            }
554            _ => {}
555        }
556    }
557
558    fn activation_policy(&self) -> ActivationPolicy {
559        ActivationPolicy::AllowOnFocusOnly
560    }
561
562    fn hover_cursor_role_at(
563        &self,
564        bounds: Rect,
565        layout: &LayoutResult,
566        pos: Point,
567    ) -> HoverCursorRole {
568        if self.drag.read().is_some() || self.seam_rect_abs(bounds, layout).contains(pos.x, pos.y) {
569            self.axis.cursor_role()
570        } else {
571            HoverCursorRole::Inherit
572        }
573    }
574}
575
576/// Position priority/clamping, state writes, event dispatch, and seam geometry.
577impl<A: 'static> SplitPaneWidget<A> {
578    /// Resolves bound, local, initial, or centered position and clamps it.
579    fn current_position(&self, available: f32) -> f32 {
580        let raw = self
581            .bound_position
582            .as_ref()
583            .map(Signal::read)
584            .or_else(|| self.local_position.read())
585            .or_else(|| {
586                self.initial_position.map(|position| match position {
587                    SplitPaneInitialPosition::Start(value) => value,
588                    SplitPaneInitialPosition::End(value) => (available - value).max(0.0),
589                })
590            })
591            .unwrap_or(available * 0.5);
592        self.clamp_position(available, raw)
593    }
594
595    /// Clamps the seam so both configured minimum extents remain satisfied.
596    fn clamp_position(&self, available: f32, position: f32) -> f32 {
597        let max = (available - self.min_end).max(self.min_start);
598        position.clamp(self.min_start.min(max), max)
599    }
600
601    /// Writes a changed position to controlled or local retained state.
602    fn set_position(&self, position: f32) {
603        if let Some(bound) = &self.bound_position {
604            if (bound.read() - position).abs() > f32::EPSILON {
605                bound.set(position);
606            }
607        } else if self
608            .local_position
609            .read()
610            .is_none_or(|value| (value - position).abs() > f32::EPSILON)
611        {
612            self.local_position.set(Some(position));
613        }
614    }
615
616    /// Emits one resize phase with incremental and press-relative deltas.
617    fn emit(
618        &self,
619        ctx: &mut EventCtx<A>,
620        phase: ResizeDragPhase,
621        position: f32,
622        delta: f32,
623        total_delta: f32,
624    ) {
625        if let Some(on_resize) = &self.on_resize {
626            on_resize(
627                ctx,
628                SplitResizeEvent {
629                    axis: self.axis,
630                    phase,
631                    position,
632                    delta,
633                    total_delta,
634                },
635            );
636        }
637    }
638
639    /// Computes the origin-local seam hit rectangle for a laid-out size.
640    fn seam_rect_for(&self, size: Size, position: f32) -> Rect {
641        let half = self.style.resize_bar.hit_thickness * 0.5;
642        match self.axis {
643            ResizeAxis::X => Rect::new(
644                position - half,
645                0.0,
646                self.style.resize_bar.hit_thickness,
647                size.h,
648            ),
649            ResizeAxis::Y => Rect::new(
650                0.0,
651                position - half,
652                size.w,
653                self.style.resize_bar.hit_thickness,
654            ),
655        }
656    }
657
658    /// Computes the seam hit rectangle in logical window coordinates.
659    fn seam_rect_abs(&self, bounds: Rect, layout: &LayoutResult) -> Rect {
660        let available = main_extent(self.axis, layout.size);
661        self.seam_rect_for(layout.size, self.current_position(available))
662            .translate(Offset::new(bounds.x, bounds.y))
663    }
664}
665
666/// Converts the builder into a retained component and preserves flex metadata.
667impl<A: 'static> IntoView<A> for SplitPane<A> {
668    fn into_view(self) -> View<A> {
669        finish_view_sized(
670            View::component(SplitPaneComponent {
671                layout: self.layout,
672                axis: self.axis,
673                start: self.start,
674                end: self.end,
675                initial_position: self.initial_position,
676                bound_position: self.bound_position,
677                min_start: self.min_start,
678                min_end: self.min_end,
679                style: self.style,
680                on_resize: self.on_resize,
681            }),
682            self.flex_item,
683            LayoutSizeHint::from_layout(self.layout),
684        )
685    }
686}
687
688/// Selects width for x-axis splits or height for y-axis splits.
689fn main_extent(axis: ResizeAxis, size: Size) -> f32 {
690    match axis {
691        ResizeAxis::X => size.w,
692        ResizeAxis::Y => size.h,
693    }
694}
695
696/// Replaces the selected main extent, flooring it at zero.
697fn size_with_main(axis: ResizeAxis, container: Size, main: f32) -> Size {
698    match axis {
699        ResizeAxis::X => Size::new(main.max(0.0), container.h),
700        ResizeAxis::Y => Size::new(container.w, main.max(0.0)),
701    }
702}