Update widgets module. Raster example initial.
This commit is contained in:
parent
9e339defd6
commit
9cfae3fe3e
48 changed files with 1169 additions and 530 deletions
|
|
@ -7,23 +7,9 @@ namespace tp {
|
|||
template <typename Events, typename Canvas>
|
||||
class SliderWidget : public Widget<Events, Canvas> {
|
||||
public:
|
||||
SliderWidget() {
|
||||
this->createConfig("SliderWidget");
|
||||
this->addColor("Default", "Base");
|
||||
this->addColor("Handle", "Accent");
|
||||
this->addColor("Hovered", "Interaction");
|
||||
this->addColor("Scrolling", "Action");
|
||||
this->addValue("Padding", "Padding");
|
||||
this->addValue("HandleSize", 20.f);
|
||||
this->addValue("MinSize", 20.f);
|
||||
this->addValue("Rounding", "Rounding");
|
||||
}
|
||||
|
||||
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
|
||||
this->mArea = aArea;
|
||||
this->mVisible = areaParent.isOverlap(aArea);
|
||||
if (!this->mVisible) return;
|
||||
SliderWidget() = default;
|
||||
|
||||
void procBody(const Events& events) override {
|
||||
if (events.isPressed(InputID::MOUSE1) && this->mArea.isInside(events.getPointer())) {
|
||||
mIsSliding = true;
|
||||
} else if (events.isReleased(InputID::MOUSE1)) {
|
||||
|
|
@ -31,44 +17,50 @@ namespace tp {
|
|||
}
|
||||
|
||||
if (mIsSliding) {
|
||||
const auto handleSize = this->getValue("HandleSize");
|
||||
mFactor = (events.getPointer().x - this->mArea.x - handleSize / 2.f) / (this->mArea.z - handleSize);
|
||||
}
|
||||
|
||||
mFactor = tp::clamp(mFactor, 0.f, 1.f);
|
||||
}
|
||||
|
||||
void draw(Canvas& canvas) override {
|
||||
if (!this->mVisible) return;
|
||||
canvas.rect(this->mArea, this->getColor("Default"), this->getValue("Rounding"));
|
||||
canvas.rect(getHandle(), this->getColor("Handle"), this->getValue("Rounding"));
|
||||
void drawBody(Canvas& canvas) override {
|
||||
canvas.rect(this->mArea, defaultColor, rounding);
|
||||
canvas.rect(getHandle(), handleColor, rounding);
|
||||
}
|
||||
|
||||
RectF getHandle() const {
|
||||
const auto handle = this->getValue("HandleSize");
|
||||
const auto halfHandle = handle / 2.f;
|
||||
const auto left = this->mArea.x + (this->mArea.z - handle) * mFactor;
|
||||
return { left, this->mArea.y, handle, this->mArea.w };
|
||||
const auto left = this->mArea.x + (this->mArea.z - handleSize) * mFactor;
|
||||
return { left, this->mArea.y, handleSize, this->mArea.w };
|
||||
}
|
||||
|
||||
public:
|
||||
void updateConfigCache(WidgetManager& wm) override {
|
||||
wm.setActiveId("Slider");
|
||||
defaultColor = wm.getColor("Default", "Base");
|
||||
handleColor = wm.getColor("Handle", "Accent");
|
||||
handleSize = wm.getNumber("HandleSize", 20.f);
|
||||
rounding = wm.getNumber("Rounding", "Rounding");
|
||||
}
|
||||
|
||||
public:
|
||||
halnf mFactor = 0.f;
|
||||
bool mIsSliding = false;
|
||||
|
||||
RGBA defaultColor;
|
||||
RGBA handleColor;
|
||||
halnf handleSize = 0;
|
||||
halnf rounding = 0;
|
||||
};
|
||||
|
||||
template <typename Events, typename Canvas>
|
||||
class NamedSliderWidget : public Widget<Events, Canvas> {
|
||||
public:
|
||||
NamedSliderWidget(const char* name = "Value") {
|
||||
explicit NamedSliderWidget(const char* name = "Value") {
|
||||
mLabel.mLabel = name;
|
||||
this->mArea = { 0, 0, 100, 30 };
|
||||
}
|
||||
|
||||
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
|
||||
this->mArea = aArea;
|
||||
this->mVisible = areaParent.isOverlap(aArea);
|
||||
if (!this->mVisible) return;
|
||||
|
||||
void procBody(const Events& events) override {
|
||||
const auto widthFirst = this->mArea.z * mFactor;
|
||||
const auto widthSecond = this->mArea.z * (1.f - mFactor);
|
||||
|
||||
|
|
@ -83,12 +75,17 @@ namespace tp {
|
|||
mSlider.proc(events, this->mArea, rec);
|
||||
}
|
||||
|
||||
void draw(Canvas& canvas) override {
|
||||
if (!this->mVisible) return;
|
||||
void drawBody(Canvas& canvas) override {
|
||||
mSlider.draw(canvas);
|
||||
mLabel.draw(canvas);
|
||||
}
|
||||
|
||||
virtual void updateConfigCache(WidgetManager& wm) {
|
||||
wm.setActiveId("NamedSlider");
|
||||
mSlider.updateConfigCache(wm);
|
||||
mLabel.updateConfigCache(wm);
|
||||
}
|
||||
|
||||
public:
|
||||
SliderWidget<Events, Canvas> mSlider;
|
||||
LabelWidget<Events, Canvas> mLabel;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue