Jump to content

[solved] Ultra App Kit window Hide


Slastraf
 Share

Recommended Posts

Hello,
i don thave much time to make this but here is a bug report about making a new window in U.A.K.
Therefore I am posting the whole script I got, and will tell you where the important lines are.
 

#include "pch.h"
#include <iostream>
#include <fstream>

using namespace UltraEngine;
string compileAndWrite(fstream& file, string& contentsOfWebsite);
string compileAndExport(string& contents);


bool RescaleUI(const Event& event, shared_ptr<Object> extra)
{
	auto ui = dynamic_pointer_cast<Interface>(extra);
	ui->SetScale(float(event.data) / 100.0f);
	auto window = dynamic_pointer_cast<Window>(event.source);
	window->SetShape(event.position.x, event.position.y, event.size.x, event.size.y);
	return true;
}

int main(int argc, const char* argv[])
{
	fstream sourceFile;
	string contentsOfWebsite = "";

	cout << "app starting..." << endl;
	auto displays = ListDisplays();
	displays = ListDisplays();

	auto win = CreateWindow("Slastraf Tool", 0, 0, 1000 /** displays[0]->scale*/, 600 /** displays[0]->scale*/, displays[0], WINDOW_HIDDEN | WINDOW_CENTER | WINDOW_TITLEBAR | WINDOW_RESIZABLE | WINDOW_DOUBLEBUFFERED);
	win->SetMinSize(600, 300);

	auto ui = CreateInterface(win);

	auto mainpanel = CreatePanel(0, 0, win->ClientSize().x, win->ClientSize().y, ui);
	mainpanel->SetAlignment(1, 1, 1, 1);

	auto mainmenu = CreateMenu("", mainpanel);
	int menuheight = mainmenu->GetSize().y;

	auto menu_file = CreateMenu("File", mainmenu);


	auto menu_new = CreateMenu("New", menu_file);
	auto newFileWindow = CreateWindow("Create New File", 0, 0, 420, 2 * 69, displays[0], WINDOW_HIDDEN | WINDOW_CENTER | WINDOW_TITLEBAR | WINDOW_RESIZABLE | WINDOW_DOUBLEBUFFERED);

	auto newFileUi = CreateInterface(newFileWindow);
	auto mainNewFilepanel = CreatePanel(0, 0, newFileWindow->ClientSize().x, newFileWindow->ClientSize().y, newFileUi);
	mainNewFilepanel->SetAlignment(1, 1, 1, 1);
	auto mainNewMenu = CreateMenu("", mainNewFilepanel);

	auto textfieldNew = CreateTextField(12, 10, newFileWindow->ClientSize().x*0.5, 32, mainNewMenu);
	textfieldNew->SetAlignment(1, 1, 1, 0);
	textfieldNew->SetText("untitled");
	auto menu_saveTextNewFile = CreateButton("Save and close (doesnt work yet, just hide the window)", 12+(newFileWindow->ClientSize().x*0.5), 10, newFileWindow->ClientSize().x*0.23, 32, mainNewMenu);


	auto menu_open = CreateMenu("Open File...", menu_file);

	auto menu_save = CreateMenu("Save...", menu_file);

	auto menu_export = CreateMenu("Export", menu_file);

	ui->SetScale(displays[0]->scale);
	ListenEvent(EVENT_WINDOWDPICHANGED, win, RescaleUI, ui);

	win->Show();
	win->Activate();

	shared_ptr<TreeViewNode> dragnode, destnode;

	while (true)
	{

		auto event = WaitEvent();

		switch (event.id)
		{
		case EVENT_WIDGETDROP:
			dragnode = event.source->As<TreeViewNode>();
			if (dragnode)
			{
				destnode = event.extra->As<TreeViewNode>();
				dragnode->Insert(destnode, event.data);
			}
			break;

		case EVENT_WIDGETSELECT:
			break;
		case EVENT_WIDGETACTION:

			if (event.source == menu_open)
			{
				wstring file = RequestFile(L"Open File");
				sourceFile.open(file, ios::out);
				if (!sourceFile) {
					sourceFile.close();
				}
				else {
					Notify("Opened file. Please export it later as .html to open it in browser.");
				}
				break;
			}

			if (event.source = menu_new) {

				newFileUi->SetScale(displays[0]->scale);
				ListenEvent(EVENT_WINDOWDPICHANGED, newFileWindow, RescaleUI, newFileUi);
				newFileWindow->Show();
				newFileWindow->Activate();
				break;
			}

			if (event.source == menu_save) {
				string errors = compileAndWrite(sourceFile, contentsOfWebsite);
				if (errors != "") {
					Notify(errors);
				}
				sourceFile.close();
				break;
			}

			if (event.source == menu_saveTextNewFile) {
				sourceFile.open(textfieldNew->text, ios::out);
				newFileWindow->Close();
				newFileWindow->Hide();

				newFileWindow = nullptr;
				break;
			}

			if (event.source == menu_export) {
				string errors = compileAndExport(contentsOfWebsite);
				break;
			}

			break;
		case EVENT_WINDOWCLOSE:
			return 0;
			break;
		}
	}
	return 0;
}

//writes all changes to the file, does not export it
string compileAndWrite(fstream& file, string& contentsOfWebsite)
{	
	/*
	if (contentsOfWebsite == "") {
		return "The app is empty, most likely an error.";
	}
	*/
	file << "hello thois isa a test";
	return "";
}

string compileAndExport(string& contents) {
	return "";
}

I create a button at line 53 which is on a second window.
This window is shown in line 107, so far so good but at line 124 it will not hide.

I hope you can fix this issue soon. 

Regards
Slastraf

Link to comment
Share on other sites

  • Slastraf changed the title to [solved] Ultra App Kit window Hide

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...