コード例 #1
0
ファイル: select.cpp プロジェクト: JickLee/Core
void UISelect::update(float dt) {

    updateZIndex();

    if(open) options_layout->zindex = this->zindex + 1;
        else options_layout->zindex = this->zindex;

    UISolidLayout::update(dt);
    options_layout->update(dt);
}
コード例 #2
0
ファイル: label.cpp プロジェクト: atondwal/Core
void UILabel::update(float dt) {

    updateZIndex();

    if(editable && !selected && value != 0) {
        if(*value != text) {
            text = *value;
            text_changed = true;
        }
    }

    if(selected && editable) {
        cursor_anim += dt;
        if(cursor_anim>=2.0f) cursor_anim=0.0f;
    } else {
        updateContent();
        if(width < 0.0f) {
            width = ui->font.getWidth(text) + 2.0f;
        }

        cursor_anim = 0.0f;
    }

    if(text_changed && width >= 0.0f && ui != 0) {
        display_text = text;
        float text_width = ui->font.getWidth(display_text);

        //add space for cursor
        float text_padding = (editable) ? 10.0f : 0.0f;

        while(text_width+text_padding > (width+expanded) && !display_text.empty()) {
            display_text = display_text.substr(1, display_text.size()-1);
            text_width = ui->font.getWidth(display_text);
        }
        text_changed = false;
    }

    updateRect();
}
コード例 #3
0
ファイル: scroll_bar.cpp プロジェクト: JickLee/Core
void UIScrollBar::updateRect() {
    if(parent==0) return;

    updateZIndex();

    vec2 scroll_rect = ((UIScrollLayout*)parent)->getScrollRect();
    vec2 inner_rect  = ((UIScrollLayout*)parent)->getInnerRect();

    if(horizontal) {
        rect        = vec2(scroll_rect.x, bar_width);
        bar_percent = std::min(1.0f, scroll_rect.x / inner_rect.x);

        if(bar_percent >= 1.0f) {
            bar_percent = 0.0f;
            bar_offset  = 0.0f;
        }

        if(stick_to_end) scrollToEnd();

        bar_rect          = vec2(std::max(bar_min / scroll_rect.x, bar_percent) * rect.x, bar_width);
        bar_visual_offset = std::min(bar_offset, 1.0f - std::max(bar_min / ((UIScrollLayout*)parent)->getScrollRect().x, bar_percent));
    } else {
        rect        = vec2(bar_width, scroll_rect.y);
        bar_percent = std::min(1.0f, scroll_rect.y / inner_rect.y);

        if(bar_percent >= 1.0f) {
            bar_percent = 0.0f;
            bar_offset  = 0.0f;
        }

        if(stick_to_end) scrollToEnd();

        bar_rect          = vec2(bar_width, std::max(bar_min / scroll_rect.y, bar_percent) * rect.y);
        bar_visual_offset = std::min(bar_offset, 1.0f - std::max(bar_min / ((UIScrollLayout*)parent)->getScrollRect().y, bar_percent));
    }
}
コード例 #4
0
ファイル: layout.cpp プロジェクト: JickLee/Core
void UILayout::update(float dt) {

    updateZIndex();

    vec2 inner = vec2(0.0f, 0.0f);

    int visible_elements = 0;

    std::list<UIElement*> fill_vert_elements;
    std::list<UIElement*> fill_horiz_elements;

    for(UIElement* e: elements) {
        e->resetRect();
        e->update(dt);

        if(e->isVisible()) {
            visible_elements++;

            if(e->fillHorizontal()) fill_horiz_elements.push_back(e);
            if(e->fillVertical())   fill_vert_elements.push_back(e);

            vec2 r = e->getRect();

            if(horizontal) {
                inner.x += r.x;
                inner.y = std::max(inner.y, r.y);
            } else {
                inner.x = std::max(inner.x, r.x);
                inner.y += r.y;
            }
        }
    }

    vec4 margin = getMargin();

    if(horizontal) {
        inner.x += margin.x+margin.z + ((float)visible_elements-1) * padding.x;
        inner.y += margin.y+margin.w;
    } else {
        inner.x += margin.x+margin.z;
        inner.y += margin.y+margin.w + ((float)visible_elements-1) * padding.y;
    }

    rect = glm::max(min_rect, inner);

    if(fill_vert_elements.empty() && fill_horiz_elements.empty()) return;

    vec2 filler = glm::max(vec2(0.0f), vec2(rect-inner)) + expanded_rect;

    if(horizontal && !fill_horiz_elements.empty()) {
        filler.x /= (float) fill_horiz_elements.size();
    } else if(!fill_vert_elements.empty()) {
        filler.y /= (float) fill_vert_elements.size();
    }

    std::list<UIElement*> fill_elements;
    fill_elements.insert(fill_elements.end(), fill_horiz_elements.begin(), fill_horiz_elements.end());
    fill_elements.insert(fill_elements.end(), fill_vert_elements.begin(), fill_vert_elements.end());

    fill_elements.unique();

    for(UIElement* e: fill_elements) {

        vec2 efill(0.0f);

        if(e->fillHorizontal()) {
            if(!horizontal) efill.x = filler.x + glm::max(0.0f, inner.x - e->rect.x - margin.x - margin.z);
            else efill.x = filler.x;
        }

        if(e->fillVertical()) {
            if(horizontal) efill.y = filler.y + glm::max(0.0f, inner.y - e->rect.y - margin.y - margin.w);
            else efill.y = filler.y;
        }

        if(efill.x > 0.0f || efill.y > 0.0f) {
            e->expandRect(efill);
            e->update(0.0f);
        }
    }

    if(!elements.empty() && elements.front()->getType() == UI_SELECT) debugLog("first element is a select");
}