Skip to content

Commit

Permalink
Merge pull request #99 from Jarod42/tabarea
Browse files Browse the repository at this point in the history
Tabarea
  • Loading branch information
Jarod42 authored Sep 18, 2024
2 parents f378ea5 + 8e5f4b0 commit 9fa5873
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
* Continue rebasing from cb494a80f276f3f91c73396f243353789bf14428
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
12 changes: 12 additions & 0 deletions include/guisan/widgets/tabbedarea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ namespace gcn
*/
bool isOpaque() const;

/**
* Checks if the tabbed area is active or not.
*
* @return true if the tabbed area is active, false otherwise.
*/
bool isTabActive() const;

/**
* Adds a tab to the tabbed area. The newly created tab will be
* automatically deleted by the tabbed area when it is removed.
Expand Down Expand Up @@ -293,6 +300,11 @@ namespace gcn
* True if the tabbed area is opaque, false otherwise.
*/
bool mOpaque;

/**
* True if the tabbed area is active, false otherwise.
*/
bool tabActive;
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ namespace gcn

void Button::mousePressed(MouseEvent& mouseEvent)
{
if (mouseEvent.isConsumed())
{
return;
}
if (mouseEvent.getButton() == MouseEvent::Left)
{
mMousePressed = true;
Expand Down
10 changes: 7 additions & 3 deletions src/widgets/tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace gcn
Tab::Tab() : mTabbedArea(NULL), mHasMouse(false)
{
mLabel = new Label();
mLabel->setPosition(4, 4);
mLabel->setPosition(6, 6);
add(mLabel);
setFrameSize(1);

Expand All @@ -85,7 +85,7 @@ namespace gcn

void Tab::adjustSize()
{
setSize(mLabel->getWidth() + 8, mLabel->getHeight() + 8);
setSize(mLabel->getWidth() + 12, mLabel->getHeight() + 12);

if (mTabbedArea != NULL)
{
Expand Down Expand Up @@ -159,12 +159,16 @@ namespace gcn
graphics->setColor(baseColor);
graphics->fillRectangle(Rectangle(0, 0, currentClipArea.width, currentClipArea.height));

if (mTabbedArea != NULL && mTabbedArea->isFocused() && mTabbedArea->isTabSelected(this))
if (mTabbedArea != NULL && mTabbedArea->isFocused() && mTabbedArea->isTabSelected(this)
// && mHasMouse)
&& mTabbedArea->isTabActive())
{
graphics->setColor(Color(0x000000));
graphics->drawRectangle(
Rectangle(2, 2, currentClipArea.width - 4, currentClipArea.height - 4));
}
mLabel->setAlignment(Graphics::Center);
mLabel->_draw(graphics);
graphics->popClipArea();
}

Expand Down
31 changes: 29 additions & 2 deletions src/widgets/tabbedarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ namespace gcn
return mOpaque;
}

bool TabbedArea::isTabActive() const
{
return tabActive;
}

void TabbedArea::draw(Graphics *graphics)
{
const Color& faceColor = getBaseColor();
Expand Down Expand Up @@ -318,7 +323,15 @@ namespace gcn
mTabContainer->getHeight());
}

//drawChildren(graphics);
// Draw the widget from a select tab.
for (const auto& p : mTabs)
{
p.first->_draw(graphics);
if (p.first == mSelectedTab)
{
p.second->_draw(graphics);
}
}
}

void TabbedArea::adjustSize()
Expand Down Expand Up @@ -356,8 +369,11 @@ namespace gcn
Tab* tab = mTabs[i].first;

tab->setPosition(x, maxTabHeight - tab->getHeight());

x += tab->getWidth();

Widget* widget = mTabs[i].second;
widget->setX(mWidgetContainer->getX());
widget->setY(mWidgetContainer->getY());
}
}

Expand Down Expand Up @@ -466,6 +482,17 @@ namespace gcn
if (tab != NULL)
{
setSelectedTab(tab);
tabActive = true;
mouseEvent.consume();
}
else
{
widget = mWidgetContainer->getWidgetAt(mouseEvent.getX(), mouseEvent.getY());
if (widget == NULL)
{
mouseEvent.consume();
}
tabActive = false;
}
}

Expand Down

0 comments on commit 9fa5873

Please sign in to comment.