widgets/wrapper: add distinct top/bottom/left/right margins

This commit is contained in:
outfoxxed 2025-05-12 13:53:07 -07:00
parent ca26210cc4
commit ead9141aca
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 230 additions and 51 deletions

View file

@ -6,7 +6,7 @@ import QtQuick
/// border, see @@ClippingWrapperRectangle.
///
/// > [!NOTE] WrapperRectangle is a @@MarginWrapperManager based component.
/// > You should read its documentation as well.
/// > See its documentation for information on how margins and sizes are calculated.
///
/// > [!WARNING] You should not set @@Item.x, @@Item.y, @@Item.width,
/// > @@Item.height or @@Item.anchors on the child item, as they are used
@ -16,20 +16,40 @@ Rectangle {
id: root
/// If true (default), the rectangle's border width will be added
/// to the margin.
/// to @@extraMargin.
property bool contentInsideBorder: true
/// The minimum margin between the child item and the WrapperRectangle's
/// edges. If @@contentInsideBorder is true, this excludes the border,
/// otherwise it includes it. Defaults to 0.
property real margin: 0
/// If the child item should be resized larger than its implicit size if
/// the WrapperRectangle is resized larger than its implicit size. Defaults to false.
/// The default for @@topMargin, @@bottomMargin, @@leftMargin and @@rightMargin.
/// Defaults to 0.
property /*real*/alias margin: manager.margin
/// An extra margin applied in addition to @@topMargin, @@bottomMargin,
/// @@leftMargin, and @@rightMargin.
/// If @@contentInsideBorder is true, the rectangle's border width will be added
/// to this property. Defaults to 0.
property real extraMargin: 0
/// The requested top margin of the content item, not counting @@extraMargin.
///
/// Defaults to @@margin, and may be reset by assigning `undefined`.
property /*real*/alias topMargin: manager.topMargin
/// The requested bottom margin of the content item, not counting @@extraMargin.
///
/// Defaults to @@margin, and may be reset by assigning `undefined`.
property /*real*/alias bottomMargin: manager.bottomMargin
/// The requested left margin of the content item, not counting @@extraMargin.
///
/// Defaults to @@margin, and may be reset by assigning `undefined`.
property /*real*/alias leftMargin: manager.leftMargin
/// The requested right margin of the content item, not counting @@extraMargin.
///
/// Defaults to @@margin, and may be reset by assigning `undefined`.
property /*real*/alias rightMargin: manager.rightMargin
/// Determines if child item should be resized larger than its implicit size if
/// the parent is resized larger than its implicit size. Defaults to false.
property /*bool*/alias resizeChild: manager.resizeChild
/// See @@WrapperManager.child for details.
property alias child: manager.child
MarginWrapperManager {
id: manager
margin: (root.contentInsideBorder ? root.border.width : 0) + root.margin
extraMargin: (root.contentInsideBorder ? root.border.width : 0) + root.extraMargin
}
}