-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
51 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ui | ||
|
||
import "github.com/ja-he/dayplan/internal/model" | ||
|
||
type ViewParams interface { | ||
GetScrollOffset() int | ||
GetZoomPercentage() float64 | ||
|
||
SetZoom(percentage float64) error | ||
ChangeZoomBy(percentage float64) error | ||
} | ||
|
||
type TimeViewParams interface { | ||
ViewParams | ||
MinutesPerRow() float64 | ||
} | ||
|
||
// SingleDayViewParams represents the zoom and scroll of a timeline in the UI. | ||
type SingleDayViewParams struct { | ||
// NRowsPerHour is the number of rows in the UI that represent an hour in the | ||
// timeline. | ||
NRowsPerHour int | ||
// ScrollOffset is the offset in rows by which the UI is scrolled. | ||
// (An unscrolled UI would have 00:00 at the very top.) | ||
ScrollOffset int | ||
} | ||
|
||
// MinutesPerRow returns the number of minutes a single row represents. | ||
func (p *SingleDayViewParams) MinutesPerRow() int { | ||
return 60 / p.NRowsPerHour | ||
} | ||
|
||
// TimeAtY is the time that corresponds to a given y-position. | ||
func (p *SingleDayViewParams) TimeAtY(y int) model.Timestamp { | ||
minutes := y*(60/p.NRowsPerHour) + p.ScrollOffset*(60/p.NRowsPerHour) | ||
ts := model.Timestamp{Hour: minutes / 60, Minute: minutes % 60} | ||
return ts | ||
} | ||
|
||
// YForTime gives the y value the given timestamp would be at with the | ||
// receiving ViewParams. | ||
func (p *SingleDayViewParams) YForTime(time model.Timestamp) int { | ||
return ((time.Hour*p.NRowsPerHour - p.ScrollOffset) + (time.Minute / (60 / p.NRowsPerHour))) | ||
} |