Skip to content

Commit 86e57ce

Browse files
committed
fix the ColorSlider texture, and rename after_color_mode_change() to change_text()
1 parent 9042326 commit 86e57ce

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/ui/components/color_picker.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include "ui/components/textinput.hpp"
1111
#include "ui/layout.hpp"
1212
#include "ui/widget.hpp"
13-
#include <stdexcept>
13+
14+
#include <memory>
1415

1516
detail::ColorSlider::ColorSlider(
1617
ServiceProvider* service_provider,
@@ -28,11 +29,15 @@ detail::ColorSlider::ColorSlider(
2829
step,
2930
layout,
3031
is_top_level },
31-
m_texture{ service_provider->renderer().get_texture_for_render_target(bar_rect().to_dimension_point()) } {
32+
m_texture{} {
3233

3334
change_layout();
3435

35-
service_provider->renderer().set_render_target(m_texture);
36+
m_texture = std::make_unique<Texture>(
37+
service_provider->renderer().get_texture_for_render_target(bar_rect().to_dimension_point())
38+
);
39+
40+
service_provider->renderer().set_render_target(*m_texture);
3641

3742
const auto w = bar_rect().width();
3843
const auto h = bar_rect().height();
@@ -88,7 +93,7 @@ void detail::ColorSlider::render(const ServiceProvider& service_provider) const
8893

8994
const auto& renderer = service_provider.renderer();
9095

91-
renderer.draw_texture(m_texture, bar_rect());
96+
renderer.draw_texture(*m_texture, bar_rect());
9297

9398
renderer.draw_rect_filled(slider_rect(), Color::white(0xAA));
9499
}
@@ -375,7 +380,7 @@ ui::ColorPicker::ColorPicker(
375380
service_provider, rgb_image_path, true, focus_id_unused,
376381
[this](const ImageButton&) -> bool {
377382
this->m_mode = ColorMode::HSV;
378-
this->after_color_mode_change();
383+
this->change_text();
379384
return false;
380385
},
381386
std::pair<double, double>{ 0.95, 0.95 },
@@ -388,7 +393,7 @@ ui::ColorPicker::ColorPicker(
388393
service_provider, hsv_image_path, true, focus_id_unused,
389394
[this](const ImageButton&) -> bool {
390395
this->m_mode = ColorMode::RGB;
391-
this->after_color_mode_change();
396+
this->change_text();
392397
return false;
393398
},
394399
std::pair<double, double>{ 0.95, 0.95 },
@@ -502,6 +507,8 @@ ui::ColorPicker::handle_event(const SDL_Event& event, const Window* window) {
502507
//TODO: maybe inform the user, that the input is incorrect?
503508
//m_color_text->display_error();
504509

510+
// reset the text
511+
change_text();
505512
break;
506513
}
507514

@@ -532,13 +539,13 @@ void ui::ColorPicker::after_color_change(detail::ColorChangeOrigin origin, const
532539
break;
533540
}
534541
case detail::ColorChangeOrigin::Canvas: {
535-
after_color_mode_change();
542+
change_text();
536543
break;
537544
}
538545
case detail::ColorChangeOrigin::Slider: {
539546
m_color_canvas->on_change(origin, color);
540547

541-
after_color_mode_change();
548+
change_text();
542549
break;
543550
}
544551
default:
@@ -548,7 +555,7 @@ void ui::ColorPicker::after_color_change(detail::ColorChangeOrigin origin, const
548555
m_callback(m_color);
549556
}
550557

551-
void ui::ColorPicker::after_color_mode_change() {
558+
void ui::ColorPicker::change_text() {
552559
const std::string text =
553560
m_color.to_string(m_mode == ColorMode::HSV ? color::SerializeMode::HSV : color::SerializeMode::RGB, false);
554561

src/ui/components/color_picker.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace detail {
1616
// it is intended, that this never has focus, than the scroll wheel doesn't work, but it shouldn't work, since scrolling a color slider isn't intended behaviour
1717
struct ColorSlider : public ui::AbstractSlider<double> {
1818
private:
19-
Texture m_texture;
19+
std::unique_ptr<Texture> m_texture;
2020

2121
public:
2222
explicit ColorSlider(
@@ -122,7 +122,7 @@ namespace ui {
122122

123123
private:
124124
void after_color_change(detail::ColorChangeOrigin origin, const HSVColor& color);
125-
void after_color_mode_change();
125+
void change_text();
126126
};
127127

128128
} // namespace ui

0 commit comments

Comments
 (0)