Welcome, Guest

Author Topic: How do I use standard collections with the binding?  (Read 2183 times)


  • Administrator
  • *****
  • Posts: 475
    • View Profile
How do I use standard collections with the binding?
« on: November 04, 2013, 01:00:10 PM »
You just need to include the appropriate header for you, e.g.
Code: [Select]
#include <Coherent/UI/Binding/String.h>

There are also built-in headers for Map, Vector, stack arrays and others.

This is a simple example of binding a std::vector and std::map:
Code: [Select]
#include <Coherent/UI/View.h>
#include <vector>
#include <map>

#include <Coherent/UI/Binding/Binding.h>
#include <Coherent/UI/Binding/String.h>
#include <Coherent/UI/Binding/Vector.h>
#include <Coherent/UI/Binding/Map.h>

struct ScoreRecord
ScoreRecord(const std::string& player, int kills, double cash)
: Player(player)
, Kills(kills)
, Cash(cash)
std::string Player;
int Kills;
double Cash;

void CoherentBind(Coherent::UI::Binder* binder, ScoreRecord* record)
if (auto type = binder->RegisterType("ScoreRecord", record))
type.Property("Player", &ScoreRecord::Player)
.Property("Kills", &ScoreRecord::Kills)
.Property("Cash", &ScoreRecord::Cash)

void ShowScoreboard(Coherent::UI::View* view)
std::vector<ScoreRecord> board;
board.push_back(ScoreRecord("John Doe", 0, 100));
board.push_back(ScoreRecord("Jane Smith", 10, 4.2));

std::map<std::string, ScoreRecord> mappedBoard;
mappedBoard["John Doe"] = board[0];

view->TriggerEvent("showScoreboard", board, mappedBoard);

R&D Director @CoherentLabs