rust-cgui 0.1.15

A low-level cross-platform GUI library
Documentation
//usr/bin/env g++ -std=c++11 -ldl $0 && exec sh -c "./a.out ; rm ./a.out" || exec echo compile failed

#include <iostream>

#include <functional>
#include <cstdint>
#include <unistd.h>

#include "src/cgui.hpp"

void write_rect(CGui w, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, uint8_t red, uint8_t green, uint8_t blue) {
  for (int x=x1; x < x2; x++) {
    for (int y=y1; y < y2; y++) {
      w.write_px(x, y, red, green, blue);
    }
  }
}

int main(int argc, char** argv) {
  std::cout << "Inside C++ code..." << std::endl;
  
  CGui w;
  w.init();
  
  int square_size = 5;
  int x = 15;
  int y = 15;
  
  while (true) {
    std::string event = w.event_tick();
    std::cout << "got event " << event << std::endl;
    
    if (event == "WinShown") {
      // Draw a blue bg
      write_rect(w, 0,0, 300,200, 0,0,0);
      // and a red square
      write_rect(w, x,y, x+square_size,y+square_size, 255,255,255);
      w.redraw_dirty();
    }
    else if (event == "KeyPress,q") {
      break;
    }
    else if (event == "KeyPress,w" || event == "KeyPress,a" || event == "KeyPress,s" || event == "KeyPress,d") {
      // erase current square
      write_rect(w, x,y, x+square_size,y+square_size, 0,0,0);
      if (event == "KeyPress,w" && y - square_size > 0) {
        y -= square_size;
      }
      else if (event == "KeyPress,a" && x - square_size > 0) {
        x -= square_size;
      }
      else if (event == "KeyPress,s" && y + square_size < 300) {
        y += square_size;
      }
      else if (event == "KeyPress,d" && x + square_size < 300) {
        x += square_size;
      }
      // Write red square and flush
      write_rect(w, x,y, x+square_size,y+square_size, 255,255,255);
      w.redraw_dirty();
    }
    
    
  }
  
  return 0;
}