Added phone tool settings
This commit is contained in:
parent
f1d7cbf896
commit
c90c09b169
42 changed files with 479 additions and 57 deletions
|
|
@ -22,7 +22,7 @@ void CheckBox::layout(const Clay_ElementId& id, const std::function<bool()>& isT
|
|||
}
|
||||
|
||||
void CheckBox::update() {
|
||||
if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, mouseHovering, CHECKBOX_ANIMATION_TIME))
|
||||
if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, is_hovering_animation(), CHECKBOX_ANIMATION_TIME))
|
||||
gui.invalidate_draw_element(this);
|
||||
if(oldIsTicked != isTicked()) {
|
||||
gui.invalidate_draw_element(this);
|
||||
|
|
@ -30,9 +30,26 @@ void CheckBox::update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool CheckBox::is_hovering_animation() {
|
||||
return mouseHovering && (!gui.last_interaction_is_touch() || isHeld);
|
||||
}
|
||||
|
||||
void CheckBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down)
|
||||
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
||||
gui.set_post_callback_func([&](){if(onClick) onClick();});
|
||||
isHeld = true;
|
||||
}
|
||||
else
|
||||
isHeld = false;
|
||||
}
|
||||
|
||||
void CheckBox::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) {
|
||||
if(mouseHovering && touch.down) {
|
||||
gui.set_post_callback_func([&](){if(onClick) onClick();});
|
||||
isHeld = true;
|
||||
}
|
||||
else
|
||||
isHeld = false;
|
||||
}
|
||||
|
||||
void CheckBox::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
||||
|
|
@ -53,7 +70,7 @@ void CheckBox::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderComma
|
|||
}
|
||||
else {
|
||||
SkRect checkBox = SkRect::MakeLTRB(-0.45f, -0.45f, 0.45f, 0.45f);
|
||||
p.setColor4f(convert_vec4<SkColor4f>(mouseHovering ? io.theme->fillColor1 : io.theme->fillColor2));
|
||||
p.setColor4f(convert_vec4<SkColor4f>(is_hovering_animation() ? io.theme->fillColor1 : io.theme->fillColor2));
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
p.setStrokeWidth(0.15f);
|
||||
canvas->drawRoundRect(checkBox, 0.25f, 0.25f, p);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ class CheckBox : public Element {
|
|||
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||
virtual void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) override;
|
||||
virtual void update() override;
|
||||
|
||||
void layout(const Clay_ElementId& id, const std::function<bool()>& isTicked, const std::function<void()>& onClick);
|
||||
|
|
@ -16,6 +17,8 @@ class CheckBox : public Element {
|
|||
static constexpr float CHECKBOX_ANIMATION_TIME = 0.3;
|
||||
float hoverAnimation = 0.0;
|
||||
bool oldIsTicked = false;
|
||||
bool isHeld = false;
|
||||
bool is_hovering_animation();
|
||||
std::function<bool()> isTicked;
|
||||
std::function<void()> onClick;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "Element.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
#include "../../TimePoint.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ template <typename T> class NumberSlider : public Element {
|
|||
|
||||
virtual void update() override {
|
||||
smooth_two_way_animation_time(dd.holdAnimation, gui.io.deltaTime, dd.isHeld, HOLD_ANIMATION_TIME);
|
||||
smooth_two_way_animation_time(dd.hoverAnimation, gui.io.deltaTime, mouseHovering, gui.io.theme->hoverExpandTime);
|
||||
smooth_two_way_animation_time(dd.hoverAnimation, gui.io.deltaTime, mouseHovering && !gui.last_interaction_is_touch(), gui.io.theme->hoverExpandTime);
|
||||
if(oldDD != dd) {
|
||||
gui.invalidate_draw_element(this, {
|
||||
.top = 10.0f,
|
||||
|
|
@ -113,6 +114,23 @@ template <typename T> class NumberSlider : public Element {
|
|||
update_slider_pos(motion.pos, false);
|
||||
}
|
||||
|
||||
virtual void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) override {
|
||||
bool oldIsHeld = dd.isHeld;
|
||||
dd.isHeld = mouseHovering && touch.down;
|
||||
if(oldIsHeld && !dd.isHeld) {
|
||||
gui.set_post_callback_func([&] {
|
||||
if(config.onRelease) config.onRelease();
|
||||
});
|
||||
}
|
||||
else if(dd.isHeld && boundingBox.has_value())
|
||||
update_slider_pos(touch.pos, true);
|
||||
}
|
||||
|
||||
virtual void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) override {
|
||||
if(dd.isHeld && boundingBox.has_value())
|
||||
update_slider_pos(motion.pos, false);
|
||||
}
|
||||
|
||||
private:
|
||||
void update_slider_pos(const Vector2f& p, bool justHeld) {
|
||||
gui.set_post_callback_func([&, p, justHeld] {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ void RadioButton::layout(const Clay_ElementId& id, const std::function<bool()>&
|
|||
}
|
||||
|
||||
void RadioButton::update() {
|
||||
if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, mouseHovering, RADIOBUTTON_ANIMATION_TIME))
|
||||
if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, is_hovering_animation(), RADIOBUTTON_ANIMATION_TIME))
|
||||
gui.invalidate_draw_element(this);
|
||||
if(oldIsTicked != isTicked()) {
|
||||
gui.invalidate_draw_element(this);
|
||||
|
|
@ -28,9 +28,26 @@ void RadioButton::update() {
|
|||
}
|
||||
}
|
||||
|
||||
bool RadioButton::is_hovering_animation() {
|
||||
return mouseHovering && (!gui.last_interaction_is_touch() || isHeld);
|
||||
}
|
||||
|
||||
void RadioButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down)
|
||||
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
||||
gui.set_post_callback_func([&] { if(onClick) onClick(); });
|
||||
isHeld = true;
|
||||
}
|
||||
else
|
||||
isHeld = false;
|
||||
}
|
||||
|
||||
void RadioButton::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) {
|
||||
if(mouseHovering && touch.down) {
|
||||
gui.set_post_callback_func([&] { if(onClick) onClick(); });
|
||||
isHeld = true;
|
||||
}
|
||||
else
|
||||
isHeld = false;
|
||||
}
|
||||
|
||||
void RadioButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
||||
|
|
@ -62,7 +79,7 @@ void RadioButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCo
|
|||
else {
|
||||
SkPaint p;
|
||||
p.setAntiAlias(skiaAA);
|
||||
p.setColor4f(convert_vec4<SkColor4f>(mouseHovering ? io.theme->fillColor1 : io.theme->backColor2));
|
||||
p.setColor4f(convert_vec4<SkColor4f>(is_hovering_animation() ? io.theme->fillColor1 : io.theme->backColor2));
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
p.setStrokeWidth(0.15f);
|
||||
canvas->drawCircle(0.0f, 0.0f, 0.5f, p);
|
||||
|
|
|
|||
|
|
@ -8,12 +8,15 @@ class RadioButton : public Element {
|
|||
RadioButton(GUIManager& gui);
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||
virtual void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) override;
|
||||
virtual void update() override;
|
||||
|
||||
void layout(const Clay_ElementId& id, const std::function<bool()>& isTicked, const std::function<void()>& onClick);
|
||||
private:
|
||||
static constexpr float RADIOBUTTON_ANIMATION_TIME = 0.3;
|
||||
bool oldIsTicked = false;
|
||||
bool isHeld = false;
|
||||
bool is_hovering_animation();
|
||||
float hoverAnimation = 0.0;
|
||||
std::function<bool()> isTicked;
|
||||
std::function<void()> onClick;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue