Skip to content

Commit

Permalink
Widgets|libgui: Working on directory browser
Browse files Browse the repository at this point in the history
Clicking on a directory will now change to that directory and repopulate
the list.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent dc3327b commit fcf8071
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
5 changes: 5 additions & 0 deletions doomsday/libs/gui/include/de/widgets/labelwidget.h
Expand Up @@ -187,6 +187,11 @@ class LIBGUI_PUBLIC LabelWidget : public GuiWidget, public IAssetGroup
*/
void setTextStyle(Font::RichFormat::IStyle const *richStyle);

/**
* Sets the font, text color, and margins for use as a menu/dialog separator label.
*/
void useSeparatorStyle();

/**
* Sets the alignment of the image when there is both an image
* and a text in the label.
Expand Down
6 changes: 4 additions & 2 deletions doomsday/libs/gui/src/directorytreedata.cpp
Expand Up @@ -47,12 +47,14 @@ DE_PIMPL(DirectoryTreeData)
// Populate a folder with the directory contents.
Folder folder(path.fileName());
folder.attach(new DirectoryFeed(path));
folder.populate(Folder::PopulateOnlyThisFolder | Folder::DisableNotification);
folder.populate(Folder::PopulateOnlyThisFolder | Folder::DisableNotification |
Folder::DisableIndexing);

// Create corresponding data items.
for (const auto &entry : folder.contents())
{
items << new DirectoryItem(entry.first, entry.second->status(), found->first);
const auto native = entry.second->correspondingNativePath();
items << new DirectoryItem(native.fileName(), entry.second->status(), found->first);
}

items.sort();
Expand Down
37 changes: 32 additions & 5 deletions doomsday/libs/gui/src/widgets/browserwidget.cpp
Expand Up @@ -21,14 +21,18 @@
#include "de/MenuWidget"
#include "de/ProgressWidget"
#include "de/ScrollAreaWidget"
#include "de/SequentialLayout"

namespace de {

DE_PIMPL(BrowserWidget)
//, DE_OBSERVES(ChildWidgetOrganizer, WidgetCreation)
{
const ui::TreeData *data = nullptr;
Path path;
LabelWidget *cwdLabel;
LabelWidget *currentPath;
LabelWidget *menuLabel;
ScrollAreaWidget *scroller;
MenuWidget *menu;

Expand All @@ -37,24 +41,34 @@ DE_PIMPL(BrowserWidget)
{
RuleRectangle &rule = self().rule();

SequentialLayout layout(rule.left(), rule.top(), ui::Down);
layout.setOverrideWidth(rule.width());

cwdLabel = LabelWidget::appendSeparatorWithText("Path", i);
layout << *cwdLabel;

currentPath = new LabelWidget("cwd");
currentPath->setSizePolicy(ui::Fixed, ui::Expand);
currentPath->rule()
.setLeftTop(rule.left(), rule.top())
.setInput(Rule::Width, rule.width());
currentPath->setAlignment(ui::AlignLeft);
layout << *currentPath;

menuLabel = LabelWidget::appendSeparatorWithText("Contents", i);
layout << *menuLabel;

scroller = new ScrollAreaWidget("scroller");
layout << *scroller;
scroller->rule()
.setLeftTop(rule.left(), currentPath->rule().bottom())
.setInput(Rule::Width, rule.width())
.setInput(Rule::Bottom, rule.bottom());

menu = new MenuWidget("items");
menu->setGridSize(1, ui::Filled, 0, ui::Expand);
menu->rule()
.setLeftTop(scroller->contentRule().left(), scroller->contentRule().top())
.setInput(Rule::Width, rule.width());
menu->enableScrolling(false);
menu->enablePageKeys(false);

// Virtualized menu expands to virtual height, so use another scroller as a parent.
scroller->setContentSize(menu->rule());
scroller->enablePageKeys(true);
scroller->enableScrolling(true);
Expand All @@ -63,18 +77,31 @@ DE_PIMPL(BrowserWidget)
i->add(currentPath);
scroller->add(menu);
i->add(scroller);

// menu->organizer().audienceForWidgetCreation() += this;
}

void changeTo(const Path &newPath)
{
DE_ASSERT(data);

scroller->scrollY(0);

// TODO: This is an async op, need to show progress widget.
path = newPath;
currentPath->setText(path);
const ui::Data &items = data->items(path);
menu->setItems(items);

// TODO: Recreate the path segment buttons.
}

// void widgetCreatedForItem(GuiWidget &widget, const ui::Item &item) override
// {
//// widget.as<ButtonWidget>().audienceForPress() += [this, &item]() {

//// };
// }
};

BrowserWidget::BrowserWidget(const String &name)
Expand Down
28 changes: 21 additions & 7 deletions doomsday/libs/gui/src/widgets/directorybrowserwidget.cpp
Expand Up @@ -27,10 +27,11 @@ DE_GUI_PIMPL(DirectoryBrowserWidget)
{
DirectoryTreeData dirTree;
IndirectRule *itemHeight = new IndirectRule;
LoopCallback mainCall;

Impl(Public *i) : Base(i)
{
itemHeight->setSource(font("default").height());
itemHeight->setSource(font("default").height() + rule("unit") * 2);

self().menu().organizer().setWidgetFactory(*this);
self().setData(dirTree, itemHeight->valuei());
Expand All @@ -41,12 +42,25 @@ DE_GUI_PIMPL(DirectoryBrowserWidget)
releaseRef(itemHeight);
}

GuiWidget *makeItemWidget(const ui::Item &, const GuiWidget *)
GuiWidget *makeItemWidget(const ui::Item &item, const GuiWidget *)
{
auto *lab = new LabelWidget;
lab->setSizePolicy(ui::Fixed, ui::Fixed);
lab->rule().setInput(Rule::Height, itemHeight);
return lab;
const auto &dirItem = item.as<DirectoryItem>();

auto *widget = new ButtonWidget;
widget->setSizePolicy(ui::Fixed, ui::Fixed);
widget->setAlignment(ui::AlignLeft);
widget->rule().setInput(Rule::Height, *itemHeight);
widget->margins().setTopBottom(rule("unit"));

if (dirItem.isDirectory())
{
const NativePath subDir = dirItem.path();
widget->audienceForPress() += [this, subDir]() {
mainCall.enqueue([this, subDir]() { self().setCurrentPath(subDir); });
};
}

return widget;
}

void updateItemWidget(GuiWidget &widget, const ui::Item &item)
Expand All @@ -65,7 +79,7 @@ DE_GUI_PIMPL(DirectoryBrowserWidget)
dirItem.status().size,
dirItem.status().modifiedAt.asText().c_str());
}
widget.as<LabelWidget>().setText(text);
widget.as<ButtonWidget>().setText(text);
}
};

Expand Down
13 changes: 10 additions & 3 deletions doomsday/libs/gui/src/widgets/labelwidget.cpp
Expand Up @@ -932,13 +932,20 @@ LabelWidget *LabelWidget::newWithText(const String &text, GuiWidget *parent)
return w;
}

void LabelWidget::useSeparatorStyle()
{
setSizePolicy(ui::Expand, ui::Expand);
setTextColor("accent");
setFont("separator.label");
setAlignment(ui::AlignLeft);
margins().setTop("gap");
}

LabelWidget *LabelWidget::appendSeparatorWithText(const String &text, GuiWidget *parent,
GridLayout *appendToGrid)
{
std::unique_ptr<LabelWidget> w(newWithText(text, parent));
w->setTextColor("accent");
w->setFont("separator.label");
w->margins().setTop("gap");
w->useSeparatorStyle();
if (appendToGrid)
{
appendToGrid->setCellAlignment({0, appendToGrid->gridSize().y}, ui::AlignLeft);
Expand Down

0 comments on commit fcf8071

Please sign in to comment.