refactor(ui): decouple ChatBox from image dependencies, allow custom TextField backgrounds

TextField's background is now a generic `Widget` pointer, enabling use of any widget (e.g., `Rect`, `Image`) as background. `ChatBox` no longer creates its own `TextField`; it accepts one via `set_text_field`. Removed `set_d_image` and `set_default_image` in favor of `set_background`. Added a shared default image constant in `default_image.hpp`. Updated `host_game_ui.cpp`, `join_game_ui.cpp`, and `world_ui_manager.cpp` to construct backgrounds accordingly.
This commit is contained in:
2026-07-19 20:15:21 +08:00
parent dae57c9163
commit 2fd9f0b854
8 changed files with 93 additions and 42 deletions

View File

@@ -6,6 +6,7 @@
#include "Cubed/scene/scene_manager.hpp"
#include "Cubed/ui/button.hpp"
#include "Cubed/ui/column_layout.hpp"
#include "Cubed/ui/default_image.hpp"
#include "Cubed/ui/image.hpp"
#include "Cubed/ui/text_field.hpp"
namespace Cubed {
@@ -48,7 +49,10 @@ void HostGameUI::init() {
auto& text_seed = layout.add_child<TextField>();
text_seed.set_show_text(tr("hostgame.world_seed"));
text_seed.set_app(&m_scene.scene_manager().app());
text_seed.set_default_image(texture_manager);
std::unique_ptr<Image> back = std::make_unique<Image>(&text_seed);
back->set_fill(true).set_image(DEFAULT_TEXT_FIELD_IMAGE,
texture_manager);
text_seed.set_background(std::move(back));
text_seed.set_on_finish([this, &text_seed]() {
unsigned seed = 0;
auto& text = text_seed.input_text();
@@ -67,7 +71,10 @@ void HostGameUI::init() {
}
{
auto& text_port = layout.add_child<TextField>();
text_port.set_default_image(texture_manager);
std::unique_ptr<Image> back = std::make_unique<Image>(&text_port);
back->set_fill(true).set_image(DEFAULT_TEXT_FIELD_IMAGE,
texture_manager);
text_port.set_background(std::move(back));
text_port.set_show_text(tr("hostgame.port"));
text_port.set_app(&m_scene.scene_manager().app());
text_port.set_on_finish([this, &text_port]() {