mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
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:
@@ -31,14 +31,21 @@ void WorldUIManager::init() {
|
||||
m_widgets.try_emplace("crosshair", &crosshair);
|
||||
|
||||
auto& chat_box = m_root_widget->add_child<ChatBox>();
|
||||
auto text_field = std::make_unique<TextField>(&chat_box);
|
||||
text_field->set_anchor(Anchor::BOTTOM_LEFT);
|
||||
auto rect = std::make_unique<Rect>(text_field.get());
|
||||
rect->set_color(Color::GRAY).set_alpha(0.6f).set_fill(true);
|
||||
text_field->set_background(std::move(rect))
|
||||
.set_app(&m_scene.scene_manager().app())
|
||||
.set_fill_width(true)
|
||||
.set_visible(false);
|
||||
chat_box.set_text_field(std::move(text_field));
|
||||
chat_box.set_spacing(15);
|
||||
chat_box.set_anchor(Anchor::BOTTOM_LEFT);
|
||||
chat_box.set_offset({0, -10});
|
||||
chat_box.set_width(200);
|
||||
chat_box.set_scale(2.0f);
|
||||
chat_box.set_text_scale(0.6f);
|
||||
chat_box.set_d_image(m_scene.scene_manager().app().texture_manager());
|
||||
chat_box.set_app(&m_scene.scene_manager().app());
|
||||
chat_box.set_on_finish([this, &chat_box]() {
|
||||
ChatMessage message{m_scene.client_world().get_player().get_name(),
|
||||
std::move(chat_box.get_input_text()), 0};
|
||||
|
||||
Reference in New Issue
Block a user