intuitive icon indicating copy to clipboard operation
intuitive copied to clipboard

constrain size (or ratio) of Section

Open onlycs opened this issue 2 years ago • 4 comments

basically required for displaying a grid

onlycs avatar Jan 09 '23 20:01 onlycs

So I'm in middle of a major rewrite because of this issue: https://github.com/enricozb/intuitive/issues/4, but I'm curious why VStack or HStack wouldn't work here?

enricozb avatar Jan 09 '23 23:01 enricozb

how so? I need a section with a locked 1:1 ratio of width:height for a chess-tui game (the board section) I am finding this quite hard to work on, as flex[] constraints for HStack and VStack are relative to the screen size.

image

onlycs avatar Jan 10 '23 02:01 onlycs

Ah I see. Okay I'll keep this in mind as I'm designing the components. This is a good use case for fixed size components. Like I mentioned earlier, I'm going through a substantial rewrite, it will take some time before I have an update here.

enricozb avatar Jan 10 '23 03:01 enricozb

    let w = size.0;
    let h = size.1;

    let mut board_w = 50;
    let mut board_h = 26;

    while board_w + 50 <= w && board_h + 26 <= h {
        board_w += 50;
        board_h += 26;
    }

    (board_w, w - board_w, board_h, h - board_h) as (u16, u16, u16, u16)

the board section is constrained to a multiple of 50x26 image

onlycs avatar Jan 10 '23 21:01 onlycs