Skip to content

Commit

Permalink
wip: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Nov 1, 2022
1 parent 3f48d61 commit d104c21
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 36 deletions.
2 changes: 1 addition & 1 deletion internal/control/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type ControlData struct {
ShowSummary bool
ShowDebug bool

ViewParams ui.ViewParams
ViewParams ui.SingleDayViewParams

ActiveView func() ui.ActiveView

Expand Down
4 changes: 2 additions & 2 deletions internal/ui/panes/events_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type EventsPane struct {

styleForCategory func(model.Category) (styling.DrawStyling, error)

viewParams *ui.ViewParams
viewParams *ui.SingleDayViewParams
cursor *ui.MouseCursorPos

pad int
Expand Down Expand Up @@ -234,7 +234,7 @@ func NewEventsPane(
inputProcessor input.ModalInputProcessor,
day func() *model.Day,
styleForCategory func(model.Category) (styling.DrawStyling, error),
viewParams *ui.ViewParams,
viewParams *ui.SingleDayViewParams,
cursor *ui.MouseCursorPos,
pad int,
drawTimestamps bool,
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/panes/timeline_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TimelinePane struct {
suntimes func() *model.SunTimes
currentTime func() *model.Timestamp

viewParams *ui.ViewParams
viewParams *ui.SingleDayViewParams
}

// Draw draws this pane.
Expand Down Expand Up @@ -96,7 +96,7 @@ func NewTimelinePane(
stylesheet styling.Stylesheet,
suntimes func() *model.SunTimes,
currentTime func() *model.Timestamp,
viewParams *ui.ViewParams,
viewParams *ui.SingleDayViewParams,
) *TimelinePane {
return &TimelinePane{
Leaf: Leaf{
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/panes/weather_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type WeatherPane struct {

weather *weather.Handler
currentDate *model.Date
viewParams *ui.ViewParams
viewParams *ui.SingleDayViewParams
}

// Dimensions gives the dimensions (x-axis offset, y-axis offset, width,
Expand Down Expand Up @@ -81,7 +81,7 @@ func NewWeatherPane(
stylesheet styling.Stylesheet,
currentDate *model.Date,
weather *weather.Handler,
viewParams *ui.ViewParams,
viewParams *ui.SingleDayViewParams,
) *WeatherPane {
return &WeatherPane{
Leaf: Leaf{
Expand Down
29 changes: 0 additions & 29 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ui

import (
"github.com/ja-he/dayplan/internal/input"
"github.com/ja-he/dayplan/internal/model"
"github.com/ja-he/dayplan/internal/styling"
)

Expand Down Expand Up @@ -198,40 +197,12 @@ type RenderOrchestratorControl interface {
Show()
}

// ViewParams represents the zoom and scroll of a timeline in the UI.
type ViewParams 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 *ViewParams) MinutesPerRow() int {
return 60 / p.NRowsPerHour
}

// MouseCursorPos represents the position of a mouse cursor on the UI's
// x-y-plane, which has its origin 0,0 in the top left.
type MouseCursorPos struct {
X, Y int
}

// TimeAtY is the time that corresponds to a given y-position.
func (p *ViewParams) 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 *ViewParams) YForTime(time model.Timestamp) int {
return ((time.Hour*p.NRowsPerHour - p.ScrollOffset) + (time.Minute / (60 / p.NRowsPerHour)))
}

// TextCursorController offers control of a text cursor, such as for a terminal.
type TextCursorController interface {
HideCursor()
Expand Down
44 changes: 44 additions & 0 deletions internal/ui/view_params.go
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)))
}

0 comments on commit d104c21

Please sign in to comment.