【问题标题】:Setting text of a text layer seems to overwrite color.设置文本图层的文本似乎会覆盖颜色。
【发布时间】:2014-03-29 20:59:20
【问题描述】:

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

我有一个很好的大部分静态副本工作,但我正在尝试向脸部添加打字动画。

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

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

这里是一些相关代码,其余在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.
}

【问题讨论】:

    标签: c pebble-watch pebble-sdk


    【解决方案1】:

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

    【讨论】:

    • 但我总是来回改变文本颜色。另外,您将其移动是什么意思?没有真正的打字发生。
    • 您正在更改整个图层的文本颜色。这真的是你想做的吗?还是您只想更改一个字符的颜色?
    • 我想改变图层整个文本的颜色。我的想法是让它看起来清晰(即不可见),直到我需要显示它。我认为这比从父级取消/重新附加它更容易。
    • 我在上面提供了一个链接。
    猜你喜欢
    • 2017-06-14
    • 2018-11-12
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多