mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Fix some problems with window closing and the delete world confirmation window.
Seems relevant for #809
This commit is contained in:
parent
fd478e2b99
commit
c495e8406c
@ -70,8 +70,11 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
||||
|
||||
fn executeCommands() void {
|
||||
mutex.lock();
|
||||
defer mutex.unlock();
|
||||
while(commands.popOrNull()) |command| {
|
||||
const commands_ = main.stackAllocator.dupe(Command, commands.items);
|
||||
defer main.stackAllocator.free(commands_);
|
||||
commands.clearAndFree();
|
||||
mutex.unlock();
|
||||
for(commands_) |command| {
|
||||
switch(command.action) {
|
||||
.open => {
|
||||
executeOpenWindowCommand(command.window);
|
||||
@ -84,7 +87,6 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
||||
}
|
||||
|
||||
fn executeOpenWindowCommand(window: *GuiWindow) void {
|
||||
main.utils.assertLocked(&mutex);
|
||||
defer updateWindowPositions();
|
||||
for(openWindows.items, 0..) |_openWindow, i| {
|
||||
if(_openWindow == window) {
|
||||
@ -95,14 +97,11 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
||||
}
|
||||
}
|
||||
openWindows.append(window);
|
||||
mutex.unlock();
|
||||
window.onOpenFn();
|
||||
mutex.lock();
|
||||
selectedWindow = null;
|
||||
}
|
||||
|
||||
fn executeCloseWindowCommand(window: *GuiWindow) void {
|
||||
main.utils.assertLocked(&mutex);
|
||||
defer updateWindowPositions();
|
||||
if(selectedWindow == window) {
|
||||
selectedWindow = null;
|
||||
@ -110,12 +109,10 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
||||
for(openWindows.items, 0..) |_openWindow, i| {
|
||||
if(_openWindow == window) {
|
||||
_ = openWindows.swapRemove(i);
|
||||
window.onCloseFn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
mutex.unlock();
|
||||
window.onCloseFn();
|
||||
mutex.lock();
|
||||
}
|
||||
};
|
||||
|
||||
@ -369,7 +366,7 @@ pub fn closeWindowFromRef(window: *GuiWindow) void {
|
||||
pub fn closeWindow(id: []const u8) void {
|
||||
for(windowList.items) |window| {
|
||||
if(std.mem.eql(u8, window.id, id)) {
|
||||
openWindowFromRef(window);
|
||||
closeWindowFromRef(window);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ const padding: f32 = 8;
|
||||
|
||||
var deleteWorldName: []const u8 = "";
|
||||
|
||||
pub fn deinit() void {
|
||||
main.globalAllocator.free(deleteWorldName);
|
||||
}
|
||||
|
||||
pub fn setDeleteWorldName(name: []const u8) void {
|
||||
main.globalAllocator.free(deleteWorldName);
|
||||
deleteWorldName = main.globalAllocator.dupe(u8, name);
|
||||
@ -48,8 +52,6 @@ pub fn onOpen() void {
|
||||
}
|
||||
|
||||
pub fn onClose() void {
|
||||
main.globalAllocator.free(deleteWorldName);
|
||||
deleteWorldName = "";
|
||||
if(window.rootComponent) |*comp| {
|
||||
comp.deinit();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user