Skip to content

Commit

Permalink
feat: Add empty tasks pane
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Oct 22, 2022
1 parent 48be9a2 commit f1f0312
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions internal/control/cli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func NewController(

controller.data = control.NewControlData(categoryStyling)

tasksWidth := 40
toolsWidth := 20
rightFlexWidth := toolsWidth

Expand Down Expand Up @@ -132,6 +133,10 @@ func NewController(
}
helpDimensions := screenDimensions
editorDimensions := centeredFloat(editorWidth, editorHeight)
tasksDimensions := func() (x, y, w, h int) {
screenWidth, screenHeight := screenSize()
return screenWidth - rightFlexWidth, 0, tasksWidth, screenHeight - statusHeight
}
toolsDimensions := func() (x, y, w, h int) {
screenWidth, screeenHeight := screenSize()
return screenWidth - toolsWidth, 0, toolsWidth, screeenHeight - statusHeight
Expand Down Expand Up @@ -313,6 +318,13 @@ func NewController(
func() control.EventEditMode { return controller.data.EventEditMode },
)

tasksInputTree, err := input.ConstructInputTree(
map[string]action.Action{
"x": action.NewSimple(func() string { return "switch to next category" }, func() {
log.Debug().Msg("Tasks action triggered by tasks pane input processing")
}),
},
)
toolsInputTree, err := input.ConstructInputTree(
map[string]action.Action{
"j": action.NewSimple(func() string { return "switch to next category" }, func() {
Expand Down Expand Up @@ -467,7 +479,15 @@ func NewController(
stderrLogger.Fatal().Err(err).Msg("failed to construct input tree for day view pane's events subpane")
}

tasksVisible := false
toolsVisible := true
tasksPane := panes.NewTasksPane(
tui.NewConstrainedRenderer(renderer, tasksDimensions),
tasksDimensions,
stylesheet,
processors.NewModalInputProcessor(tasksInputTree),
func() bool { return tasksVisible },
)
toolsPane := panes.NewToolsPane(
tui.NewConstrainedRenderer(renderer, toolsDimensions),
toolsDimensions,
Expand Down Expand Up @@ -635,21 +655,36 @@ func NewController(
stderrLogger.Fatal().Err(err).Msg("failed to construct input tree for root pane")
}
var ensureDayViewMainPaneFocusIsOnVisible func()
updateMainPaneRightFlexWidth := func() {
rightFlexWidth = 0
if tasksPane.IsVisible() {
rightFlexWidth += tasksWidth
}
if toolsPane.IsVisible() {
rightFlexWidth += toolsWidth
}
}
toggleToolsPane := func() {
toolsVisible = !toolsVisible
if toolsVisible {
rightFlexWidth = toolsWidth
} else {
rightFlexWidth = 0
if !toolsVisible {
ensureDayViewMainPaneFocusIsOnVisible()
}
updateMainPaneRightFlexWidth()
}
toggleTasksPane := func() {
tasksVisible = !tasksVisible
if !tasksVisible {
ensureDayViewMainPaneFocusIsOnVisible()
}
updateMainPaneRightFlexWidth()
}

var dayViewFocusNext, dayViewFocusPrev func()
dayViewInputTree, err := input.ConstructInputTree(
map[string]action.Action{
"W": action.NewSimple(func() string { return "update weather" }, controller.updateWeather),
"t": action.NewSimple(func() string { return "toggle tools pane" }, toggleToolsPane),
"T": action.NewSimple(func() string { return "toggle tools pane" }, toggleTasksPane),
"<c-w>h": action.NewSimple(func() string { return "switch to previous pane" }, func() { dayViewFocusPrev() }),
"<c-w>l": action.NewSimple(func() string { return "switch to next pane" }, func() { dayViewFocusNext() }),
},
Expand Down Expand Up @@ -718,11 +753,13 @@ func NewController(
dayViewMainPane := panes.NewWrapperPane(
[]ui.Pane{
dayViewScrollablePane,
tasksPane,
toolsPane,
statusPane,
},
[]ui.Pane{
dayViewScrollablePane,
tasksPane,
toolsPane,
},
processors.NewModalInputProcessor(dayViewInputTree),
Expand Down

0 comments on commit f1f0312

Please sign in to comment.