C 设置文本层的文本似乎覆盖了颜色。

C 设置文本层的文本似乎覆盖了颜色。,c,pebble-watch,pebble-sdk,C,Pebble Watch,Pebble Sdk,我正在制作一个Pebble watchface,在适当的Linux终端调用下显示数据和时间,以获取这些时间 我有一个很好的主要是静态复制工作,但我试图添加一个打字动画的脸 为此,我使用了一个200毫秒的AppTimer,并在每次调用时多键入一个字母 然而,现在我遇到了一个问题,即使我可以让命令设置动画,我也无法让大量的时间和日期文本消失(并在命令完成键入后重新出现) 下面是一些相关的代码,其余的在GitHub上 我认为它发生的是,文本的设置覆盖了颜色的设置,并使文本再次出现。但我不能完全肯定。

我正在制作一个Pebble watchface,在适当的Linux终端调用下显示数据和时间,以获取这些时间

我有一个很好的主要是静态复制工作,但我试图添加一个打字动画的脸

为此,我使用了一个200毫秒的AppTimer,并在每次调用时多键入一个字母

然而,现在我遇到了一个问题,即使我可以让命令设置动画,我也无法让大量的时间和日期文本消失(并在命令完成键入后重新出现)

下面是一些相关的代码,其余的在GitHub上

我认为它发生的是,文本的设置覆盖了颜色的设置,并使文本再次出现。但我不能完全肯定。如果必须,请自行安装

static char hourmin[] = "~$date +%I:%M";
static char timecmd[] = "             ";
static char monthday[] = "~$date +%h\\ %d";
static char datecmd[] =  "              ";
...
static void handleMinuteTick(...)
{
    text_layer_set_text_color(time_layer, GColorClear);//the time text
    text_layer_set_text_color(date_layer, GColorClear);//the date text
    text_layer_set_text_color(dprompt_layer, GColorClear);//the date prompt
    text_layer_set_text_color(prompt_layer, GColorClear);//the final, empty prompt
    ...
    //set text of time_layer to the current time
    //register a timer
}

static void animateTimePrompt()
{
    static unsigned int i = 2;
    static int TYPE_TIME = 200;

    app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "i: %d", i);
    strncpy(timecmd, hourmin, i++);
    app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 60, "timecmd: \"%s\"", timecmd);
    text_layer_set_text(text_layer, timecmd);
    if( i > strlen(hourmin))
    {
        app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "Typed word!!: %d", i);
        i = 2;
        text_layer_set_text_color(time_layer, GColorWhite);
        text_layer_set_text_color(dprompt_layer, GColorWhite);
        //app_timer_cancel(timer);
        timer = app_timer_register(TYPE_TIME, animateDatePrompt, 0);
    }
    else
        timer = app_timer_register(TYPE_TIME, animateTimePrompt, 0);
}

static void animateDatePrompt()
{
    static int i = 2;
    static int TYPE_TIME = 200;

    app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "i: %d", i);
    strncpy(datecmd, monthday, i++);
    app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 60, "datacmd: \"%s\"", datecmd);
    text_layer_set_text(dprompt_layer, datecmd);
    if((unsigned int) i > strlen(monthday))
    {
        app_log(APP_LOG_LEVEL_DEBUG, "unix-time.c", 97, "Typed word!!: %d", i);
        i = 2;
        text_layer_set_text_color(date_layer, GColorWhite);
        text_layer_set_text_color(prompt_layer, GColorWhite);
        //timer = app_timer_register(TYPE_TIME, animateDatePrompt, 0);
        //app_timer_cancel(timer);
    }
    else
        timer = app_timer_register(TYPE_TIME, animateDatePrompt, 0);
}

...
void handleSecondTick(...)
{
    //set text of prompt_layer for the blinking cursor.
}

我认为当您只想更改提示的颜色时,您正在更改整个文本层的颜色。我认为创建一个图层来显示提示,然后在用户键入时移动它可能更容易

但是我总是来回地改变文本的颜色。你说的移动是什么意思?没有真正的输入。您正在更改整个图层的文本颜色。这真的是你想做的吗?还是只想更改一个字符的颜色?我想更改图层整个文本的颜色。我的想法是让它看起来清晰(看不见),直到我需要显示它为止。我想这比从父级上取消/重新连接要容易得多。我在上面提供了一个链接。