mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-09 00:05:46 +00:00
Add option TESSESFRAMEWORK_DEFINE_SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
This commit is contained in:
29
include/TessesFramework/SDL2/Views/TabView.hpp
Normal file
29
include/TessesFramework/SDL2/Views/TabView.hpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||||
|
#include "../GUI.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::Framework::SDL2::Views
|
||||||
|
{
|
||||||
|
class TabView : public ContainerView {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::vector<std::pair<std::string,std::pair<View*,bool>>> items;
|
||||||
|
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
|
||||||
|
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TabView();
|
||||||
|
TabView(bool tabsVisible);
|
||||||
|
bool tabsVisible;
|
||||||
|
size_t firstTab;
|
||||||
|
size_t selectedTab;
|
||||||
|
|
||||||
|
void AddTab(std::string name, View* view, bool owns=true);
|
||||||
|
void RemoveTab(View* view);
|
||||||
|
void Clear();
|
||||||
|
virtual size_t ViewCount();
|
||||||
|
virtual View* GetViewAt(size_t index);
|
||||||
|
~TabView();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
121
src/SDL2/Views/TabView.cpp
Normal file
121
src/SDL2/Views/TabView.cpp
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||||
|
#include "TessesFramework/SDL2/Views/TabView.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::Framework::SDL2::Views
|
||||||
|
{
|
||||||
|
void TabView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||||
|
{
|
||||||
|
auto view = this->GetViewAt(0);
|
||||||
|
auto win =this->GetWindow();
|
||||||
|
if(this->tabsVisible)
|
||||||
|
{
|
||||||
|
|
||||||
|
int h =
|
||||||
|
win->monospaced_font->MaxHeight() + (win->palette.borderSize*3);
|
||||||
|
|
||||||
|
SDL_Rect viewBounds = {
|
||||||
|
.x=r.x,
|
||||||
|
.y=h+r.y,
|
||||||
|
.w=r.w,
|
||||||
|
.h=r.h-h
|
||||||
|
};
|
||||||
|
CallOnDraw(view,renderer,viewBounds);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(view != nullptr) CallOnDraw(view,renderer,r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool TabView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||||
|
{
|
||||||
|
auto view = this->GetViewAt(0);
|
||||||
|
auto win =this->GetWindow();
|
||||||
|
if(this->tabsVisible)
|
||||||
|
{
|
||||||
|
int h =
|
||||||
|
win->monospaced_font->MaxHeight() + (win->palette.borderSize*3);
|
||||||
|
SDL_Rect viewBounds = {
|
||||||
|
.x=0,
|
||||||
|
.y=h,
|
||||||
|
.w=myBounds.w,
|
||||||
|
.h=myBounds.h-h
|
||||||
|
};
|
||||||
|
|
||||||
|
SDL_Rect theirVisibleBounds = viewBounds;
|
||||||
|
theirVisibleBounds.x += visibleBounds.x;
|
||||||
|
theirVisibleBounds.y += visibleBounds.y;
|
||||||
|
|
||||||
|
viewBounds.x += myBounds.x;
|
||||||
|
viewBounds.y += myBounds.y;
|
||||||
|
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
||||||
|
return CallOnEvent(view,event,viewBounds,theirVisibleBounds);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(view != nullptr) return CallOnEvent(view,event,myBounds,visibleBounds);
|
||||||
|
}
|
||||||
|
return View::OnEvent(event,myBounds,visibleBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TabView::TabView() : TabView(true)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
TabView::TabView(bool tabsVisible) : ContainerView()
|
||||||
|
{
|
||||||
|
this->tabsVisible=tabsVisible;
|
||||||
|
this->firstTab=0;
|
||||||
|
this->selectedTab=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TabView::AddTab(std::string name, View* view, bool owns)
|
||||||
|
{
|
||||||
|
for(auto& item : this->items)
|
||||||
|
{
|
||||||
|
if(item.second.first == view) return;
|
||||||
|
}
|
||||||
|
this->AssignChildParentToThis(view);
|
||||||
|
this->items.push_back(std::pair<std::string,std::pair<View*,bool>>(name,std::pair<View*,bool>(view,owns)));
|
||||||
|
}
|
||||||
|
void TabView::RemoveTab(View* view)
|
||||||
|
{
|
||||||
|
for(auto index = this->items.begin(); index != this->items.end(); index++)
|
||||||
|
{
|
||||||
|
if(index->second.first == view)
|
||||||
|
{
|
||||||
|
if(index->second.second) delete index->second.first;
|
||||||
|
this->items.erase(index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TabView::Clear()
|
||||||
|
{
|
||||||
|
for(auto& item : this->items)
|
||||||
|
{
|
||||||
|
if(item.second.second) delete item.second.first;
|
||||||
|
}
|
||||||
|
items.clear();
|
||||||
|
}
|
||||||
|
size_t TabView::ViewCount()
|
||||||
|
{
|
||||||
|
return this->items.empty() ? 0 : 1;
|
||||||
|
}
|
||||||
|
View* TabView::GetViewAt(size_t index)
|
||||||
|
{
|
||||||
|
if(this->items.empty()) return nullptr;
|
||||||
|
if(this->selectedTab >= this->items.size()) return this->items.back().second.first;
|
||||||
|
return this->items[this->selectedTab].second.first;
|
||||||
|
}
|
||||||
|
TabView::~TabView()
|
||||||
|
{
|
||||||
|
for(auto& item : this->items)
|
||||||
|
{
|
||||||
|
if(item.second.second) delete item.second.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user