mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-07 19:21:14 -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 {
|
fn executeCommands() void {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
defer mutex.unlock();
|
const commands_ = main.stackAllocator.dupe(Command, commands.items);
|
||||||
while(commands.popOrNull()) |command| {
|
defer main.stackAllocator.free(commands_);
|
||||||
|
commands.clearAndFree();
|
||||||
|
mutex.unlock();
|
||||||
|
for(commands_) |command| {
|
||||||
switch(command.action) {
|
switch(command.action) {
|
||||||
.open => {
|
.open => {
|
||||||
executeOpenWindowCommand(command.window);
|
executeOpenWindowCommand(command.window);
|
||||||
@ -84,7 +87,6 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn executeOpenWindowCommand(window: *GuiWindow) void {
|
fn executeOpenWindowCommand(window: *GuiWindow) void {
|
||||||
main.utils.assertLocked(&mutex);
|
|
||||||
defer updateWindowPositions();
|
defer updateWindowPositions();
|
||||||
for(openWindows.items, 0..) |_openWindow, i| {
|
for(openWindows.items, 0..) |_openWindow, i| {
|
||||||
if(_openWindow == window) {
|
if(_openWindow == window) {
|
||||||
@ -95,14 +97,11 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
openWindows.append(window);
|
openWindows.append(window);
|
||||||
mutex.unlock();
|
|
||||||
window.onOpenFn();
|
window.onOpenFn();
|
||||||
mutex.lock();
|
|
||||||
selectedWindow = null;
|
selectedWindow = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn executeCloseWindowCommand(window: *GuiWindow) void {
|
fn executeCloseWindowCommand(window: *GuiWindow) void {
|
||||||
main.utils.assertLocked(&mutex);
|
|
||||||
defer updateWindowPositions();
|
defer updateWindowPositions();
|
||||||
if(selectedWindow == window) {
|
if(selectedWindow == window) {
|
||||||
selectedWindow = null;
|
selectedWindow = null;
|
||||||
@ -110,12 +109,10 @@ const GuiCommandQueue = struct { // MARK: GuiCommandQueue
|
|||||||
for(openWindows.items, 0..) |_openWindow, i| {
|
for(openWindows.items, 0..) |_openWindow, i| {
|
||||||
if(_openWindow == window) {
|
if(_openWindow == window) {
|
||||||
_ = openWindows.swapRemove(i);
|
_ = openWindows.swapRemove(i);
|
||||||
|
window.onCloseFn();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mutex.unlock();
|
|
||||||
window.onCloseFn();
|
|
||||||
mutex.lock();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -369,7 +366,7 @@ pub fn closeWindowFromRef(window: *GuiWindow) void {
|
|||||||
pub fn closeWindow(id: []const u8) void {
|
pub fn closeWindow(id: []const u8) void {
|
||||||
for(windowList.items) |window| {
|
for(windowList.items) |window| {
|
||||||
if(std.mem.eql(u8, window.id, id)) {
|
if(std.mem.eql(u8, window.id, id)) {
|
||||||
openWindowFromRef(window);
|
closeWindowFromRef(window);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,10 @@ const padding: f32 = 8;
|
|||||||
|
|
||||||
var deleteWorldName: []const u8 = "";
|
var deleteWorldName: []const u8 = "";
|
||||||
|
|
||||||
|
pub fn deinit() void {
|
||||||
|
main.globalAllocator.free(deleteWorldName);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setDeleteWorldName(name: []const u8) void {
|
pub fn setDeleteWorldName(name: []const u8) void {
|
||||||
main.globalAllocator.free(deleteWorldName);
|
main.globalAllocator.free(deleteWorldName);
|
||||||
deleteWorldName = main.globalAllocator.dupe(u8, name);
|
deleteWorldName = main.globalAllocator.dupe(u8, name);
|
||||||
@ -48,8 +52,6 @@ pub fn onOpen() void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
main.globalAllocator.free(deleteWorldName);
|
|
||||||
deleteWorldName = "";
|
|
||||||
if(window.rootComponent) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user