Advertisement
snake5

some ui code

Jul 15th, 2019
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. struct OpenClose : UINode
  2. {
  3.     void Render(UIContainer* ctx) override
  4.     {
  5.         ctx->PushBox();
  6.  
  7.         cb = ctx->Element<UICheckbox>();
  8.         cb->SetValue(open);
  9.  
  10.         openBtn = ctx->Element<UIButton>();
  11.         openBtn->SetText("Open");
  12.  
  13.         closeBtn = ctx->Element<UIButton>();
  14.         closeBtn->SetText("Close");
  15.  
  16.         if (open)
  17.         {
  18.             ctx->PushBox();
  19.             ctx->Text("It is open!");
  20.             ctx->Pop();
  21.         }
  22.  
  23.         ctx->Pop();
  24.     }
  25.     void OnEvent(UIEvent& e) override
  26.     {
  27.         if (e.type == UIEventType::Click)
  28.         {
  29.             if (e.target == openBtn || e.target == closeBtn)
  30.             {
  31.                 open = e.target == openBtn;
  32.                 e.context->Rebuild(this);
  33.             }
  34.         }
  35.         if (e.type == UIEventType::Change)
  36.         {
  37.             if (e.target == cb)
  38.             {
  39.                 open = cb->GetValue();
  40.                 e.context->Rebuild(this);
  41.             }
  42.         }
  43.     }
  44.  
  45.     bool open = false;
  46.  
  47.     UICheckbox* cb;
  48.     UIButton* openBtn;
  49.     UIButton* closeBtn;
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement