Skip to content

Commit

Permalink
Update file browser for text clipping change
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed Sep 17, 2020
1 parent 42ce285 commit ff794c1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions file-browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ void FileBrowser::render()

r.x += itemPadding;
r.w -= itemPadding * 2;
blit::screen.text(curDir + "/", font, r, true, blit::TextAlign::center_left, clipped);
blit::screen.clip = clipped;
blit::screen.text(curDir + "/", font, r, true, blit::TextAlign::center_left);

// back icon
if(!curDir.empty())
{
blit::Point iconOffset(-(backTextWidth + iconSize + 2), (itemHeight - font.char_h) / 2); // from the top-right

blit::screen.clip.w += backIconSpaceW;
blit::screen.text("Back", font, r, true, blit::TextAlign::center_right);
controlIcons.render(ControlIcons::Icon::B, r.tr() + iconOffset, blit::Pen(0x22, 0x22, 0x22), iconSize);
}
Expand Down Expand Up @@ -95,7 +97,8 @@ void FileBrowser::render()
auto str = f.name + ((f.flags & blit::FileFlags::directory) ? "/" : "");

blit::Rect r(filesDisplayRect.x, filesDisplayRect.y + yOff + y, filesDisplayRect.w, itemHeight);
blit::Rect clipped = r.intersection(filesDisplayRect);
auto &clipped = blit::screen.clip;
clipped = r.intersection(filesDisplayRect);

blit::screen.rectangle(clipped);

Expand All @@ -112,21 +115,23 @@ void FileBrowser::render()
r.x += itemPadding;
r.w -= itemPadding * 2;

blit::screen.text(str, font, r, true, blit::TextAlign::center_left, clipped);
blit::screen.text(str, font, r, true, blit::TextAlign::center_left);

// open icon
if(i == selectedFile)
{
clipped.w += openIconSpaceW;
blit::Point iconOffset(-(openTextWidth + iconSize + 2), (itemHeight - font.char_h) / 2); // from the top-right

blit::screen.text("Open", font, r, true, blit::TextAlign::center_right, clipped);
blit::screen.text("Open", font, r, true, blit::TextAlign::center_right);
controlIcons.render(ControlIcons::Icon::A, r.tr() + iconOffset, blit::Pen(0x22, 0x22, 0x22), iconSize);
}

y += itemHeight;
i++;
}

blit::screen.clip = blit::Rect(blit::Point(0), blit::screen.bounds);
}

void FileBrowser::update(uint32_t time)
Expand Down

0 comments on commit ff794c1

Please sign in to comment.