Пример #1
0
void nk_menu_wnd_main(nk_menu_handle_t *zr)
{
   struct nk_panel layout;
   struct nk_context *ctx = &zr->ctx;
   const int id           = ZRMENU_WND_MAIN;
   settings_t *settings   = config_get_ptr();

   if (nk_begin(ctx, &layout, "Main", nk_rect(-1, -1, 120, zr->size.x + 1),
         NK_WINDOW_NO_SCROLLBAR))
   {
      struct nk_panel menu;
      struct nk_panel node, context_menu;

      /* context menu */

      /* main menu */
      nk_menubar_begin(ctx);
      nk_layout_row_begin(ctx, NK_STATIC, 25, 1);
      nk_layout_row_push(ctx, 100);

      nk_layout_row_push(ctx, 60);
      nk_menubar_end(ctx);
   }


   /* save position and size to restore after context reset */
   nk_menu_set_state(zr, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
   if (zr->size_changed)
      nk_window_set_size(ctx, nk_vec2(nk_window_get_size(ctx).x, zr->size.y));

   nk_end(ctx);
}
Пример #2
0
void drawUI(nk_context* ctx, nk_colorf& bg)
{
    nk_glfw3_new_frame();

    /* GUI */
	if (nk_begin(ctx, "Buttons", nk_rect(1093, 0, 273, 360),
		NK_WINDOW_BORDER | NK_WINDOW_BACKGROUND)) {
		
		nk_layout_row_static(ctx, 30, 80, 1);
		nk_label(ctx, "Actions", NK_TEXT_LEFT);

		nk_layout_row_static(ctx, 30, 100, 2);
		if (nk_button_label(ctx, "Pause")) {
			Logger::ButtonPress(3);
			if (Controller::getInstance().state != Controller::paused) {
				prevstate = Controller::getInstance().state;
				Controller::getInstance().state = Controller::paused;
			}
		}
		if (nk_button_label(ctx, "Continue")) {
			Logger::ButtonPress(1);
			if (Controller::getInstance().state > 1)
				Controller::getInstance().state = prevstate;
		}
		if (nk_button_label(ctx, "Generate")) {
			Logger::ButtonPress(2);
			Controller::getInstance().way = Controller::getInstance().solver.Solve();

			if (Controller::getInstance().state == Controller::idle)
				Controller::getInstance().state = Controller::prepare;
		}
		if (nk_button_label(ctx, "Stop")) {
			Logger::ButtonPress(0);
			if (Controller::getInstance().way[0])
				Controller::getInstance().way = std::vector<spin>(1, Controller::getInstance().way[0]);
		}

		nk_layout_row_static(ctx, 30, 80, 1);
		nk_label(ctx, "Manual inputs", NK_TEXT_LEFT);

		nk_layout_row_begin(ctx, NK_STATIC, 30, 3); {

			nk_layout_row_push(ctx, 60);
			if (nk_button_label(ctx, "Left")) {
				wayoverride(WL);
			}
			nk_label(ctx, "White", NK_TEXT_CENTERED);
			if (nk_button_label(ctx, "Right")) {
				wayoverride(WR);
			}

			nk_layout_row_push(ctx, 60);
			if (nk_button_label(ctx, "Left")) {
				wayoverride(YL);
			}
			nk_label(ctx, "Yellow", NK_TEXT_CENTERED);
			if (nk_button_label(ctx, "Right")) {
				wayoverride(YR);
			}

			nk_layout_row_push(ctx, 60);
			if (nk_button_label(ctx, "Left")) {
				wayoverride(RL);
			}
			nk_label(ctx, "Red", NK_TEXT_CENTERED);
			if (nk_button_label(ctx, "Right")) {
				wayoverride(RR);
			}

			nk_layout_row_push(ctx, 60);
			if (nk_button_label(ctx, "Left")) {
				wayoverride(BL);
			}
			nk_label(ctx, "Blue", NK_TEXT_CENTERED);
			if (nk_button_label(ctx, "Right")) {
				wayoverride(BR);
			}

			nk_layout_row_push(ctx, 60);
			if (nk_button_label(ctx, "Left")) {
				wayoverride(OL);
			}
			nk_label(ctx, "Orange", NK_TEXT_CENTERED);
			if (nk_button_label(ctx, "Right")) {
				wayoverride(OR);
			}

			nk_layout_row_push(ctx, 60);
			if (nk_button_label(ctx, "Left")) {
				wayoverride(GL);
			}
			nk_label(ctx, "Green", NK_TEXT_CENTERED);
			if (nk_button_label(ctx, "Right")) {
				wayoverride(GR);
			}
		}
		nk_layout_row_end(ctx);
	}

    nk_end(ctx);

	if (nk_begin(ctx, "Code", nk_rect(1093, 350, 273, 350),
		NK_WINDOW_BORDER)) {

		static char linenums[256];
		std::string buf;
		std::istringstream str(Compiler::code);
		int linecount = 0;
		strcpy(linenums, "");
		while (std::getline(str, buf)) strcat(linenums, (std::to_string(++linecount) + "\n").c_str());
		strcat(linenums, (std::to_string(++linecount) + "\n").c_str());

		nk_layout_row_begin(ctx, NK_STATIC, 200, 2); {
			nk_layout_row_push(ctx, 40);
			if (nk_group_begin(ctx, "nums", NK_WINDOW_NO_SCROLLBAR)) {
				nk_layout_row_static(ctx, 1000, 40, 1);
				nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX, linenums, sizeof(linenums), nk_filter_default);
				nk_group_end(ctx);
			} 

			nk_layout_row_push(ctx, 200);
			if (nk_group_begin(ctx, "text", 0)) {
				nk_layout_row_static(ctx, 1000, 176, 1);
				nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX, Compiler::code, sizeof(Compiler::code), nk_filter_default);
				nk_group_end(ctx);
			}

			nk_uint *x = new nk_uint(0), *y = new nk_uint(0);
			nk_group_get_scroll(ctx, "text", x, y);
			nk_group_set_scroll(ctx, "nums", *x, *y);
			delete(x); delete(y);
		}

		nk_layout_row_begin(ctx, NK_STATIC, 30, 2); {
			nk_layout_row_push(ctx, 60);
			if (nk_button_label(ctx, "Run")) {
				Compiler::Compile();
			}
			if (nk_button_label(ctx, "Save")) {
				Compiler::Save();
			}
		}

		nk_layout_row_dynamic(ctx, 200, 1);
		nk_edit_string_zero_terminated(ctx, NK_EDIT_BOX, Compiler::output, sizeof(Compiler::output), nk_filter_default);
	}

	nk_end(ctx);
}