首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置文本层的文本似乎会覆盖颜色。

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

Stack Overflow用户
提问于 2014-03-30 04:59:21
回答 1查看 256关注 0票数 0

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

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

​

​

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

然而,现在我遇到了一个问题,即使我可以让命令动画化,我也不能让大的时间和日期文本消失(当命令完成键入时,它们会重新出现)。

这里有一些相关的代码,其余的在GitHub https://github.com/vidia/Pebble-Shell/tree/type上

我认为发生的情况是,文本的设置覆盖了颜色的设置,并使文本再次出现。但我不能完全确定。如果有必要,您可以自行安装。

代码语言:javascript
复制
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.
}
EN

回答 1

Stack Overflow用户

发布于 2014-04-01 14:23:50

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22736837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档