1
// Simple immediate mode UI implementation.
3
// Heavily inspired by Sol's tutorial at http://sol.gfxile.net/imgui/.
5
// A common pattern is Adapter classes for changing how things are drawn
6
// in lists, for example.
8
// Immediate UI works great for overlay UI for games, for example, but is actually
9
// not really a good idea for full app UIs. Also, animations are difficult because
10
// there's not really any good place to store state.
16
// Simple ID generators. Absolutely no guarantee of collision avoidance if you implement
17
// multiple parts of a single screen of UI over multiple files unless you use IMGUI_SRC_ID.
19
#define GEN_ID (int)((IMGUI_SRC_ID) + (__LINE__))
20
#define GEN_ID_LOOP(i) (int)((IMGUI_SRC_ID) + (__LINE__) + (i) * 13612)
22
#define GEN_ID (__LINE__)
23
#define GEN_ID_LOOP(i) ((__LINE__) + ((int)i) * 13612)
29
#include "gfx_es2/draw_buffer.h"
30
#include "input/input_state.h"
36
// This is the drawbuffer used for UI. Remember to flush it at the end of the frame.
37
// TODO: One should probably pass it in through UIInit.
38
extern DrawBuffer ui_draw2d;
39
extern DrawBuffer ui_draw2d_front; // for things that need to be on top of the rest
41
// TODO: These don't really belong here.
43
// Implement this interface to style your lists
46
virtual size_t getCount() const = 0;
47
virtual void drawItem(int item, int x, int y, int w, int h, bool active) const = 0;
48
virtual float itemHeight(int itemIndex) const { return 64; }
49
virtual bool itemEnabled(int itemIndex) const { return true; }
52
class StringVectorListAdapter : public UIListAdapter {
54
StringVectorListAdapter(const std::vector<std::string> *items) : items_(items) {}
55
virtual size_t getCount() const { return items_->size(); }
56
virtual void drawItem(int item, int x, int y, int w, int h, bool active) const;
59
const std::vector<std::string> *items_;
63
// Call at start of frame
64
void UIBegin(Thin3DShaderSet *shaderSet);
66
// Call at end of frame.