设置文本图层的文本似乎会覆盖颜色。

时间:2014-03-29 20:59:21

标签: c pebble-watch pebble-sdk

我正在制作Pebble表盘,以便在适当的Linux终端调用下显示数据和时间以获得这些时间。

我有一个很好的静态副本工作,但我试图在脸上添加一个打字动画。

enter image description here

为此,我使用AppTimer 200ms并在每次调用时输入一个字母。

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

以下是一些相关代码,其余的是GitHub https://github.com/vidia/Pebble-Shell/tree/type

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

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.
}

1 个答案:

答案 0 :(得分:0)

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