如何将 NSOutlineView 的最后一个树项保留在侧边栏的最底部?

发布于 2024-08-03 06:54:15 字数 325 浏览 6 评论 0原文

我希望特殊项目具有与 Things 应用程序中相同的行为。我的意思是侧边栏底部的日志垃圾箱项目:

日志和垃圾箱项目位于最底部 http://tinyurl.com/lhctza

请告知在侧边栏树中实现相同功能的任何方法。

我觉得特殊的“spacer”树项应该与outlineView:heightOfRowByItem:方法一起使用。

但是,我找不到如何计算所有可见项目的总高度(包括组之间的空间)。

I'd like to have the same behavior of special items as it's done in the Things application. I mean Logbook and Trash items in the bottom part of the Sidebar:

Logbook and Trash items are in the most bottom http://tinyurl.com/lhctza

Please advise any way to implement the same functionality in the sidebar tree.

I feel that special ‘spacer’ tree item should be used together with outlineView:heightOfRowByItem: method.

However, I can't find how to calculate the total height of all visible items (incl. space between groups).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一袭白衣梦中忆 2024-08-10 06:54:16

您可以尝试简单地使用两个轮廓视图:一个具有固定高度,固定在其超级视图的底部,另一个具有可变高度,其底部紧邻第一个视图的顶部。固定高度大纲视图将包含日志和垃圾箱项目,可变高度大纲视图将包含所有其他项目。

棘手的部分是通过滚动视图使这个游戏变得更好,但我认为你可以做到。我想你会把它们放在一个完全可调整大小的 NSView 中,并使其成为滚动视图的文档视图。

You might try simply having two outline views: One of fixed height, pinned to the bottom of their superview, and the other of variable height, with its bottom immediately above the top of the first. The fixed-height outline view would contain those Logbook and Trash items, and the variable-height outline view would contain all the others.

The tricky part would be making this play nice with a scroll view, but I think you could do it. I imagine you'd put them both in a fully-resizable NSView and make that the scroll view's document view.

尴尬癌患者 2024-08-10 06:54:16

我决定通过为组样式中的每个根项添加 8 个像素的高度来硬编码该解决方案。
所以,代码如下:

- (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item;
{
    if (![item isSpacer]) return [ov rowHeight];

    static const CGFloat ADDITIONAL_SPACE = 8.0f;
    NSUInteger numberOfRootGroups = 2;
    CGFloat heightOfRows = [ov rowHeight] * ([ov rowForItem:item] + 1) 
        + ADDITIONAL_SPACE * numberOfRootGroups;
    CGFloat heightOfSidebar = [[ov superview] frame].size.height;
    return MAX(0.0f, heightOfSidebar - heightOfRows);
}

感谢大家的支持!

I've decided to hardcode the solution by adding 8 pixels of height for every root item in group style.
So, the code looks like this:

- (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item;
{
    if (![item isSpacer]) return [ov rowHeight];

    static const CGFloat ADDITIONAL_SPACE = 8.0f;
    NSUInteger numberOfRootGroups = 2;
    CGFloat heightOfRows = [ov rowHeight] * ([ov rowForItem:item] + 1) 
        + ADDITIONAL_SPACE * numberOfRootGroups;
    CGFloat heightOfSidebar = [[ov superview] frame].size.height;
    return MAX(0.0f, heightOfSidebar - heightOfRows);
}

Thanks to everybody for support!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文