Skip to content

Commit

Permalink
Use improved text alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
z-riley committed Nov 11, 2024
1 parent 57bcc95 commit 127a43f
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 33 deletions.
12 changes: 4 additions & 8 deletions common/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@ type tile struct {

// newTile constructs a new tile with the correct style.
func newTile(sizePx float64, pos turdgl.Vec, val int, posIdx coord) *tile {
r := turdgl.NewCurvedRect(sizePx, sizePx, TileCornerRadius, pos)
tile := tile{
tb: turdgl.NewTextBox(r, strconv.Itoa(val), tileFont).
return &tile{
tb: turdgl.NewTextBox(turdgl.NewCurvedRect(
sizePx, sizePx, TileCornerRadius, pos,
).SetStyle(turdgl.Style{Colour: tileColour(val)}), strconv.Itoa(val), tileFont).
SetTextSize(tileFontSize(val)).
SetTextAlignment(turdgl.AlignCustom).
SetTextColour(tileTextColour(val)),
pos: posIdx,
}
tile.tb.Text.SetOffset(turdgl.Vec{X: 0, Y: 15})
r.SetStyle(turdgl.Style{Colour: tileColour(val)})

return &tile
}

// animationData contains animations and the current game state.
Expand Down
8 changes: 2 additions & 6 deletions common/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func NewMenuButton(width, height float64, pos turdgl.Vec, callback func()) *turd
b := turdgl.NewButton(r, FontPathMedium).
SetLabelText("SET ME").
SetLabelSize(36).
SetLabelColour(WhiteFontColour).
SetLabelAlignment(turdgl.AlignCustom).
SetLabelOffset(turdgl.Vec{X: 0, Y: 15})
SetLabelColour(WhiteFontColour)

b.SetCallback(
turdgl.ButtonTrigger{State: turdgl.NoClick, Behaviour: turdgl.OnHold},
Expand Down Expand Up @@ -73,9 +71,7 @@ func NewGameButton(width, height float64, pos turdgl.Vec, callback func()) *turd
b := turdgl.NewButton(r, FontPathBold).
SetLabelText("BUTTON").
SetLabelSize(14).
SetLabelColour(WhiteFontColour).
SetLabelAlignment(turdgl.AlignCustom).
SetLabelOffset(turdgl.Vec{X: 0, Y: 7})
SetLabelColour(WhiteFontColour)

b.SetCallback(
turdgl.ButtonTrigger{State: turdgl.NoClick, Behaviour: turdgl.OnHold},
Expand Down
8 changes: 4 additions & 4 deletions common/textbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewEntryBox(width, height float64, pos turdgl.Vec, txt string) *EntryBox {

bloom := turdgl.NewCurvedRect(width, height, 6, pos).SetStyle(styleUnselected)

tb := NewTextBox(width, height, pos, txt)
tb := NewTextBox(width, height, pos, txt).SetTextAlignment(turdgl.AlignCentre)
tb.SetSelectedCB(func() {
tb.SetTextColour(turdgl.White)
bloom.SetStyle(styleSelected)
Expand Down Expand Up @@ -91,7 +91,7 @@ type ScoreBox struct {
func NewScoreBox(width, height float64, pos turdgl.Vec, colour color.RGBA) *ScoreBox {
headingPos := turdgl.Vec{
X: pos.X + width/2,
Y: pos.Y + 25,
Y: pos.Y + 15,
}
heading := turdgl.NewText("Heading", headingPos, FontPathBold).
SetColour(LightGreyTextColour).
Expand All @@ -104,7 +104,7 @@ func NewScoreBox(width, height float64, pos turdgl.Vec, colour color.RGBA) *Scor
).SetStyle(turdgl.Style{Colour: colour})

body := turdgl.NewTextBox(r, "", FontPathBold).
SetTextOffset(turdgl.Vec{X: 0, Y: 18}).
SetTextOffset(turdgl.Vec{X: 0, Y: 10}).
SetTextSize(26).
SetTextColour(WhiteFontColour)

Expand Down Expand Up @@ -146,7 +146,7 @@ func NewLogoBox(size float64, pos turdgl.Vec) *turdgl.TextBox {
SetTextSize(32).
SetTextColour(WhiteFontColour)

logo.Text.SetAlignment(turdgl.AlignCustom).SetOffset(turdgl.Vec{Y: 15})
logo.Text.SetAlignment(turdgl.AlignCustom)
logo.Shape.(*turdgl.CurvedRect).SetStyle(turdgl.Style{Colour: Tile2048Colour})

return logo
Expand Down
4 changes: 2 additions & 2 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Widget struct {
}

func NewDebugWidget(win *turdgl.Window) *Widget {
location := turdgl.NewText("Loc: ", turdgl.Vec{X: 1090, Y: 25}, common.FontPathMedium).
location := turdgl.NewText("Loc: ", turdgl.Vec{X: 1120, Y: 25}, common.FontPathMedium).
SetAlignment(turdgl.AlignBottomRight).
SetSize(12)

fps := turdgl.NewText("FPS: -", turdgl.Vec{X: 1150, Y: 25}, common.FontPathMedium).
fps := turdgl.NewText("FPS: -", turdgl.Vec{X: 1180, Y: 25}, common.FontPathMedium).
SetAlignment(turdgl.AlignBottomRight).
SetSize(12)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/brunoga/deep v1.2.4
github.com/google/uuid v1.6.0
github.com/moby/moby v27.3.1+incompatible
github.com/z-riley/turdgl v0.0.0-20241110155312-25280b430bfe
github.com/z-riley/turdgl v0.0.0-20241111212625-8502d81bbf4b
github.com/z-riley/turdserve v0.0.0-20241109095301-66eab11d38af
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
)
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ github.com/z-riley/turdgl v0.0.0-20241110155021-280343130dc7 h1:i0KmQ9APd/pzkuwP
github.com/z-riley/turdgl v0.0.0-20241110155021-280343130dc7/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A=
github.com/z-riley/turdgl v0.0.0-20241110155312-25280b430bfe h1:eAF2Nn4N/xDvA2WLpUJWcL1lx36se4SKfi8AJJDzIxI=
github.com/z-riley/turdgl v0.0.0-20241110155312-25280b430bfe/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A=
github.com/z-riley/turdgl v0.0.0-20241111205046-14cbbbc7e3fa h1:r9fOAXSEnUoSLiQNYYSdZXlow0JizK2klt5VqNMWm8w=
github.com/z-riley/turdgl v0.0.0-20241111205046-14cbbbc7e3fa/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A=
github.com/z-riley/turdgl v0.0.0-20241111210007-493f8ad4a7dd h1:8DVIcZh7AnUpd0WZ6LKMr346sdrrAVab9bmX4ycOALk=
github.com/z-riley/turdgl v0.0.0-20241111210007-493f8ad4a7dd/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A=
github.com/z-riley/turdgl v0.0.0-20241111211348-7f67596fc4c3 h1:KyGahMKTdYnjt1TD46qz1GJPeSgeN04bFBer6CN/QxQ=
github.com/z-riley/turdgl v0.0.0-20241111211348-7f67596fc4c3/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A=
github.com/z-riley/turdgl v0.0.0-20241111211940-c3cd8a2a4483 h1:70BLpyLJWGuxgRDWuZ7Sr1KSgbLMnKDrc29Ky1X7HkQ=
github.com/z-riley/turdgl v0.0.0-20241111211940-c3cd8a2a4483/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A=
github.com/z-riley/turdgl v0.0.0-20241111212625-8502d81bbf4b h1:Vf/FWjMHQAcLWjDGTGmhs52EoNHK+ojtG722IWdyduw=
github.com/z-riley/turdgl v0.0.0-20241111212625-8502d81bbf4b/go.mod h1:PUy0rnENvtQrZRghi9dYinsUUE7gvC9wOz8C/gcwJ8A=
github.com/z-riley/turdserve v0.0.0-20241103172943-200ed8c9c094 h1:9ldkpBMZ5+BV8GOGH+4QhrBgevotAprFgMVCasm+td0=
github.com/z-riley/turdserve v0.0.0-20241103172943-200ed8c9c094/go.mod h1:D5VroZVlQvt0vUtZ2xHL8aQOlCumE/9LFEH1BBLE468=
github.com/z-riley/turdserve v0.0.0-20241109095301-66eab11d38af h1:X0XCfUgoGvZaOZtSRcB6UkuEkP4B6EzwvDUkkZkA7p0=
Expand Down
6 changes: 3 additions & 3 deletions screen/multiplayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *MultiplayerScreen) Enter(initData InitData) {

s.guide = common.NewGameText(
"Your grid",
turdgl.Vec{X: anchor.X + s.arena.Width(), Y: anchor.Y - 0.53*unit},
turdgl.Vec{X: anchor.X + s.arena.Width(), Y: anchor.Y - 0.67*unit},
).SetAlignment(turdgl.AlignTopRight)

s.backend = backend.NewGame(&backend.Opts{
Expand All @@ -125,7 +125,7 @@ func (s *MultiplayerScreen) Enter(initData InitData) {
s.arenaInputCh = make(chan func(), 100)

s.timer = common.NewGameText("",
turdgl.Vec{X: config.WinWidth / 2, Y: anchor.Y - 0.53*unit},
turdgl.Vec{X: config.WinWidth / 2, Y: anchor.Y - 0.67*unit},
).SetAlignment(turdgl.AlignTopCentre)
}

Expand All @@ -143,7 +143,7 @@ func (s *MultiplayerScreen) Enter(initData InitData) {
s.opponentName = initData[opponentUsernameKey].(string)
s.opponentGuide = common.NewGameText(
s.opponentName+"'s grid",
turdgl.Vec{X: opponentAnchor.X, Y: opponentAnchor.Y - 0.53*unit},
turdgl.Vec{X: opponentAnchor.X, Y: opponentAnchor.Y - 0.67*unit},
)

s.opponentBackend = backend.NewGame(&backend.Opts{
Expand Down
4 changes: 2 additions & 2 deletions screen/multiplayer_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *MultiplayerHostScreen) Enter(_ InitData) {

s.nameHeading = turdgl.NewText(
"Your name:",
turdgl.Vec{X: config.WinWidth / 2, Y: 290},
turdgl.Vec{X: config.WinWidth / 2, Y: 300},
common.FontPathMedium,
).
SetColour(common.GreyTextColour).
Expand All @@ -60,7 +60,7 @@ func (s *MultiplayerHostScreen) Enter(_ InitData) {

s.nameEntry = common.NewEntryBox(
440, 60,
turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.nameHeading.Pos().Y + 20},
turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.nameHeading.Pos().Y + 30},
namesgenerator.GetRandomName(0),
).
SetModifiedCB(func() {
Expand Down
8 changes: 4 additions & 4 deletions screen/multiplayer_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) {

s.nameHeading = turdgl.NewText(
"Your name:",
turdgl.Vec{X: config.WinWidth / 2, Y: 230},
turdgl.Vec{X: config.WinWidth / 2, Y: 250},
common.FontPathMedium,
).
SetColour(common.GreyTextColour).
Expand All @@ -60,7 +60,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) {

s.nameEntry = common.NewEntryBox(
440, 60,
turdgl.Vec{X: config.WinWidth/2 - 440/2, Y: s.nameHeading.Pos().Y + 15},
turdgl.Vec{X: config.WinWidth/2 - 440/2, Y: s.nameHeading.Pos().Y + 30},
namesgenerator.GetRandomName(0),
).
SetModifiedCB(func() {
Expand All @@ -74,7 +74,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) {

s.ipHeading = turdgl.NewText(
"Host IP:",
turdgl.Vec{X: config.WinWidth / 2, Y: 370},
turdgl.Vec{X: config.WinWidth / 2, Y: 380},
common.FontPathMedium,
).
SetColour(common.GreyTextColour).
Expand All @@ -90,7 +90,7 @@ func (s *MultiplayerJoinScreen) Enter(_ InitData) {

s.ipEntry = common.NewEntryBox(
440, 60,
turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.ipHeading.Pos().Y + 15},
turdgl.Vec{X: (config.WinWidth - 440) / 2, Y: s.ipHeading.Pos().Y + 30},
string(b),
).SetModifiedCB(func() {
if err := s.ipStore.SaveBytes([]byte(s.ipEntry.Text())); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions screen/singleplayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func (s *SingleplayerScreen) Enter(_ InitData) {

s.heading = turdgl.NewText(
"", // to be set and drawn when player loses
turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 2.3*unit},
turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 2.8*unit},
common.FontPathBold,
).SetSize(40).SetColour(common.GreyTextColour).SetAlignment(turdgl.AlignTopCentre)

s.loseDialog = turdgl.NewText(
"", // to be set and drawn when player loses
turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 1.7*unit},
turdgl.Vec{X: anchor.X + s.arena.Width()/2, Y: anchor.Y - 1.9*unit},
common.FontPathBold,
).SetSize(20).SetColour(common.GreyTextColour).SetAlignment(turdgl.AlignTopCentre)

Expand Down Expand Up @@ -108,7 +108,7 @@ func (s *SingleplayerScreen) Enter(_ InitData) {

s.guide = turdgl.NewText(
"Join the numbers and get to the 2048 tile!",
turdgl.Vec{X: anchor.X, Y: anchor.Y - 0.53*unit},
turdgl.Vec{X: anchor.X, Y: anchor.Y - 0.60*unit},
common.FontPathBold,
).SetSize(16).SetColour(common.GreyTextColour)

Expand Down

0 comments on commit 127a43f

Please sign in to comment.