Skip to content

Commit

Permalink
fix block
Browse files Browse the repository at this point in the history
  • Loading branch information
maxence-charriere committed Jun 28, 2021
1 parent bcb4ac4 commit fa270f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
2 changes: 2 additions & 0 deletions pkg/ui/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func (b *block) OnUpdate(ctx app.Context) {

func (b *block) Render() app.UI {
layout := Stack().
Style("width", "100%").
Style("height", "100%").
Center().
Content(
app.Div().
Expand Down
48 changes: 34 additions & 14 deletions pkg/ui/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type IStack interface {
// Sets the class. Multiple classes can be defined by successive calls.
Class(v string) IStack

// Sets the style. Multiple styles can be defined by successive calls.
Style(k, v string) IStack

// Left aligns the content on the left.
Left() IStack

Expand Down Expand Up @@ -53,6 +56,7 @@ type stack struct {
Iclass string
IhorizontalAlign string
IverticalAlign string
Istyles []style
Icontent []app.UI
}

Expand All @@ -61,6 +65,28 @@ func (s *stack) ID(v string) IStack {
return s
}

func (s *stack) Class(v string) IStack {
if v == "" {
return s
}
if s.Iclass != "" {
s.Iclass += " "
}
s.Iclass += v
return s
}

func (s *stack) Style(k, v string) IStack {
if v == "" {
return s
}
s.Istyles = append(s.Istyles, style{
key: k,
value: v,
})
return s
}

func (s *stack) Left() IStack {
s.IhorizontalAlign = "flex-start"
return s
Expand Down Expand Up @@ -96,17 +122,6 @@ func (s *stack) Stretch() IStack {
return s
}

func (s *stack) Class(v string) IStack {
if v == "" {
return s
}
if s.Iclass != "" {
s.Iclass += " "
}
s.Iclass += v
return s
}

func (s *stack) Content(elems ...app.UI) IStack {
s.Icontent = app.FilterUIElems(elems...)
return s
Expand All @@ -116,12 +131,17 @@ func (s *stack) OnUpdate(ctx app.Context) {
}

func (s *stack) Render() app.UI {
return app.Div().
body := app.Div().
DataSet("goapp", "Stack").
ID(s.Iid).
Class(s.Iclass).
Style("display", "flex").
Style("justify-content", s.IhorizontalAlign).
Style("align-items", s.IverticalAlign).
Body(s.Icontent...)
Style("align-items", s.IverticalAlign)

for _, s := range s.Istyles {
body.Style(s.key, s.value)
}

return body.Body(s.Icontent...)
}
5 changes: 5 additions & 0 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ const (
left
middle
)

type style struct {
key string
value string
}

0 comments on commit fa270f6

Please sign in to comment.