Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
2018 April 26th

eric bachard
Resync'ed the code with Dear ImGui 1.61 WIP
Added IMGUI_VERSION_160_OR_MINUX GUARD for old code
Simplified the interface :
-removed :ImGuiUserCol_TabHover, ImGuiUserCol_TabTitleTextNormal, ImGuiUserCol_TabTitleTextSelected,
- now using ImGui themes
- added StyleColorsLightGreen() theme, since it is miniDart legacy theme
- removed duplicated code
Tested ok using miniDart
The code builds OK when cross-compiling (target : Windows7+ 64 and 32 bits)

2018 July 21
DrawTabsBackground added by eric bachard (Jul 21, 2017) under the same license
See : https://github.com/ebachard/imgui_tabs
and https://github.com/ScottMudge/imgui_tabs/issues/1
5 changes: 5 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


DrawTabsBackground added by eric bachard (Jul 21, 2017) under the same license
See : https://github.com/ebachard/imgui_tabs
and https://github.com/ScottMudge/imgui_tabs/issues/1
200 changes: 154 additions & 46 deletions imgui_tabs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
* SOFTWARE.
*
* **************************************************************************************/
// 2017-2018 : some changes made by eric bachard. See the Changelog
// File Name: imgui_tabs.cpp
// File Description: Custom ImGui tab system module


#include "imgui_tabs.h"

ImGui::ImGuiUserStyle::ImGuiUserStyle(){
Colors[ImGuiUserCol_TabNormal] = ImVec4(0.65f, 0.65f, 0.68f, 1.00f);
Colors[ImGuiUserCol_TabTitleTextNormal] = ImVec4(0.0f, 0.0f, 0.0f, 0.5f);
Colors[ImGuiUserCol_TabTitleTextSelected] = ImVec4(1.0f, 1.0f, 1.0f, 1.00f);
// define this constant in the case you are using ImGUI < 1.51
// #define IMGUI_VERSION_150_OR_MINUS

ImGui::ImGuiUserStyle::ImGuiUserStyle()
{
Colors[ImGuiUserCol_TabNormal] = ImVec4(0.69f, 0.69f, 0.69f, 1.00/*0.70f*/);
Colors[ImGuiUserCol_TabBorder] = Colors[ImGuiUserCol_TabNormal] * ImVec4(1.15f,1.15f,1.15f,1.0f);
Colors[ImGuiUserCol_TabBorderShadow] = Colors[ImGuiUserCol_TabNormal] * ImVec4(0.65f,0.65f,0.65f,1.0f);
Colors[ImGuiUserCol_TabHover] = Colors[ImGuiUserCol_TabNormal] * ImVec4(1.15f,1.15f,1.15f,1.0f);
}

const ImU32 ImGui::GetColorU32(ImGuiUserCol_ idx, float alpha_mul) {
Expand Down Expand Up @@ -103,27 +105,30 @@ void ImGui::_drawPartialRect(const ImVec2 a, const ImVec2 b, const float roundin
dl->PathArcToFast(ImVec2(a.x+r3-shadow_offset,b.y-r3), r3, 3, 6);
dl->PathArcToFast(ImVec2(a.x+r0-shadow_offset,a.y+r0), r0, 6, 9);
dl->PathLineTo(ImVec2(a.x,b.y));
dl->PathFill(col);
dl->PathFillConvex(col);
} if (shadow_edges & EDGE_RIGHT){
dl->PathArcToFast(ImVec2(b.x-r1+shadow_offset,a.y+r1), r1, 9, 12);
dl->PathArcToFast(ImVec2(b.x-r2+shadow_offset,b.y-r2), r2, 0, 3);
dl->PathLineTo(ImVec2(b.x,b.y));
dl->PathFill(col);
dl->PathFillConvex(col);
}
}
}
}

