prime8dev

prime8dev
git clone https://git.prime8.dev/prime8dev.git
Log | Files | Refs | README | LICENSE

layout.go (1528B)


      1 package tui
      2 
      3 import "github.com/charmbracelet/lipgloss"
      4 
      5 func (m *portfolioModel) syncViewport() {
      6 	m.viewport.SetContent(m.detailContent())
      7 	w, h := m.detailSize()
      8 	m.viewport.Width = max(w, 1)
      9 	m.viewport.Height = max(h, 1)
     10 	m.viewport.GotoTop()
     11 }
     12 
     13 func (m portfolioModel) detailSize() (int, int) {
     14 	bodyW, bodyH := m.bodySize()
     15 
     16 	if m.activeTab == tabAbout {
     17 		if bodyW < 72 {
     18 			return max(bodyW-4, 10), max(bodyH-2, 3)
     19 		}
     20 		leftW := min(max(bodyW/3, 26), 36)
     21 		rightW := max(bodyW-leftW, 12)
     22 		return max(rightW-4, 10), max(bodyH-2, 3)
     23 	}
     24 
     25 	if m.activeTab == tabProjects {
     26 		if bodyW < 72 {
     27 			stackTop := max(bodyH/2, 3)
     28 			stackBottom := max(bodyH-stackTop, 1)
     29 			return max(bodyW-4, 10), max(stackBottom-2, 3)
     30 		}
     31 
     32 		sideW := m.sidebarWidth(bodyW)
     33 		detailPanelW := bodyW - sideW
     34 		return max(detailPanelW-4, 10), max(bodyH-2, 3)
     35 	}
     36 
     37 	return max(bodyW-4, 10), max(bodyH-2, 3)
     38 }
     39 
     40 func (m portfolioModel) bodySize() (int, int) {
     41 	w := max(m.width, 40)
     42 	h := max(m.height, 12)
     43 	headerH := lipgloss.Height(m.renderHeader(w))
     44 	footerH := lipgloss.Height(m.renderFooter(w))
     45 	bodyH := max(h-headerH-footerH, 3)
     46 	return max(w, 20), bodyH
     47 }
     48 
     49 func (m portfolioModel) sidebarWidth(bodyWidth int) int {
     50 	if bodyWidth < 80 {
     51 		return bodyWidth
     52 	}
     53 	return min(max(bodyWidth/3, 24), 40)
     54 }
     55 
     56 func (m portfolioModel) detailContent() string {
     57 	switch m.activeTab {
     58 	case tabAbout:
     59 		return m.aboutDetail()
     60 	case tabProjects:
     61 		return m.projectDetail()
     62 	case tabExperience:
     63 		return m.experiencePage()
     64 	default:
     65 		return m.blogPage()
     66 	}
     67 }