Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@altsem
Copy link
Owner

@altsem altsem commented Sep 29, 2025

This is another attempt at introducing a ui that is more easy to work with.
It is now composable via functions, and simplifies the UI code to just:

    layout.clear();

    layout.stacked(OPTS, |layout| {
        screen::layout_screen(
            layout,
            frame.area().as_size(),
            state.screens.last().unwrap(),
        );

        layout.vertical(OPTS.align_end(), |layout| {
            menu::layout_menu(layout, state);
            layout_command_log(layout, state);
            layout_prompt(layout, state);
        });
    });

    layout.compute([frame.area().width, frame.area().height]);

    for span in layout.iter() {
        let area = Rect {
            x: span.pos[0],
            y: span.pos[1],
            width: span.size[0],
            height: span.size[1],
        };

        frame.render_widget(span.data, area);
    }
  • The styling, particularly in the screen-module needs fixing.
    - [ ] Spans do wrap to new lines, breaking the editor (it assumes 1 item = 1 line)
    - [ ] Spans are truncated if too long, we should word/char-wrap instead. Perhaps feeding every single char to "layout" could work.
  • There's a lot of allocations going on, one way to amend this could be to look at removing the 'static lifetime from app.layout_tree. Since it is only used once per frame and cleared after.
  • The tui_prompt dependency should be easier to get rid of now. Eventually, we may get rid of Ratatui as well.

@altsem altsem force-pushed the refactor/ui branch 2 times, most recently from 9b67dae to 61e6c1b Compare October 28, 2025 00:08
@altsem altsem changed the title refactor: new LayoutTree module to improve on ui headaches refactor: add a custom ui layout module to enable future text-wrap/composed ui Nov 9, 2025
@altsem altsem requested a review from Copilot November 9, 2025 12:04
@altsem altsem marked this pull request as ready for review November 9, 2025 12:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the UI rendering system by introducing a new layout tree module that replaces the previous widget-based approach. The changes include:

  • A new custom layout system with flex-box-like capabilities for managing UI element positioning and sizing
  • Conversion from ratatui's table widgets to a custom span-based rendering approach
  • Updates to lifetime annotations for better memory management

Reviewed Changes

Copilot reviewed 208 out of 208 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/ui/layout/mod.rs New layout tree implementation with flexbox-style layout capabilities
src/ui/layout/node.rs Node structure with layout options (fit/flex sizing, gap, direction)
src/ui/layout/vec2.rs 2D vector operations for layout calculations
src/ui/layout/direction.rs Direction enum for horizontal/vertical layouts
src/ui.rs Refactored to use new layout system with span-based rendering
src/ui/menu.rs Converted from table widget to layout tree approach
src/screen/mod.rs Refactored rendering to use new layout system with improved line handling
src/items.rs Updated to clone data and return owned strings for compatibility with new layout system
src/app.rs Minor formatting change (added blank line)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This is another attempt at introducing a ui that is more easy to work
with.

It is now composable via functions, and simplifies the UI code to just:
```rust
    layout.clear();

    layout.stacked(OPTS, |layout| {
        screen::layout_screen(
            layout,
            frame.area().as_size(),
            state.screens.last().unwrap(),
        );

        layout.vertical(OPTS.align_end(), |layout| {
            menu::layout_menu(layout, state);
            layout_command_log(layout, state);
            layout_prompt(layout, state);
        });
    });

    layout.compute([frame.area().width, frame.area().height]);

    for span in layout.iter() {
        let area = Rect {
            x: span.pos[0],
            y: span.pos[1],
            width: span.size[0],
            height: span.size[1],
        };

        frame.render_widget(span.data, area);
    }
```

- Implementing wrapping of text is now closer.
- The tui_prompt dependency should be easier to get rid of now.
@altsem altsem merged commit d23b90f into master Nov 9, 2025
2 of 3 checks passed
@altsem altsem deleted the refactor/ui branch November 9, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants