tomassedovic / tcod-rs

Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)
Do What The F*ck You Want To Public License
229 stars 45 forks source link

print_frame title is not printed #240

Closed jmc-figueira closed 7 years ago

jmc-figueira commented 7 years ago

Consider the following code:

fn draw_box(width: i32, height: i32, title: Option<&str>) -> Offscreen{
        let mut ret_val = Offscreen::new(width + 1, height + 1);

        let ui_color = ColorCell::new(DARK, HUD);

        ret_val.set_default_background(*ui_color.background());
        ret_val.set_default_foreground(*ui_color.foreground());

        ret_val.print_frame::<&str>(0, 0, width, height, true, BackgroundFlag::None, title);

        ret_val
}

This code should print the contents of title in case it is Some("string literal"), right? However, it doesn't print the title, printing only a small box in its place, as shown here.

I've been trying to figure out why this is the case, and have yet to find a solution. Any suggestions?

tomassedovic commented 7 years ago

Thanks for the report!

You're correct that the title should be shown there but it's not. I've managed to reproduce it locally. I've no idea why that is (yet), but I've verified that the equivalent C code linked to the libtcod.so we generate works:

#include "libtcod.h"
#include "console.h"

int main(int argc, char** argv) {
  TCOD_console_init_root(80, 50, "My Title", false, TCOD_RENDERER_SDL);

  while (!TCOD_console_is_window_closed()) {
    TCOD_console_clear(0);
    TCOD_console_print_frame(0, 15, 25, 35, 10, false, TCOD_BKGND_SET, "Hello World!");
    TCOD_console_flush();
    TCOD_console_check_for_keypress(TCOD_KEY_PRESSED);
  }

  return 0;
}

(compiled with cc -L ./target/debug/build/tcod-sys-4d14ca3eba1c71ca/out/ -I./tcod_sys/libtcod/include/ -ltcod frame.c -o frame and ran with LD_LIBRARY_PATH=./target/debug/build/tcod-sys-4d14ca3eba1c71ca/out/ ./frame)

So it's something to do with the bindings themselves. I'll take a look.

jmc-figueira commented 7 years ago

Thank you for the quick reply, that definitely solved it!