Good tabs

This commit is contained in:
Astatin3
2024-03-14 12:35:36 -06:00
parent 2dab7295ac
commit 5ee635352d
6 changed files with 334 additions and 72 deletions
+51 -42
View File
@@ -1,4 +1,6 @@
import math
from copy import copy
import pygame as pg
from pygame.locals import *
from sys import exit
@@ -7,6 +9,8 @@ import numpy as np
import src.render as render
import src.menu as menu
import src.pathEditor as pathEditor
import src.buttonEditor as buttonEditor
import src.export as export
doubleClickDuration = 200
@@ -14,50 +18,48 @@ pg.init()
pg.font.init()
topBarHeight = 40
bottomBarHeight = 40
bottomBarHeight = 60
screen_width = 1200
screen_height = (screen_width * (643/1286)) + topBarHeight + bottomBarHeight
screen = pg.display.set_mode((screen_width, screen_height))
screen = pg.display.set_mode((screen_width, screen_height))#, pg.RESIZABLE)
pg.display.set_caption("Auto Planner")
pathR = render.render(pg, screen, topBarHeight)
tabIndex = 1
render = render.render(pg, screen, topBarHeight, bottomBarHeight)
tabIndex = 0
tabs = [
menu.menu(pg, pathR),
pathEditor.pathEditor(pg, pathR)
menu.menu(pg, render),
pathEditor.pathEditor(render),
buttonEditor.buttonEditor(render, pathEditor),
export.export(pg, render)
]
def isInRect(pos, rect):
return pos[0] >= rect[0] and \
pos[0] <= rect[2] and \
pos[1] >= rect[1] and \
pos[1] <= rect[3]
tabs[tabIndex].load()
def refreshTabs(pos):
for i in range(len(tabs)):
# color = i * (255/(len(tabs)-1))
# color = (color, color, color)
x1 = i * (screen_width/(len(tabs)))
x2 = (i+1) * (screen_width/(len(tabs)))
rect = (x1, 0, x2, topBarHeight)
if i == tabIndex:
color = (255, 255, 255)
elif isInRect(pos, rect):
color = (127,127,127)
else:
color = (63,63,63)
pg.draw.rect(screen, color, rect)
pg.display.update()
refreshTabs((screen_width/2, screen_height/2))
def addTab(i):
x1 = i * (screen_width/(len(tabs)))
x2 = (screen_width/(len(tabs)))
rect = (x1, 0, x2, topBarHeight)
def getIsSelected():
global tabIndex
return tabIndex == i
def onClick(pos):
global tabIndex
tabIndex = i
tabs[tabIndex].load()
render.renderElements(pos)
pg.display.update()
render.addButton(rect, tabs[i].name, getIsSelected, onClick)
for i in range(len(tabs)):
addTab(i)
render.renderElements((screen_width/2, screen_height/2))
running = True
last_click = -1
@@ -68,8 +70,16 @@ def offsetPos(pos):
while running:
for event in pg.event.get():
if event.type == pg.MOUSEBUTTONDOWN:
if event.type == pg.MOUSEMOTION:
pos = pg.mouse.get_pos()
render.renderElements(pos)
if pos[1] > topBarHeight:
tabs[tabIndex].mouseMove(offsetPos(pos))
# refreshTabs(pos)
elif event.type == pg.MOUSEBUTTONDOWN:
pos = pg.mouse.get_pos()
render.clickElement(pos)
if pos[1] > topBarHeight:
now = pg.time.get_ticks()
if now - last_click <= doubleClickDuration:
@@ -77,19 +87,18 @@ while running:
else:
tabs[tabIndex].mouseDown(offsetPos(pos))
last_click = pg.time.get_ticks()
if event.type == pg.MOUSEMOTION:
pos = pg.mouse.get_pos()
if pos[1] > topBarHeight:
tabs[tabIndex].mouseMove(offsetPos(pos))
refreshTabs(pos)
# else:
# clickTab(pos)
if event.type == pg.MOUSEBUTTONUP:
elif event.type == pg.MOUSEBUTTONUP:
pos = pg.mouse.get_pos()
if pos[1] > topBarHeight:
tabs[tabIndex].mouseUp(offsetPos(pos))
if event.type == pg.QUIT:
elif event.type == pg.KEYDOWN:
tabs[tabIndex].keyDown(event.key)
elif event.type == pg.QUIT:
running = False
pg.quit()