Initial steps for icon buttons.

This commit is contained in:
jmsgrogan 2023-01-18 20:25:13 +00:00
parent 8130308f7f
commit f2ab532005
17 changed files with 66 additions and 2 deletions

View file

@ -96,11 +96,17 @@ void SvgPainter::setStyle(SceneModel* model, SvgShapeElement* element) const
if (model->hasFillColor())
{
element->setFill(model->getFillColor());
auto opacity = static_cast<float>(model->getFillColor().getAlpha());
if (opacity != 1.0)
{
element->setFillOpacity(opacity);
}
}
else
{
element->setNoFill();
}
if (model->hasOutlineColor())
{
element->setStrokeColor(model->getOutlineColor());
@ -156,10 +162,18 @@ void SvgPainter::paintText(SvgDocument* document, SceneText* text) const
{
auto svg_text = std::make_unique<SvgTextElement>();
svg_text->setContent(text->getTextData().mContent);
svg_text->setLocation(text->getTransform().getLocation());
auto loc = text->getTransform().getLocation();
loc.move(0.0, text->getTextHeight());
svg_text->setLocation(loc);
svg_text->setFontFamily(text->getTextData().mFont.getFaceName());
svg_text->setFill(text->getFillColor());
auto opacity = static_cast<float>(text->getFillColor().getAlpha());
if (opacity != 1.0)
{
svg_text->setFillOpacity(opacity);
}
svg_text->setFontSize(text->getTextData().mFont.getSize());
document->getRoot()->addChild(std::move(svg_text));

View file

@ -34,6 +34,8 @@ list(APPEND visual_elements_LIB_INCLUDES
svg/elements/SvgShapeElements.cpp
nodes/MaterialNode.h
nodes/MaterialNode.cpp
nodes/ImageNode.h
nodes/ImageNode.cpp
nodes/MeshNode.h
nodes/MeshNode.cpp
nodes/TextNode.h

View file

@ -130,7 +130,13 @@ void SvgShapeElement::setStrokeWidth(double width)
{
auto attr = std::make_unique<XmlAttribute>("stroke-width");
attr->setValue(std::to_string(width));
addAttribute(std::move(attr));
}
void SvgShapeElement::setFillOpacity(float opacity)
{
auto attr = std::make_unique<XmlAttribute>("fill-opacity");
attr->setValue(std::to_string(opacity));
addAttribute(std::move(attr));
}

View file

@ -17,6 +17,8 @@ public:
void setNoFill();
void setFillOpacity(float opacity);
void setStrokeWidth(double width);
void setStrokeColor(const Color& stroke);

View file

@ -10,6 +10,13 @@ SvgTextElement::SvgTextElement()
}
void SvgTextElement::setFillOpacity(float opacity)
{
auto attr = std::make_unique<XmlAttribute>("fill-opacity");
attr->setValue(std::to_string(opacity));
addAttribute(std::move(attr));
}
void SvgTextElement::setLocation(const Point& loc)
{
auto x = std::make_unique<XmlAttribute>("x");

View file

@ -15,6 +15,8 @@ public:
void setFill(const Color& fill);
void setFillOpacity(float opacity);
void setFontFamily(const std::string& family);
void setFontSize(float size);

View file

@ -62,16 +62,21 @@ void Button::setEnabled(bool isEnabled)
if (mEnabled != isEnabled)
{
mEnabled = isEnabled;
if (mStyle.mState == ButtonData::State::Disabled)
if (isEnabled && mStyle.mState == ButtonData::State::Disabled)
{
setState(ButtonData::State::Enabled);
}
else if (!isEnabled && mStyle.mState == ButtonData::State::Enabled)
{
setState(ButtonData::State::Disabled);
}
}
}
void Button::updateState()
{
setBackground(mStyle.getContainerColor());
setBackgroundOpacity(mStyle.getStateLayerOverlayOpacity());
setBackgroundTone(mStyle.getContainerSurfaceTintColor());
setElevation(mStyle.getContainerElevation());

View file

@ -10,6 +10,7 @@
class PaintEvent;
class MouseEvent;
class TextNode;
class IconNode;
class Button : public Widget
{
@ -57,6 +58,8 @@ private:
std::unique_ptr<TextNode> mTextNode;
bool mContentDirty{true};
std::unique_ptr<IconNode> mIconNode;
bool mEnabled{ true };
};

View file

@ -36,6 +36,10 @@ list(APPEND LIB_INCLUDES
style/FontTokens.cpp
style/ElevationTokens.h
style/OpacityTokens.h
style/MediaResources.h
style/MediaResources.cpp
style/MediaResourceManager.h
style/MediaResourceManager.cpp
IconNode.h
IconNode.cpp
)

View file

@ -0,0 +1,9 @@
#pragma once
#include "AbstractVisualNode.h"
class IconNode
{
private:
};

View file

@ -4,6 +4,7 @@
#include "ThemeManager.h"
#include "PaintEvent.h"
#include "MouseEvent.h"
#include "VerticalSpacer.h"
@ -24,14 +25,23 @@ TEST_CASE(TestButton_Elevated, "ui_controls")
disabled_button->setEnabled(false);
disabled_button->setLabel("Disabled");
auto pressed_button = Button::Create(ButtonData::Component::Elevated);
pressed_button->setLabel("Pressed");
spacer.addWidget(std::move(enabled_button));
spacer.addWidget(std::move(disabled_button));
spacer.addWidget(std::move(pressed_button));
auto node = spacer.getRootNode();
TestRenderer renderer;
renderer.getScene()->addNode(node);
auto mouse_event = MouseEvent::Create();
mouse_event->setAction(MouseEvent::Action::Pressed);
mouse_event->setClientLocation({ 250, 20 });
spacer.onMouseEvent(mouse_event.get());
auto paint_event = PaintEvent::Create(theme_manager.get(), nullptr);
spacer.onPaintEvent(paint_event.get());