I am using the python port of imgui This is the code of the two classes that i am using to implement the materializecss style toasts in imgui, but the problem that i run into is that they start to overlap, i have been trying to solve the problem and the pring statement shows that the y position is where is should be yet it doesn't show that way. `
class ToastController():
def __init__(self, Width, Height, window, pad=[10,10], font=None, xfont=None):
self.Toasts = []
self.Width = Width
self.Height = Height
self.window = window
self.font = font
self.xfont = xfont
self.window = window
self.pad = pad
def AddToast(self, Text = "", Timeout=10):
print(glfw.get_window_size(self.window)[1]-(self.Height*(len(self.Toasts)+1))-self.pad[1])
self.pos = [glfw.get_window_size(self.window)[0]-self.Width-self.pad[0], glfw.get_window_size(self.window)[1]-(self.Height*(len(self.Toasts)+1))-self.pad[1]]
self.Toasts.append(Toast(self.Width, self.Height, self.window, self.pos, Text, self.font, self.xfont, Timeout))
def Display(self):
for i in self.Toasts:
# j = self.Toasts[i]
if i.i > 0:
i.Display()
else:
self.Toasts.pop(self.Toasts.index(i))
class Toast:
def __init__(self, width, height, window, pos, Text="", font=None, xfont=None, timeout=10):
self.Toasts = {}
self.width = width
self.height = height
self.font = font
self.Text = Text
self.timeout=timeout
self.pos = pos
self.xfont = xfont
self.ShouldDel = False
self.time = time.time()
self.i = 1
def AddButton(self, Text, callback, callbackargs=None, inline=False, font=None, fontcolor=None, bgcolor=None, width=None, height=None):
if font != None:
imgui.push_font(font)
if bgcolor != None:
imgui.push_style_color(imgui.COLOR_BUTTON, *bgcolor)
if fontcolor != None:
imgui.push_style_color(imgui.COLOR_TEXT, *fontcolor)
width = width if width != None else 100
height = height if height != None else 20
if inline == True:
imgui.same_line()
if imgui.button(Text, width, height):
if callbackargs != None:
callback(callbackargs)
else:
callback()
if fontcolor != None:
imgui.pop_style_color(1)
if bgcolor != None:
imgui.pop_style_color(1)
if font != None:
imgui.pop_font()
def CloseToast(self):
self.i = -1
self.ShouldDel = True
def Display(self,):
if self.font != None:
imgui.push_font(self.font)
if time.time()-self.time >= (self.timeout)/1000:
self.i -= 0.001
self.time = time.time()
if self.i >= 0:
imgui.set_next_window_size(self.width, self.height)
imgui.set_next_window_position(self.pos[0], self.pos[1])
imgui.begin("", flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_SCROLLBAR)
imgui.text(self.Text)
self.AddButton("X", lambda: self.CloseToast(), inline=True, font=self.font, fontcolor=(1.0, 1.0, 1.0, 1.0), bgcolor=(0.0, 0.0, 0.0, 0), width=2*imgui.calc_text_size("X").x, height=1.5*imgui.calc_text_size("X").y)
imgui.progress_bar(self.i, (self.width, self.height/10))
imgui.end()
else:
self.CloseToast()
if self.font != None:
imgui.pop_font()
`

yet when one of timers on the toasts runs out, the other one goes to where it should belong

I have no idea how to fix this issue
what i was expecting is the toasts to stack up and fade out as they expire like on the websites