Skip to content

Commit

Permalink
wip: wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Dec 14, 2022
1 parent d104c21 commit 4bc2313
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 83 deletions.
98 changes: 60 additions & 38 deletions internal/control/cli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ func NewController(
"gg": action.NewSimple(func() string { return "scroll to top" }, controller.ScrollTop),
"G": action.NewSimple(func() string { return "scroll to bottom" }, controller.ScrollBottom),
"+": action.NewSimple(func() string { return "zoom in" }, func() {
if controller.data.ViewParams.NRowsPerHour*2 <= 12 {
controller.data.ViewParams.NRowsPerHour *= 2
controller.data.ViewParams.ScrollOffset *= 2
if controller.data.MainTimelineViewParams.NRowsPerHour*2 <= 12 {
controller.data.MainTimelineViewParams.NRowsPerHour *= 2
controller.data.MainTimelineViewParams.ScrollOffset *= 2
}
}),
"-": action.NewSimple(func() string { return "zoom out" }, func() {
if (controller.data.ViewParams.NRowsPerHour % 2) == 0 {
controller.data.ViewParams.NRowsPerHour /= 2
controller.data.ViewParams.ScrollOffset /= 2
if (controller.data.MainTimelineViewParams.NRowsPerHour % 2) == 0 {
controller.data.MainTimelineViewParams.NRowsPerHour /= 2
controller.data.MainTimelineViewParams.ScrollOffset /= 2
} else {
log.Warn().Msg(fmt.Sprintf("can't decrease resolution below %d", controller.data.ViewParams.NRowsPerHour))
log.Warn().Msg(fmt.Sprintf("can't decrease resolution below %d", controller.data.MainTimelineViewParams.NRowsPerHour))
}
}),
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func NewController(
return controller.data.Days.GetDay(controller.data.CurrentDate.GetDayInWeek(dayIndex))
},
categoryStyling.GetStyle,
&controller.data.ViewParams,
&controller.data.MainTimelineViewParams,
&controller.data.CursorPos,
0,
false,
Expand Down Expand Up @@ -258,7 +258,7 @@ func NewController(
return controller.data.Days.GetDay(controller.data.CurrentDate.GetDayInMonth(dayIndex))
},
categoryStyling.GetStyle,
&controller.data.ViewParams,
&controller.data.MainTimelineViewParams,
&controller.data.CursorPos,
0,
false,
Expand Down Expand Up @@ -381,14 +381,14 @@ func NewController(

// TODO(ja-he): move elsewhere
ensureVisible := func(time model.Timestamp) {
topRowTime := controller.data.ViewParams.TimeAtY(0)
topRowTime := controller.data.MainTimelineViewParams.TimeAtY(0)
if topRowTime.IsAfter(time) {
controller.data.ViewParams.ScrollOffset += (controller.data.ViewParams.YForTime(time))
controller.data.MainTimelineViewParams.ScrollOffset += (controller.data.MainTimelineViewParams.YForTime(time))
}
_, _, _, maxY := dayViewEventsPaneDimensions()
bottomRowTime := controller.data.ViewParams.TimeAtY(maxY)
bottomRowTime := controller.data.MainTimelineViewParams.TimeAtY(maxY)
if time.IsAfter(bottomRowTime) {
controller.data.ViewParams.ScrollOffset += ((controller.data.ViewParams.YForTime(time)) - maxY)
controller.data.MainTimelineViewParams.ScrollOffset += ((controller.data.MainTimelineViewParams.YForTime(time)) - maxY)
}
}
var startMovePushing func()
Expand Down Expand Up @@ -427,7 +427,8 @@ func NewController(
Cat: controller.data.CurrentCategory,
}
if current == nil {
newEvent.Start = model.NewTimestampFromGotime(time.Now()).Snap(controller.data.ViewParams.MinutesPerRow())
newEvent.Start = model.NewTimestampFromGotime(time.Now()).
Snap(int(controller.data.MainTimelineViewParams.DurationOfHeight(1) / time.Minute))
} else {
newEvent.Start = current.End
}
Expand All @@ -447,7 +448,8 @@ func NewController(
Cat: controller.data.CurrentCategory,
}
if current == nil {
newEvent.End = model.NewTimestampFromGotime(time.Now()).Snap(controller.data.ViewParams.MinutesPerRow())
newEvent.End = model.NewTimestampFromGotime(time.Now()).
Snap(int(controller.data.MainTimelineViewParams.DurationOfHeight(1) / time.Minute))
} else {
newEvent.End = current.Start
}
Expand Down Expand Up @@ -535,7 +537,7 @@ func NewController(
processors.NewModalInputProcessor(dayViewEventsPaneInputTree),
controller.data.GetCurrentDay,
categoryStyling.GetStyle,
&controller.data.ViewParams,
&controller.data.MainTimelineViewParams,
&controller.data.CursorPos,
2,
true,
Expand All @@ -556,8 +558,8 @@ func NewController(
"j": action.NewSimple(func() string { return "move down" }, func() {
err := controller.data.GetCurrentDay().MoveEventsPushingBy(
controller.data.GetCurrentDay().Current,
controller.data.ViewParams.MinutesPerRow(),
controller.data.ViewParams.MinutesPerRow(),
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
if err != nil {
panic(err)
Expand All @@ -568,8 +570,8 @@ func NewController(
"k": action.NewSimple(func() string { return "move up" }, func() {
err := controller.data.GetCurrentDay().MoveEventsPushingBy(
controller.data.GetCurrentDay().Current,
-controller.data.ViewParams.MinutesPerRow(),
controller.data.ViewParams.MinutesPerRow(),
-int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -605,12 +607,20 @@ func NewController(
}),
"j": action.NewSimple(func() string { return "move down" }, func() {
current := controller.data.GetCurrentDay().Current
controller.data.GetCurrentDay().MoveSingleEventBy(current, controller.data.ViewParams.MinutesPerRow(), controller.data.ViewParams.MinutesPerRow())
controller.data.GetCurrentDay().MoveSingleEventBy(
current,
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
ensureVisible(current.End)
}),
"k": action.NewSimple(func() string { return "move up" }, func() {
current := controller.data.GetCurrentDay().Current
controller.data.GetCurrentDay().MoveSingleEventBy(current, -controller.data.ViewParams.MinutesPerRow(), controller.data.ViewParams.MinutesPerRow())
controller.data.GetCurrentDay().MoveSingleEventBy(
current,
-int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
ensureVisible(current.Start)
}),
"m": action.NewSimple(func() string { return "exit move mode" }, func() { dayEventsPane.PopModalOverlay(); controller.data.EventEditMode = control.EventEditModeNormal }),
Expand Down Expand Up @@ -639,20 +649,32 @@ func NewController(
"j": action.NewSimple(func() string { return "increase size (lengthen)" }, func() {
var err error
current := controller.data.GetCurrentDay().Current
err = controller.data.GetCurrentDay().ResizeBy(current, controller.data.ViewParams.MinutesPerRow())
err = controller.data.GetCurrentDay().ResizeBy(
current,
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
if err != nil {
log.Warn().Msg(err.Error())
}
err = controller.data.GetCurrentDay().SnapEnd(current, controller.data.ViewParams.MinutesPerRow())
err = controller.data.GetCurrentDay().SnapEnd(
current,
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
if err != nil {
log.Warn().Msg(err.Error())
}
ensureVisible(current.End)
}),
"k": action.NewSimple(func() string { return "decrease size (shorten)" }, func() {
current := controller.data.GetCurrentDay().Current
controller.data.GetCurrentDay().ResizeBy(current, -controller.data.ViewParams.MinutesPerRow())
controller.data.GetCurrentDay().SnapEnd(current, controller.data.ViewParams.MinutesPerRow())
controller.data.GetCurrentDay().ResizeBy(
current,
-int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
controller.data.GetCurrentDay().SnapEnd(
current,
int(controller.data.MainTimelineViewParams.DurationOfHeight(1)/time.Minute),
)
ensureVisible(current.End)
}),
"r": action.NewSimple(func() string { return "exit resize mode" }, func() { dayEventsPane.PopModalOverlay(); controller.data.EventEditMode = control.EventEditModeNormal }),
Expand Down Expand Up @@ -740,15 +762,15 @@ func NewController(
return nil
}
},
&controller.data.ViewParams,
&controller.data.MainTimelineViewParams,
),
panes.NewWeatherPane(
tui.NewConstrainedRenderer(renderer, weatherDimensions),
weatherDimensions,
stylesheet,
&controller.data.CurrentDate,
&controller.data.Weather,
&controller.data.ViewParams,
&controller.data.MainTimelineViewParams,
),
},
[]ui.Pane{
Expand Down Expand Up @@ -806,7 +828,7 @@ func NewController(
stylesheet,
func() *model.SunTimes { return nil },
func() *model.Timestamp { return nil },
&controller.data.ViewParams,
&controller.data.MainTimelineViewParams,
),
weekViewEventsWrapper,
},
Expand All @@ -828,7 +850,7 @@ func NewController(
stylesheet,
func() *model.SunTimes { return nil },
func() *model.Timestamp { return nil },
&controller.data.ViewParams,
&controller.data.MainTimelineViewParams,
),
monthViewEventsWrapper,
},
Expand Down Expand Up @@ -1110,7 +1132,7 @@ func NewController(

controller.timestampGuesser = func(cursorX, cursorY int) model.Timestamp {
_, yOffset, _, _ := dayViewEventsPaneDimensions()
return controller.data.ViewParams.TimeAtY(yOffset + cursorY)
return controller.data.MainTimelineViewParams.TimeAtY(yOffset + cursorY)
}

controller.initializedScreen = renderer
Expand All @@ -1123,29 +1145,29 @@ func NewController(

func (t *Controller) ScrollUp(by int) {
eventviewTopRow := 0
if t.data.ViewParams.ScrollOffset-by >= eventviewTopRow {
t.data.ViewParams.ScrollOffset -= by
if t.data.MainTimelineViewParams.ScrollOffset-by >= eventviewTopRow {
t.data.MainTimelineViewParams.ScrollOffset -= by
} else {
t.ScrollTop()
}
}

func (t *Controller) ScrollDown(by int) {
eventviewBottomRow := t.tmpStatusYOffsetGetter()
if t.data.ViewParams.ScrollOffset+by+eventviewBottomRow <= (24 * t.data.ViewParams.NRowsPerHour) {
t.data.ViewParams.ScrollOffset += by
if t.data.MainTimelineViewParams.ScrollOffset+by+eventviewBottomRow <= (24 * t.data.MainTimelineViewParams.NRowsPerHour) {
t.data.MainTimelineViewParams.ScrollOffset += by
} else {
t.ScrollBottom()
}
}

func (t *Controller) ScrollTop() {
t.data.ViewParams.ScrollOffset = 0
t.data.MainTimelineViewParams.ScrollOffset = 0
}

func (t *Controller) ScrollBottom() {
eventviewBottomRow := t.tmpStatusYOffsetGetter()
t.data.ViewParams.ScrollOffset = 24*t.data.ViewParams.NRowsPerHour - eventviewBottomRow
t.data.MainTimelineViewParams.ScrollOffset = 24*t.data.MainTimelineViewParams.NRowsPerHour - eventviewBottomRow
}

func (t *Controller) abortEdit() {
Expand Down Expand Up @@ -1379,7 +1401,7 @@ func (t *Controller) handleMouseResizeEditEvent(ev tcell.Event) {
switch buttons {
case tcell.Button1:
cursorTime := t.timestampGuesser(x, y)
visualCursorTime := cursorTime.OffsetMinutes(t.data.ViewParams.MinutesPerRow())
visualCursorTime := cursorTime.OffsetMinutes(int(t.data.MainTimelineViewParams.DurationOfHeight(1) / time.Minute))
event := t.data.MouseEditedEvent

var err error
Expand Down
6 changes: 3 additions & 3 deletions 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.SingleDayViewParams
MainTimelineViewParams ui.SingleDayViewParams

ActiveView func() ui.ActiveView

Expand Down Expand Up @@ -141,8 +141,8 @@ func NewControlData(cs styling.CategoryStyling) *ControlData {
t.Categories = append(t.Categories, style.Cat)
}

t.ViewParams.NRowsPerHour = 6
t.ViewParams.ScrollOffset = 8 * t.ViewParams.NRowsPerHour
t.MainTimelineViewParams.NRowsPerHour = 6
t.MainTimelineViewParams.ScrollOffset = 8 * t.MainTimelineViewParams.NRowsPerHour

return &t
}
Expand Down
5 changes: 3 additions & 2 deletions internal/input/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
// Key represents a key input.
//
// NOTE:
// currently barely generifying tcell's input type; could eventually be
// properly generified for other input sources.
//
// currently barely generifying tcell's input type; could eventually be
// properly generified for other input sources.
type Key struct {
Mod tcell.ModMask
Key tcell.Key
Expand Down
5 changes: 3 additions & 2 deletions internal/input/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
// It can have child nodes or an action.
//
// NOTE:
// must not have children if it has an action, and must not have an action if
// it has children.
//
// must not have children if it has an action, and must not have an action if
// it has children.
type Node struct {
Children map[Key]*Node
Action action.Action
Expand Down
12 changes: 6 additions & 6 deletions internal/input/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
//
// Example:
//
// tree: mapping:
// tree: mapping:
//
// x
// +-y
// | +-z -> action1 "xyz" -> action1
// +-z -> action2 "xz" -> action2
// z -> action3 "z" -> action3
// x
// +-y
// | +-z -> action1 "xyz" -> action1
// +-z -> action2 "xz" -> action2
// z -> action3 "z" -> action3
type Tree struct {
Root *Node
Current *Node
Expand Down
27 changes: 13 additions & 14 deletions internal/model/day.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,21 +323,20 @@ func (day *Day) SumUpByCategory() map[Category]int {
// splitting a less prioritized event if it had a higher-priority event occur
// during it as shown here:
//
// +-------+ +-------+
// | a | | a | (`a` lower prio than `B`)
// | +-----+ +-------+
// | | B | ~~> | B |
// | +-----+ +-------+
// | | | a |
// +-------+ +-------+
//
// +-------+ +-------+
// | a | | a | (`a` lower prio than `B`)
// | +-----+ +-------+
// | | B | ~~> | B |
// +---| | | |
// +-----+ +-------+
// +-------+ +-------+
// | a | | a | (`a` lower prio than `B`)
// | +-----+ +-------+
// | | B | ~~> | B |
// | +-----+ +-------+
// | | | a |
// +-------+ +-------+
//
// +-------+ +-------+
// | a | | a | (`a` lower prio than `B`)
// | +-----+ +-------+
// | | B | ~~> | B |
// +---| | | |
// +-----+ +-------+
func (day *Day) Flatten() {
if len(day.Events) < 2 {
return
Expand Down
1 change: 1 addition & 0 deletions internal/model/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (a Timestamp) IsAfter(b Timestamp) bool {
}
}

// TODO: migrate to time.Duration-based
func (t Timestamp) Snap(minutesModulus int) Timestamp {
minutes := t.toMinutes()

Expand Down
6 changes: 3 additions & 3 deletions internal/styling/render_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ func (s *FallbackStyling) clone() *FallbackStyling {
// Strings have to have hexadecimal or HTML color notation and lead with a '#'.
//
// Examples:
// - '#ff0000'
// - '#fff'
// - '#BEEF42'
// - '#ff0000'
// - '#fff'
// - '#BEEF42'
func StyleFromHexPair(fg, bg string) *FallbackStyling {
return &FallbackStyling{
fg: colorfulColorFromHexString(fg),
Expand Down
Loading

0 comments on commit 4bc2313

Please sign in to comment.