Skip to content

Bar Panel Widget

Cristina Suciu edited this page Dec 23, 2020 · 1 revision

The DUXBetaBarPanelWidget belongs to the cluster of panel widgets. A Bar Panel Widget is a collection of simple widgets that can be grouped together in two orientations:

  • DUXBetaPanelVariant.horizontal
  • DUXBetaPanelVariant.vertical

This type of DUXBetaPanelWidget is primarily used for the application's top bar or other similarly sized widgets. The Bar Panel Widget is split into two lists: left and right (in vertical orientation left is equivalent to top and right to bottom.) Once a Bar Panel Widget has been created, widgets can be added to the left or right side. Bar Panel Widgets don't have a titlebar.

An example of a Bar Panel Widget is the TopBarPanelWidget

Configuration Options and Instantiation

When creating a DUXBetaBarPanelWidget, the configuration object specifies the widget type (DUXBetaPanelType) and variant (DUXBetaPanelVariant). Note, a Bar Panel Widget does not have a titlebar.

Creating a Bar Panel

Swift

let barConfigObject = DUXBetaPanelWidgetConfiguration(type: .bar, variant: .horizontal)
let myBarPanel = DUXBetaBarPanel().configure(barConfigObject)

Objective-C

DUXBetaPanelWidgetConfiguration *barConfigObject = [DUXBetaPanelWidgetConfiguration alloc] initWithType:DUXBetaPanelTypeBar variant::DUXBetaPanelVariantHorizontal];
DUXBetaBarPanel *myBarPanel = [[[DUXBetaBarPanel alloc] init] configure:barConfigObject];

Bar Panel Margins

It may be appropriate for a bar panel to have margins around it for visual clarity of its widgets. To add margins, simple call the setBarMargins method or set the margins individually.

Swift

barPanel.setBarMargins(marginInsets: UIEdgeInsets(top: 10.0, left: 5.0, bottom: 10.0, right: 5.0)

barPanel.topMargin = 10.0
barPanel.leftMargin = 5.0
barPanel.bottomMargin = 10.0
barPanel.rightMargin = 5.0

Objective-C

[barPanel setBarMarginsWithMarginInsets: UIEdgeInsetsMake(10.0, 5.0, 10.0, 5.0)];

barPanel.topMargin = 10.0
barPanel.leftMargin = 5.0
barPanel.bottomMargin = 10.0
barPanel.rightMargin = 5.0

Manipulating List Items

Bar Panel Widgets are manipulated by adding and removing widgets. You can retrieve the widget count, append widgets, insert widgets at a specific index, or remove widgets dynamically to either the left or right side. To initialize the Bar Panel Widget with widgets, pass an array of widgets when calling addRightWidgetArray, addLeftWidgetArray, or addWidgetArray. All list indexes are 0 based and index from leading to trailing (normally left to right.)

Bar Panel Methods

Counting widgets

The method widgetCount returns the number of widgets on the right hand side of a bar panel. For explicit access to either side, use rightWidgetCount or leftWidgetCount.

Swift

func widgetCount() -> Int
func rightWidgetCount() -> Int
func leftWidgetCount() -> Int

Objective-C

- (NSInteger)widgetCount;
- (NSInteger)rightWidgetCount;
- (NSInteger)leftWidgetCount;

Adding Widgets

The add methods are used to append an array of widgets to the end of the current widget list in the bar panel. To add a single widget, pass the widget wrapped in an array.

Inserting widgets into the middle of a bar is done one at a time. The bar index is 0 based, and you pass the index at which you want the new widget to, moving all the other widgets over in the bar. Pass an index of 0 to insert into the leading end of the bar panel section.

Swift

func addWidgetArray(displayWidgets: [ DUXBetaBaseWidget ])
func addRightWidgetArray(_ displayWidgets: [DUXBetaBaseWidget])
func addLeftWidgetArray(_ displayWidgets: [DUXBetaBaseWidget])

func insert(widget: DUXBetaBaseWidget, atIndex: Int)
func insertRightWidget(_ widget: DUXBetaBaseWidget, atIndex: Int)
func insertLeftWidget(_ widget: DUXBetaBaseWidget, atIndex: Int)

Objective-C

- (void)addWidgetArray:(NSArray<DUXBetaBaseWidget*>)displayWidgets;
- (void)addRightWidgetArray:(NSArray<DUXBetaBaseWidget *> * _Nonnull)displayWidgets;
- (void)addLeftWidgetArray:(NSArray<DUXBetaBaseWidget *> * _Nonnull)displayWidgets;

- (void)insertWithWidget:(DUXBetaBaseWidget)widget atIndex:(NSInteger)index;
- (void)insertRightWidget:(DUXBetaBaseWidget * _Nonnull)widget atIndex:(NSInteger)atIndex;
- (void)insertLeftWidget:(DUXBetaBaseWidget * _Nonnull)widget atIndex:(NSInteger)atIndex;

Removing Widgets

The removeWidget calls are fairly self-explanatory. Use the AtIndex version to remove a widget at a given index and the remove All, Right, or Left methods to remove the appropriate widgets. As usual, the methods which don't specify a side apply to the right side.

Swift

func removeWidget(atIndex: Int)
func removeRightWidget(atIndex: Int)
func removeLeftWidget(atIndex: Int) 

func removeAllWidgets()
func removeRightWidgets()
func removeLeftWidgets()

Objective-C

- (void)removeWidgetAtIndex:(NSInteger)index;
- (void)removeRightWidgetAtIndex:(NSInteger)atIndex;
- (void)removeLeftWidgetAtIndex:(NSInteger)atIndex;

- (void)removeAllWidgets;
- (void)removeRightWidgets;
- (void)removeLeftWidgets;
Clone this wiki locally