Commit 02620f19 authored by w4t's avatar w4t

simplify themes and add custom theme to demo

parent 906dad97
Pipeline #73 failed with stages
#include "MyTheme.h"
ofColor getRandomColor()
{
return ofColor(ofRandom(0, 255), ofRandom(0, 255), ofRandom(0, 255), 255);
}
void MyTheme::setup()
{
ImGuiStyle* style = &ImGui::GetStyle();
style->WindowMinSize = ImVec2(160, 65);
style->FramePadding = ImVec2(4, 2);
style->ItemSpacing = ImVec2(6, 2);
style->ItemInnerSpacing = ImVec2(6, 4);
style->Alpha = 1.0f;
style->WindowRounding = 0.0f;
style->FrameRounding = 0.0f;
style->IndentSpacing = 6.0f;
style->ItemInnerSpacing = ImVec2(2, 4);
style->ColumnsMinSpacing = 50.0f;
style->GrabMinSize = 14.0f;
style->GrabRounding = 0.0f;
style->ScrollbarSize = 12.0f;
style->ScrollbarRounding = 0.0f;
style->Colors[ImGuiCol_Text] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_TextDisabled] = ImVec4(getRandomColor(), 0.58f);
style->Colors[ImGuiCol_WindowBg] = ImVec4(getRandomColor(), 0.70f);
style->Colors[ImGuiCol_ChildWindowBg] = ImVec4(getRandomColor(), 0.58f);
style->Colors[ImGuiCol_Border] = ImVec4(getRandomColor(), 0.00f);
style->Colors[ImGuiCol_BorderShadow] = ImVec4(getRandomColor(), 0.00f);
style->Colors[ImGuiCol_FrameBg] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(getRandomColor(), 0.78f);
style->Colors[ImGuiCol_FrameBgActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_TitleBg] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(getRandomColor(), 0.75f);
style->Colors[ImGuiCol_TitleBgActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_MenuBarBg] = ImVec4(getRandomColor(), 0.47f);
style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(getRandomColor(), 0.21f);
style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(getRandomColor(), 0.78f);
style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_CheckMark] = ImVec4(getRandomColor(), 0.80f);
style->Colors[ImGuiCol_SliderGrab] = ImVec4(getRandomColor(), 0.14f);
style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_Button] = ImVec4(getRandomColor(), 0.14f);
style->Colors[ImGuiCol_ButtonHovered] = ImVec4(getRandomColor(), 0.86f);
style->Colors[ImGuiCol_ButtonActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_Header] = ImVec4(getRandomColor(), 0.76f);
style->Colors[ImGuiCol_HeaderHovered] = ImVec4(getRandomColor(), 0.86f);
style->Colors[ImGuiCol_HeaderActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_Separator] = ImVec4(getRandomColor(), 0.32f);
style->Colors[ImGuiCol_SeparatorHovered] = ImVec4(getRandomColor(), 0.78f);
style->Colors[ImGuiCol_SeparatorActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_ResizeGrip] = ImVec4(getRandomColor(), 0.04f);
style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(getRandomColor(), 0.78f);
style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_PlotLines] = ImVec4(getRandomColor(), 0.63f);
style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_PlotHistogram] = ImVec4(getRandomColor(), 0.63f);
style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(getRandomColor(), 1.00f);
style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(getRandomColor(), 0.43f);
style->Colors[ImGuiCol_PopupBg] = ImVec4(getRandomColor(), 0.92f);
style->Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(getRandomColor(), 0.73f);
}
\ No newline at end of file
#pragma once
#include "BaseTheme.h"
#include "ofMain.h"
class MyTheme: public ofxImGui::BaseTheme
{
public:
void setup() override;
};
\ No newline at end of file
......@@ -61,7 +61,6 @@ void ofApp::setup()
void ofApp::update() {
}
bool doThemeColorsWindow = false;
//--------------------------------------------------------------
void ofApp::draw() {
......@@ -92,6 +91,19 @@ void ofApp::draw() {
}
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
if (ImGui::Button("CUSTOM THEME"))
{
gui.setTheme(new MyTheme());
}ImGui::SameLine();
if (ImGui::Button("DEFAULT THEME"))
{
gui.setTheme(new ofxImGui::DefaultTheme());
}
}
// 2. Show another window, this time using an explicit ImGui::Begin and ImGui::End
if (show_another_window) {
......@@ -138,10 +150,6 @@ void ofApp::draw() {
ImGui::Image((ImTextureID)(uintptr_t)textureSourceID, ImVec2(200, 200));
ImGui::Image(GetImTextureID(pixelsButtonID), ImVec2(200, 200));
if(doThemeColorsWindow) {
gui.openThemeColorWindow();
}
//required to call this at end
gui.end();
......
......@@ -2,7 +2,7 @@
#include "ofMain.h"
#include "ofxImGui.h"
#include "ThemeTest.h"
#include "MyTheme.h"
class ofApp : public ofBaseApp{
public:
......
#include "BaseTheme.h"
#include "imgui.h"
namespace ofxImGui
{
//--------------------------------------------------------------
BaseTheme::BaseTheme()
{
col_main_text = ofColor::white;
col_main_head = ofColor::blue;
col_main_area = ofColor::gray;
col_win_popup = ofColor::yellow;
col_win_backg = ofColor::black;
col_main_text = ofColor::fromHex(0xdbede2);
col_main_head = ofColor::fromHex(0xd12d49);
col_main_area = ofColor::fromHex(0x333844);
col_win_popup = ofColor::fromHex(0x77c4d3);
col_win_backg = ofColor::fromHex(0x21232b);
}
//--------------------------------------------------------------
void BaseTheme::setup()
{
ImGuiStyle* style = &ImGui::GetStyle();
style->WindowMinSize = ImVec2(160, 65);
style->FramePadding = ImVec2(4, 2);
style->ItemSpacing = ImVec2(6, 2);
style->ItemInnerSpacing = ImVec2(6, 4);
style->Alpha = 1.0f;
style->WindowRounding = 0.0f;
style->FrameRounding = 0.0f;
style->IndentSpacing = 6.0f;
style->ItemInnerSpacing = ImVec2(2, 4);
style->ColumnsMinSpacing = 50.0f;
style->GrabMinSize = 14.0f;
style->GrabRounding = 0.0f;
style->ScrollbarSize = 12.0f;
style->ScrollbarRounding = 0.0f;
}
//--------------------------------------------------------------
void BaseTheme::updateColors()
{
ImGuiStyle* style = &ImGui::GetStyle();
style->Colors[ImGuiCol_Text] = ImVec4(col_main_text, 1.00f);
style->Colors[ImGuiCol_TextDisabled] = ImVec4(col_main_text, 0.58f);
//style->Colors[ImGuiCol_WindowBg] = ImVec4(col_win_backg, 0.70f);
style->Colors[ImGuiCol_WindowBg] = ImVec4(col_win_backg, 1.00f);
style->Colors[ImGuiCol_ChildBg] = ImVec4(col_main_area, 0.58f);
style->Colors[ImGuiCol_Border] = ImVec4(col_win_backg, 0.00f);
style->Colors[ImGuiCol_BorderShadow] = ImVec4(col_win_backg, 0.00f);
style->Colors[ImGuiCol_FrameBg] = ImVec4(col_main_area, 1.00f);
style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_FrameBgActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_TitleBg] = ImVec4(col_main_area, 1.00f);
style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(col_main_area, 0.75f);
style->Colors[ImGuiCol_TitleBgActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_MenuBarBg] = ImVec4(col_main_area, 0.47f);
style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(col_main_area, 1.00f);
style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(col_win_popup, 0.21f);
style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_CheckMark] = ImVec4(col_main_head, 0.80f);
style->Colors[ImGuiCol_SliderGrab] = ImVec4(col_win_popup, 0.14f);
style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(col_main_head, 1.00f);
//style->Colors[ImGuiCol_Button] = ImVec4(col_win_popup, 0.14f);
style->Colors[ImGuiCol_Button] = ImVec4(col_win_popup, 0.16f);
//style->Colors[ImGuiCol_ButtonHovered] = ImVec4(col_main_head, 0.86f);
style->Colors[ImGuiCol_ButtonHovered] = ImVec4(col_main_head, 0.39f);
style->Colors[ImGuiCol_ButtonActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_Header] = ImVec4(col_main_head, 0.76f);
style->Colors[ImGuiCol_HeaderHovered] = ImVec4(col_main_head, 0.86f);
style->Colors[ImGuiCol_HeaderActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_Separator] = ImVec4(col_win_popup, 0.32f);
style->Colors[ImGuiCol_SeparatorHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_SeparatorActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_ResizeGrip] = ImVec4(col_win_popup, 0.04f);
style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_PlotLines] = ImVec4(col_main_text, 0.63f);
style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_PlotHistogram] = ImVec4(col_main_text, 0.63f);
style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(col_main_head, 0.43f);
style->Colors[ImGuiCol_PopupBg] = ImVec4(col_win_backg, 0.92f);
style->Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(col_main_area, 0.73f);
}
//--------------------------------------------------------------
inline ofColor BaseTheme::convertColor(float* f)
{
return ofColor(f[0] * 255, f[1] * 255, f[2] * 255);
}
//--------------------------------------------------------------
bool BaseTheme::addColorEdit(const std::string& label, ofColor& color)
{
bool didChange = false;
float floats[3];
floats[0] = color.r / 255.f;
floats[1] = color.g / 255.f;
floats[2] = color.b / 255.f;
didChange = ImGui::ColorEdit3(label.c_str(), &floats[0], ImGuiColorEditFlags_NoOptions);
color = convertColor(&floats[0]);
return didChange;
}
//--------------------------------------------------------------
void BaseTheme::themeColorsWindow(bool isOpen)
{
if (isOpen)
{
ImGui::SetNextWindowSize(ImVec2(421, 192), ImGuiCond_FirstUseEver);
ImGui::Begin("Theme Colors", &isOpen);
bool b1 = addColorEdit("Text", col_main_text);
bool b2 = addColorEdit("Headers", col_main_head);
bool b3 = addColorEdit("Areas", col_main_area);
bool b4 = addColorEdit("Popups", col_win_popup);
bool b5 = addColorEdit("Background", col_win_backg);
if (b1 || b2 || b3 || b4 || b5)
{
updateColors();
}
ImGui::End();
}
}
}
\ No newline at end of file
#pragma once
#include "ofColor.h"
#include "imgui.h"
namespace ofxImGui
{
class BaseTheme
{
public:
BaseTheme();
virtual ~BaseTheme() {}
virtual void setup();
void themeColorsWindow(bool isOpen);
BaseTheme()
{
void updateColors();
}
virtual ~BaseTheme()
{
ofColor col_main_text;
ofColor col_main_head;
ofColor col_main_area;
ofColor col_win_popup;
ofColor col_win_backg;
}
bool addColorEdit(const std::string& label, ofColor& color);
ofColor convertColor(float* f);
virtual void setup()=0;
};
}
#include "DefaultTheme.h"
namespace ofxImGui
{
void DefaultTheme::setup()
{
ofColor col_main_text = ofColor::fromHex(0xdbede2);
ofColor col_main_head = ofColor::fromHex(0xd12d49);
ofColor col_main_area = ofColor::fromHex(0x333844);
ofColor col_win_popup = ofColor::fromHex(0x77c4d3);
ofColor col_win_backg = ofColor::fromHex(0x21232b);
ImGuiStyle* style = &ImGui::GetStyle();
style->WindowMinSize = ImVec2(160, 65);
style->FramePadding = ImVec2(4, 2);
style->ItemSpacing = ImVec2(6, 2);
style->ItemInnerSpacing = ImVec2(6, 4);
style->Alpha = 1.0f;
style->WindowRounding = 0.0f;
style->FrameRounding = 0.0f;
style->IndentSpacing = 6.0f;
style->ItemInnerSpacing = ImVec2(2, 4);
style->ColumnsMinSpacing = 50.0f;
style->GrabMinSize = 14.0f;
style->GrabRounding = 0.0f;
style->ScrollbarSize = 12.0f;
style->ScrollbarRounding = 0.0f;
style->Colors[ImGuiCol_Text] = ImVec4(col_main_text, 1.00f);
style->Colors[ImGuiCol_TextDisabled] = ImVec4(col_main_text, 0.58f);
style->Colors[ImGuiCol_WindowBg] = ImVec4(col_win_backg, 0.70f);
style->Colors[ImGuiCol_ChildWindowBg] = ImVec4(col_main_area, 0.58f);
style->Colors[ImGuiCol_Border] = ImVec4(col_win_backg, 0.00f);
style->Colors[ImGuiCol_BorderShadow] = ImVec4(col_win_backg, 0.00f);
style->Colors[ImGuiCol_FrameBg] = ImVec4(col_main_area, 1.00f);
style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_FrameBgActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_TitleBg] = ImVec4(col_main_area, 1.00f);
style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(col_main_area, 0.75f);
style->Colors[ImGuiCol_TitleBgActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_MenuBarBg] = ImVec4(col_main_area, 0.47f);
style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(col_main_area, 1.00f);
style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(col_win_popup, 0.21f);
style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_CheckMark] = ImVec4(col_main_head, 0.80f);
style->Colors[ImGuiCol_SliderGrab] = ImVec4(col_win_popup, 0.14f);
style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_Button] = ImVec4(col_win_popup, 0.14f);
style->Colors[ImGuiCol_ButtonHovered] = ImVec4(col_main_head, 0.86f);
style->Colors[ImGuiCol_ButtonActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_Header] = ImVec4(col_main_head, 0.76f);
style->Colors[ImGuiCol_HeaderHovered] = ImVec4(col_main_head, 0.86f);
style->Colors[ImGuiCol_HeaderActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_Separator] = ImVec4(col_win_popup, 0.32f);
style->Colors[ImGuiCol_SeparatorHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_SeparatorActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_ResizeGrip] = ImVec4(col_win_popup, 0.04f);
style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(col_main_head, 0.78f);
style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_PlotLines] = ImVec4(col_main_text, 0.63f);
style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_PlotHistogram] = ImVec4(col_main_text, 0.63f);
style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(col_main_head, 1.00f);
style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(col_main_head, 0.43f);
style->Colors[ImGuiCol_PopupBg] = ImVec4(col_win_backg, 0.92f);
style->Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(col_main_area, 0.73f);
}
}
\ No newline at end of file
#pragma once
#include "BaseTheme.h"
namespace ofxImGui
{
class DefaultTheme: public ofxImGui::BaseTheme
{
public:
void setup() override;
};
}
\ No newline at end of file
......@@ -35,11 +35,12 @@ namespace ofxImGui
if (theme_)
{
setTheme(theme_);
setTheme(theme_);
}
else
{
setTheme(new BaseTheme());
DefaultTheme* defaultTheme = new DefaultTheme();
setTheme((BaseTheme*)defaultTheme);
}
ofDisableArbTex();
......@@ -114,20 +115,9 @@ namespace ofxImGui
theme = nullptr;
}
theme = theme_;
theme->updateColors();
theme->setup();
}
//--------------------------------------------------------------
void Gui::setDefaultTheme() {
setTheme(new BaseTheme());
}
//--------------------------------------------------------------
void Gui::openThemeColorWindow() {
theme->themeColorsWindow(true);
}
//--------------------------------------------------------------
GLuint Gui::loadPixels(ofPixels& pixels) {
return engine.loadTextureImage2D(pixels.getData(), (int)pixels.getWidth(), (int)pixels.getHeight());
......
......@@ -12,7 +12,7 @@
#include "EngineGLFW.h"
#endif
#include "BaseTheme.h"
#include "DefaultTheme.h"
namespace ofxImGui
{
......@@ -38,7 +38,6 @@ namespace ofxImGui
void setTheme(BaseTheme* theme);
void setDefaultTheme();
void openThemeColorWindow();
GLuint loadImage(ofImage& image);
GLuint loadImage(const std::string& imagePath);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment