Browse Source

color update, set win on components, onBeforeLoad, use docComp's navto

master
Odilitime 5 years ago
parent
commit
3d22573e1e
  1. 68
      src/graphics/components/TabbedComponent.cpp
  2. 13
      src/graphics/components/TabbedComponent.h

68
src/graphics/components/TabbedComponent.cpp

@ -37,7 +37,7 @@ TabbedComponent::TabbedComponent(const float rawX, const float rawY, const float @@ -37,7 +37,7 @@ TabbedComponent::TabbedComponent(const float rawX, const float rawY, const float
BoxComponent *addBoxHandle = addNewBox.get();
addNewBox->onMouseover = [addBoxHandle, this]() {
//std::cout << "addNewBox->onMouseover" << std::endl;
addBoxHandle->changeColor(this->tabHoverColor);
addBoxHandle->changeColor(this->tabAddHoverColor);
this->win->renderDirty = true;
};
addNewBox->onMouseout = [addBoxHandle, this]() {
@ -66,6 +66,7 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -66,6 +66,7 @@ void TabbedComponent::addTab(std::string passedTitle) {
//(const std::string &rawText, const int rawX, const int rawY, const unsigned int size, const bool bolded, const unsigned int hexColor, const int passedWindowWidth, const int passedWindowHeight)
std::shared_ptr<TextComponent> newTabTitle = std::make_shared<TextComponent>(passedTitle, 0, 0, 12, false, this->tabTextColor, windowWidth, windowHeight);
size_t textWidth = 0;
newTabTitle->win = this->win;
std::unique_ptr<std::pair<int, int>> textInfo = newTabTitle->size();
if (textInfo) {
textWidth = static_cast<size_t>(textInfo->first);
@ -147,7 +148,7 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -147,7 +148,7 @@ void TabbedComponent::addTab(std::string passedTitle) {
closeTabBox->onMouseover = [closeTabBox, this]() {
//std::cout << "closeTabBox->onMouseover" << std::endl;
closeTabBox->changeColor(0xF00000FF);
closeTabBox->changeColor(this->tabCloseHoverColor);
this->win->renderDirty = true;
};
closeTabBox->onMouseout = [closeTabBox, this]() {
@ -168,6 +169,38 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -168,6 +169,38 @@ void TabbedComponent::addTab(std::string passedTitle) {
docComponent->win = this->win;
docComponent->boundToPage = false;
docComponent->onBeforeLoad=[this](std::string url) {
//std::cout << "tabbedComponent::addTab:::docComponent->onBeforeLoad - fire" << std::endl;
// if we're in a tab
if (this->mpSelectedTab) {
// set tab
TextComponent *textComponent = dynamic_cast<TextComponent*>(this->mpSelectedTab->titleBox.get());
if (textComponent) {
// similar to loadDomIntoTab
textComponent->text = url;
textComponent->wrap();
// recalc what that just did to our fellow tabs
this->layoutTabs(this->selectedTab, 0);
}
} else {
std::cout << "tabbedComponent::addTab:::docComponent->onBeforeLoad - document component but no tab selected" << std::endl;
// but we're loading into a specific tab, we have a doc component...
if (!this->tabs.size()) {
std::cout << "tabbedComponent::addTab:::docComponent->onBeforeLoad - document component but no tabs!" << std::endl;
}
}
// set address bar
InputComponent *ab = dynamic_cast<InputComponent*>(this->win->addressComponent.get());
if (ab) {
ab->value = url;
ab->updateText();
} else {
std::cout << "No address component" << std::endl;
}
this->updateWindowState(url);
};
// set up position and resize info
docComponent->y = -96; // our bar
docComponent->uiControl.x = { 0, 0 }; // 0
@ -185,7 +218,12 @@ void TabbedComponent::addTab(std::string passedTitle) { @@ -185,7 +218,12 @@ void TabbedComponent::addTab(std::string passedTitle) {
newTab->history = std::make_unique<BrowsingHistory>([this](URL const& goToURL) {
std::cout << "history goto " << goToURL << std::endl;
this->win->navTo(goToURL.toString());
std::shared_ptr<DocumentComponent> docComponent = std::static_pointer_cast<DocumentComponent>(this->documentComponent);
if (docComponent) {
// now tell it to navigate somewhere
docComponent->navTo(goToURL.toString());
}
//this->win->navTo(goToURL.toString());
});
if (tabs.size()) {
@ -216,7 +254,15 @@ void TabbedComponent::updateWindowState(std::string newTitle) { @@ -216,7 +254,15 @@ void TabbedComponent::updateWindowState(std::string newTitle) {
// need to update currentURL for navTo
// if we're no tab, we have no relative point, no harm in setting http://
//if (ab->value!="http://") {
this->win->currentURL = newTitle;
//this->win->currentURL = newTitle;
// I'm not sure we need this
/*
DocumentComponent *docComponent = dynamic_cast<DocumentComponent*>(this->documentComponent.get());
if (docComponent) {
docComponent->currentURL = newTitle;
}
*/
//}
// redraw pls
@ -242,7 +288,7 @@ std::vector<std::shared_ptr<Tab>>::iterator TabbedComponent::getTab(size_t tabId @@ -242,7 +288,7 @@ std::vector<std::shared_ptr<Tab>>::iterator TabbedComponent::getTab(size_t tabId
void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
//std::cout << "TabbedComponent::selectTab - select tab " << tabId << std::endl;
// locate tabId
// locate tab
if (tab == nullptr) {
std::cout << "TabbedComponent::selectTab - tab is nullptr" << std::endl;
return;
@ -269,6 +315,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -269,6 +315,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
it2 = std::find(this->rootComponent->children.begin(), this->rootComponent->children.end(), this->documentComponent);
if ( it2 != this->rootComponent->children.end() ) {
//std::cout << "Found old contents" << std::endl;
// FIXME: cast to doccomp and setDOM to null to make sure its clean
it2->get()->parent = nullptr;
this->rootComponent->children.erase(it2);
}
@ -289,7 +336,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -289,7 +336,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
}
ab->updateText();
} else {
std::cout << "Window addressComponent isnt an inputcomponent" << std::endl;
std::cout << "TabbedComponent::selectTab - Window addressComponent isnt an inputcomponent" << std::endl;
}
// I can't get selectedTab to works always (tab size = 1 or 2)
@ -306,6 +353,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -306,6 +353,7 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
i++;
}
//std::cout << "i" << i << "/" << this->tabs.size() << std::endl;
std::cout << "TabbedComponent::selectTab - selector found: " << found << std::endl;
if (found) {
// was there a previously selected tab?
//if (this->selectedTab != this->tabs.end() && this->selectedTab != this->tabs.begin()) {
@ -314,9 +362,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -314,9 +362,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
selector->changeColor(this->tabActiveColor);
}
// if we had something selected
// make sure we didn't just reselect ourself
//if (this->selectedTabId != newTab->get()->id) {
if (this->mpSelectedTab != tab) {
if (this->mpSelectedTab && this->mpSelectedTab != tab) {
selector = dynamic_cast<BoxComponent*>(this->selectedTab->get()->selectorBox.get());
if (selector) {
// reset it's color
@ -338,6 +387,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) { @@ -338,6 +387,10 @@ void TabbedComponent::selectTab(std::shared_ptr<Tab> tab) {
selector = dynamic_cast<BoxComponent*>(tab->selectorBox.get());
if (selector) {
selector->changeColor(this->tabActiveColor);
} else {
if (this->tabs.size()) {
std::cout << "TabbedComponent::selectTab - Can't find selectorBox for tab" << std::endl;
}
}
}
@ -503,6 +556,7 @@ void TabbedComponent::loadDomIntoTab(std::shared_ptr<Node> newRoot, std::string @@ -503,6 +556,7 @@ void TabbedComponent::loadDomIntoTab(std::shared_ptr<Node> newRoot, std::string
this->updateWindowState(newTitle);
}
//FIXME: make sure we update window's ptrs, we can't have documentComponent not pointing to nullptr when there's no tabs
void TabbedComponent::removeTab(size_t tabId) {
// find tabId
bool found = false;

13
src/graphics/components/TabbedComponent.h

@ -27,6 +27,7 @@ struct Tab { @@ -27,6 +27,7 @@ struct Tab {
// or create a special store/load system for it (might be less memory but more cpu)
std::shared_ptr<Node> domRootNode = nullptr;
//BrowsingHistory history;
// FIXME: we should move this into document component
std::unique_ptr<BrowsingHistory> history = nullptr;
std::shared_ptr<Tab> previousTab = nullptr;
};
@ -35,6 +36,7 @@ struct Tab { @@ -35,6 +36,7 @@ struct Tab {
class TabbedComponent : public MultiComponent {
public:
TabbedComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
// maybe you could return a handle so we can use it to select
void addTab(std::string passedTitle);
void updateWindowState(std::string newTitle);
std::vector<std::shared_ptr<Tab>>::iterator getTab(size_t tabId);
@ -55,14 +57,17 @@ public: @@ -55,14 +57,17 @@ public:
std::shared_ptr<Component> documentComponent = nullptr;
unsigned int tabAddColor = 0xF0F0F0FF;
unsigned int tabAddHoverColor = 0x008888FF;
unsigned int tabAddHoverColor = 0x008800FF;
unsigned int tabInactiveColor = 0x808080FF;
unsigned int tabHoverColor = 0x008888FF;
unsigned int tabActiveColor = 0x00FFFFFF;
unsigned int tabHoverColor = 0x8888BBFF;
unsigned int tabActiveColor = 0xE0E0E0FF;
unsigned int tabTextColor = 0x000000FF;
unsigned int tabTextHoverColor = 0x008888FF;
unsigned int tabCloseColor = 0x222222FF;
unsigned int tabCloseHoverColor = 0x008888FF;
unsigned int tabCloseHoverColor = 0x880000FF;
};
#endif

Loading…
Cancel
Save