Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function similar to ZStack in SwiftUI #342

Open
dullbananas opened this issue Apr 17, 2022 · 1 comment
Open

Add a function similar to ZStack in SwiftUI #342

dullbananas opened this issue Apr 17, 2022 · 1 comment
Labels
has-ellie This is a bug and has an ellie which demonstrates it.

Comments

@dullbananas
Copy link

It would be like row or column except it puts each element on top of the previous one

@NduatiK
Copy link

NduatiK commented Apr 25, 2022

Assuming you want a solution and don't care if its the library that does it.

You can pull this off using the inFront attribute. Ellie

zStack attrs children =
    case children of
        [] ->
            none
        bottomMost :: otherChildren ->
            el 
                (inFront (zStack attr otherChildren) :: attr)        
                bottomMost 

then

module Main exposing (..)

import Element exposing (Element, alignRight, centerY, el, fill, fillPortion, height, padding, px, rgb, rgb255, rgba, row, spacing, text, width)
import Element.Background as Background
import Element.Border as Border
import Element.Font as Font
import Element.Input as Input


type Msg
    = Noop Float


main =
    Element.layout [] content


content =
    zStack [width fill]
    [ text "Bottom"
    , el [Element.moveDown 10] ( text "Middle" )
    , el [Element.moveDown 20] (text "Top")
    ] 

zStack attrs children =
    case children of
        [] ->
            Element.none
        bottomMost :: otherChildren ->
            el 
                (Element.inFront (zStack attrs otherChildren) :: attrs)        
                bottomMost 

@github-actions github-actions bot added the has-ellie This is a bug and has an ellie which demonstrates it. label Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-ellie This is a bug and has an ellie which demonstrates it.
Projects
None yet
Development

No branches or pull requests

2 participants