ImGui::TabBar::TabBar(const char *label, const ImVec2 tab_bar_size) {
ImGui::TabBar::TabBar(const char *label, const ImVec2 tab_bar_size)
{
hash = ImHash(label,0);
size = tab_bar_size;
}

void ImGui::TabBar::setActiveTab(const unsigned idx) {
void ImGui::TabBar::setActiveTab(const unsigned idx)
{
activeTab = (int)idx; // This get's checked at the beginning of
}

const int ImGui::TabBar::getActiveTab() {
const int ImGui::TabBar::getActiveTab()
{
return activeTab;
}

Expand All @@ -133,11 +138,12 @@ void ImGui::TabBar::_drawTabBarTop(const char *label) {
// Gather pointers and references
ImGuiWindow* wind = ImGui::GetCurrentWindow();
ImDrawList* dl = wind->DrawList;
ImGuiDrawContext& dc = wind->DC;
ImGuiWindowTempData& dc = wind->DC;
ImGuiStyle& style = ImGui::GetStyle();
std::string str = label;

barTitle = str.substr(0,str.find_first_of("#"));

if (barTitle.length()>0)
ImGui::Text(std::string("\t"+barTitle).c_str(), "%s");

Expand All @@ -148,17 +154,22 @@ void ImGui::TabBar::_drawTabBarTop(const char *label) {
const float division = ((wind->Size.x - 2*padding.x)/(float)tabCount);

// Compile-time constants
static constexpr const float rounding = 6.0f;
// static constexpr const float rounding = 6.0f;
// ericb limit tabs rounding, to keep the consistence with the current theme
static constexpr const float rounding = 3.0f;
// This is the border shrink in px. Not sure why it needs to be 1, but it works. Adjust to your border size
static constexpr const float shrink = 1.0f;

const float tab_height = CalcTextSize(tabTitles[0]).y + (frame_padding.y * 2);
// ericb ajouté 2.0, parce que pas assez d'espace
const float tab_height = CalcTextSize(tabTitles[0]).y + (frame_padding.y * 2) + 6.0;

float selected_offset = 0;
_TabType selected_tab_type;
// FIXME unused
// _TabType selected_tab_type;
ImVec2 selected_expands;
_EdgeType selected_shadow_edges = EDGE_NONE;
int selected_idx = 0;

// Store maximum/minimum x value for clipping rect.
const float max_x = wind->Pos.x + wind->Size.x - padding.x; // Used for clipping rect adjustment.
const float min_x = wind->Pos.x + padding.x;
Expand All @@ -170,14 +181,16 @@ void ImGui::TabBar::_drawTabBarTop(const char *label) {
newSelected = -1;

// Draw the tabs
for (int i = 0; i<tabCount; i++) {
for (int i = 0; i<tabCount; i++)
{


// Calculate offset
const float offs = i * division;
const bool selected = (activeTab == i);
ImVec2 expands;
if (!selected) {
if (!selected)
{
if (i == 0) {
expands = ImVec2(0,2);
} else if (i == tabCount - 1) {
Expand All @@ -190,59 +203,71 @@ void ImGui::TabBar::_drawTabBarTop(const char *label) {
const float xr = offs + division - shrink + expands.y;
const ImRect bb = ImRect(ImVec2(pos + ImVec2(xl, 0)),ImVec2( pos + ImVec2(xr, tab_height)));

bool hovered, held;
bool pressed = ButtonBehavior(bb, tabHashes[i], &hovered, &held);
bool hovered = false;
bool held = false;
ButtonBehavior(bb, tabHashes[i], &hovered, &held);

if (held)
newSelected = i;


ImU32 col;
hovered ? col = GetColorU32(ImGuiUserCol_TabHover) : col = GetColorU32(ImGuiUserCol_TabNormal);
hovered ? col = GetColorU32(ImGuiCol_ButtonHovered) : col = GetColorU32(ImGuiCol_Button);

// Draw background rect
dl->AddRectFilled(bb.Min, bb.Max, col, rounding,
ImGuiCorner_TopLeft | ImGuiCorner_TopRight);
dl->AddRectFilled(bb.Min, bb.Max, col, rounding, ImDrawCornerFlags_All);

// Draw the border
_drawPartialRect(bb.Min, bb.Max,rounding, ImGuiCorner_TopLeft | ImGuiCorner_TopRight, dl,
_drawPartialRect(bb.Min, bb.Max,rounding, ImDrawCornerFlags_All, dl,
(_EdgeType) (EDGE_LEFT | EDGE_RIGHT | EDGE_TOP), GetColorU32(ImGuiUserCol_TabBorderShadow));
// Draw the text
const ImVec2 text_size = CalcTextSize(tabTitles[i]);
const ImVec2 text_pos = pos + ImVec2(offs+((xr-xl) - text_size.x)/2.0f,((text_size.y - frame_padding.y*2.0f)/2.0f));
dl->AddText(text_pos,GetColorU32(ImGuiUserCol_TabTitleTextNormal),tabTitles[i]);
dl->AddText(text_pos,GetColorU32(ImGuiCol_Text),tabTitles[i]);


} else{
}
else
{
selected_offset = offs;
selected_idx = i;
if (i == 0) {
if (i == 0)
{
selected_expands = ImVec2(0,rounding);
selected_shadow_edges = EDGE_RIGHT;
} else if (i == tabCount - 1) {
}
else if (i == tabCount - 1)
{
selected_expands = ImVec2(rounding,0);
selected_shadow_edges = EDGE_LEFT;
} else {
}
else
{
selected_expands = ImVec2(rounding,rounding);
selected_shadow_edges = (_EdgeType)(EDGE_RIGHT | EDGE_LEFT);
}

}
}

const float xl = selected_offset - selected_expands.x + shrink;
const float xr = selected_offset + division - shrink + selected_expands.y;
const ImRect bb = ImRect(ImVec2(pos + ImVec2(xl, 0)),ImVec2( pos + ImVec2(xr, tab_height)));

// Draw the selected tab on top of everything else
dl->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiUserCol_TabNormal), rounding, ImGuiCorner_TopLeft | ImGuiCorner_TopRight);

dl->AddRectFilled(bb.Min, bb.Max, ImColor(1.0f, 1.0f, 1.0f, 0.35f), rounding, ImGuiCorner_TopLeft | ImGuiCorner_TopRight);
// current theme
dl->AddRectFilled(bb.Min, bb.Max,GetColorU32(ImGuiCol_ButtonActive), rounding, ImDrawCornerFlags_All);

// Draw the border
_drawPartialRect(bb.Min, bb.Max,rounding, ImGuiCorner_TopLeft | ImGuiCorner_TopRight, dl,
_drawPartialRect(bb.Min, bb.Max,rounding, ImDrawCornerFlags_All, dl,
(_EdgeType) (EDGE_LEFT | EDGE_RIGHT | EDGE_TOP), GetColorU32(ImGuiUserCol_TabBorderShadow),
true,selected_shadow_edges);
// Draw the text

// at the end ... draw the text
const ImVec2 text_size = CalcTextSize(tabTitles[selected_idx]);
const ImVec2 text_pos = pos + ImVec2(selected_offset+((xr-xl) - text_size.x)/2.0f - selected_expands.x,((text_size.y - frame_padding.y*2.0f)/2.0f));
dl->AddText(text_pos+ImVec2(1,1),GetColorU32(ImGuiUserCol_TabTitleTextNormal),tabTitles[selected_idx]); // Shadow
dl->AddText(text_pos,GetColorU32(ImGuiUserCol_TabTitleTextSelected),tabTitles[selected_idx]);
const ImVec2 text_pos = pos + ImVec2(selected_offset+((xr-xl) - text_size.x)/2.0f + 2.0f - selected_expands.x,((text_size.y - frame_padding.y*2.0f)/2.0f));

// shadow or not shadow ?
dl->AddText(text_pos,GetColorU32(ImGuiCol_Text),tabTitles[selected_idx]);

dc.CursorPos += ImVec2(0,tab_height + padding.y); // Add all the extra height used above.
upperLeft = dc.CursorPos - ImVec2(0,padding.y);
Expand All @@ -255,7 +280,7 @@ void ImGui::TabBar::_drawTabBarBottom() {
ImGuiWindow* wind = ImGui::GetCurrentWindow();
ImDrawList* dl = wind->DrawList;
ImGuiStyle& style = ImGui::GetStyle();
ImGuiDrawContext& dc = wind->DC;
ImGuiWindowTempData& dc = wind->DC;

const ImVec2 padding = style.WindowPadding;

Expand All @@ -264,18 +289,21 @@ void ImGui::TabBar::_drawTabBarBottom() {
// the zero below the tabs is dc.CursorPos.y - padding.y
// and if we wnt to add the tab height, we'll have to remove a constant
// (= all the additional offsets used for the layout). FIXME : use the real name(s) instead
const float height = dc.CursorPos.y - padding.y + wind->Size.y - 92.0f;
const float additionnalOffset_y = 67.0f;//53.0f;//92.0f;// 63.0f;
const float height = dc.CursorPos.y - padding.y + wind->Size.y - additionnalOffset_y;
const ImVec2 pos = ImVec2(wind->Pos.x + wind->Size.x - padding.x, height);

// Draw the background in a given color + alpha
dl->AddRectFilled(upperLeft, pos,ImColor(1.0f,1.0f,1.0f,0.15f),corner_rounding,ImGuiCorner_BottomLeft | ImGuiCorner_BottomRight);
dl->AddRectFilled(upperLeft, pos,ImColor(1.0f,1.0f,1.0f,0.15f),corner_rounding,ImDrawCornerFlags_All);

// Draw the border in a given color + alpha
dl->AddRect(upperLeft, pos,ImColor(1.0f,1.0f,1.0f,0.35f),corner_rounding,ImGuiCorner_BottomLeft | ImGuiCorner_TopRight);
dl->AddRect(upperLeft, pos,ImColor(0.2f,0.2f,0.2f,0.35f),corner_rounding,ImDrawCornerFlags_All);

dc.CursorPos += ImVec2(0,corner_rounding+2.0f); // Add all the extra height used above.
ImGui::PopClipRect();
}


void ImGui::TabBar::_setTabCount() {
if (newSelected >= 0 ){
activeTab = newSelected;
Expand Down Expand Up @@ -343,7 +371,8 @@ void ImGui::BeginTabBar(const char *label, const ImVec2 size) {
TabStack.getCurrentTabBar()->_drawTabBarTop(label);
}

const bool ImGui::AddTab(const char *title) {
const bool ImGui::AddTab(const char *title)
{
// Get current TabBar;
TabBar* bar = TabStack.getCurrentTabBar();
// Check to make sure there aren't any null pointers
Expand Down Expand Up @@ -377,9 +406,88 @@ void ImGui::EndTabBar() {
bar->_setTabCount();
}

/* FIXME : unused ?
void ImGui::SetActiveTabOfCurrentTabBar(const unsigned idx) {
TabStack.getCurrentTabBar()->setActiveTab(idx);
// Legacy miniDart theme
void ImGui::StyleColorsLightGreen(ImGuiStyle* dst)
{
ImGuiStyle* style = dst ? dst : &ImGui::GetStyle();
ImVec4* colors = style->Colors;

style->WindowRounding = 2.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
style->ScrollbarRounding = 3.0f; // Radius of grab corners rounding for scrollbar
style->GrabRounding = 2.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
style->AntiAliasedLines = true;
style->AntiAliasedFill = true;
style->WindowRounding = 2.0f;
style->ChildRounding = 2.0f;
style->ScrollbarSize = 16.0f;
style->ScrollbarRounding = 3.0f;
style->GrabRounding = 2.0f;
style->ItemSpacing.x = 10.0f;
style->ItemSpacing.y = 4.0f;
style->IndentSpacing = 22.0f;
style->FramePadding.x = 6.0f;
style->FramePadding.y = 4.0f;
style->Alpha = 1.0f;
style->FrameRounding = 3.0f;

colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
//colors[ImGuiCol_TextHovered] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
//colors[ImGuiCol_TextActive] = ImVec4(1.00f, 1.00f, 0.00f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
// unused ??
colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
// ??
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.93f, 0.93f, 0.93f, 0.98f);
colors[ImGuiCol_Border] = ImVec4(0.71f, 0.71f, 0.71f, 0.08f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.04f);
colors[ImGuiCol_FrameBg] = ImVec4(0.71f, 0.71f, 0.71f, 0.55f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.94f, 0.94f, 0.94f, 0.55f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.71f, 0.78f, 0.69f, 0.98f);
colors[ImGuiCol_TitleBg] = ImVec4(0.85f, 0.85f, 0.85f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.82f, 0.78f, 0.78f, 0.51f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.78f, 0.78f, 0.78f, 1.00f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.25f, 0.30f, 0.61f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.90f, 0.90f, 0.90f, 0.30f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.92f, 0.92f, 0.92f, 0.78f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.184f, 0.407f, 0.193f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.71f, 0.78f, 0.69f, 0.40f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.725f, 0.805f, 0.702f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.793f, 0.900f, 0.836f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.71f, 0.78f, 0.69f, 0.31f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.71f, 0.78f, 0.69f, 0.80f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.71f, 0.78f, 0.69f, 1.00f);
// 1.61 ?
colors[ImGuiCol_Column] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
colors[ImGuiCol_ColumnHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
colors[ImGuiCol_ColumnActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.14f, 0.44f, 0.80f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.14f, 0.44f, 0.80f, 1.00f);
////
colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.00f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.45f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
#ifdef IMGUI_VERSION_160_OR_MINUS
// obsolete since ImGui 1.61
style->colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, 0.50f);
style->colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.98f, 0.98f, 1.00f);
style->colors[ImGuiCol_CloseButtonHovered] = ImVec4(1.00f, 0.43f, 0.35f, 0.90f);
#endif

colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);

colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
colors[ImGuiCol_NavHighlight] = colors[ImGuiCol_HeaderHovered];
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(0.70f, 0.70f, 0.70f, 0.70f);
}
*/

Loading