Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Strosel/treman
Browse files Browse the repository at this point in the history
  • Loading branch information
Strosel committed Aug 20, 2020
2 parents d1757b1 + 1aed562 commit cfcf0fb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 24 deletions.
82 changes: 60 additions & 22 deletions add.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package main

import (
"image/color"
"runtime"

"gioui.org/io/key"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"golang.org/x/image/colornames"
)

type addRule struct {
rules []Rule

ruleRadio *widget.Enum
d1 *diceButton
d2 *diceButton
nameEdit *widget.Editor
saveClick *widget.Clickable
ruleRadio *widget.Enum
d1 *diceButton
d2 *diceButton
nameEdit *widget.Editor
saveClick *widget.Clickable
cancelClick *widget.Clickable
}

func addRuleScreen(th *material.Theme, rules []Rule) Screen {
a := &addRule{
rules: rules,
ruleRadio: new(widget.Enum),
d1: newDiceButton(th),
d2: newDiceButton(th),
nameEdit: new(widget.Editor),
saveClick: new(widget.Clickable),
rules: rules,
ruleRadio: new(widget.Enum),
d1: newDiceButton(th),
d2: newDiceButton(th),
nameEdit: new(widget.Editor),
saveClick: new(widget.Clickable),
cancelClick: new(widget.Clickable),
}

a.ruleRadio.Value = "sum"
Expand All @@ -37,17 +44,48 @@ func (a *addRule) Layout(gtx Ctx, th *material.Theme) (nextScreen Screen) {
nextScreen = a

radio := func(gtx Ctx) Dim {
in := layout.UniformInset(unit.Dp(0))
in.Top = unit.Dp(64)
return in.Layout(gtx, func(gtx Ctx) Dim {
return layout.Flex{
Spacing: layout.SpaceAround,
}.Layout(gtx,
layout.Rigid(material.RadioButton(th, a.ruleRadio, "sum", "Summa").Layout),
layout.Rigid(material.RadioButton(th, a.ruleRadio, "set", "Par").Layout),
layout.Rigid(material.RadioButton(th, a.ruleRadio, "single", "En tärning").Layout),
)
})
if runtime.GOOS == "android" {
in := layout.UniformInset(unit.Dp(0))
in.Top = unit.Dp(64)
return in.Layout(gtx, func(gtx Ctx) Dim {
return layout.Flex{
Spacing: layout.SpaceAround,
}.Layout(gtx,
layout.Rigid(material.RadioButton(th, a.ruleRadio, "sum", "Summa").Layout),
layout.Rigid(material.RadioButton(th, a.ruleRadio, "set", "Par").Layout),
layout.Rigid(material.RadioButton(th, a.ruleRadio, "single", "En tärning").Layout),
)
})
}
return layout.Flex{
Axis: layout.Vertical,
}.Layout(gtx,
layout.Rigid(func(gtx Ctx) Dim {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx Ctx) Dim {
bttn := material.Button(th, a.cancelClick, "←")
bttn.Color = colornames.Black
bttn.Background = color.RGBA{255, 255, 255, 255}
bttn.Font.Weight = text.Bold

for a.cancelClick.Clicked() {
nextScreen = gameScreen(a.rules)
}

return bttn.Layout(gtx)
}),
)
}),
layout.Rigid(func(gtx Ctx) Dim {
return layout.Flex{
Spacing: layout.SpaceAround,
}.Layout(gtx,
layout.Rigid(material.RadioButton(th, a.ruleRadio, "sum", "Summa").Layout),
layout.Rigid(material.RadioButton(th, a.ruleRadio, "set", "Par").Layout),
layout.Rigid(material.RadioButton(th, a.ruleRadio, "single", "En tärning").Layout),
)
}),
)
}

rolls := func(gtx Ctx) Dim {
Expand Down
27 changes: 25 additions & 2 deletions viewRules.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package main

import (
"image/color"
"runtime"

"gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"golang.org/x/image/colornames"
)

var baserules = `Först väljs en spelare till treman, detta är en titel som kommer förflytta sig under spelets gång.
Expand All @@ -21,7 +26,8 @@ n+n klunkar betyder att n st klunkar får delas ut till två personer eller dubb
type viewRules struct {
rules []Rule

list *layout.List
list *layout.List
cancelClick *widget.Clickable
}

func viewRulesScreen(rules []Rule) Screen {
Expand All @@ -30,6 +36,7 @@ func viewRulesScreen(rules []Rule) Screen {
list: &layout.List{
Axis: layout.Vertical,
},
cancelClick: new(widget.Clickable),
}
}

Expand All @@ -39,8 +46,24 @@ func (v *viewRules) Layout(gtx Ctx, th *material.Theme) (nextScreen Screen) {
layout.UniformInset(unit.Dp(8)).Layout(gtx, func(gtx Ctx) Dim {
return v.list.Layout(gtx, len(v.rules)+2, func(gtx Ctx, i int) Dim {
return layout.UniformInset(unit.Dp(16)).Layout(gtx, func(gtx Ctx) Dim {
if i == 0 {
if i == 0 && runtime.GOOS == "android" {
return layout.Inset{Top: unit.Dp(16)}.Layout(gtx, material.H6(th, "Regler").Layout)
} else if i == 0 {
bttn := material.Button(th, v.cancelClick, "← Regler"+runtime.GOOS)
bttn.Color = colornames.Black
bttn.Background = color.RGBA{255, 255, 255, 255}
bttn.TextSize = material.H6(th, "").TextSize
bttn.Inset.Left = unit.Dp(0)

for v.cancelClick.Clicked() {
nextScreen = gameScreen(v.rules)
}

return layout.Flex{
Alignment: layout.Start,
}.Layout(gtx,
RigidInset(layout.Inset{Top: unit.Dp(16)}, bttn.Layout),
)
} else if i == 1 {
body := material.Body1(th, baserules)
body.TextSize = unit.Dp(24)
Expand Down

0 comments on commit cfcf0fb

Please sign in to comment.