From f2af92b4db76262506d30616395135099c7a2cf8 Mon Sep 17 00:00:00 2001 From: Nikita Sin <74384266+lesleysin@users.noreply.github.com> Date: Thu, 2 May 2024 22:13:56 +0300 Subject: [PATCH] feat: OverflowBox widget model (#33) --- pkg/duit_attributes/duit_flex/overflow_box_fit.go | 8 ++++++++ pkg/duit_attributes/overflow_box_attributes.go | 15 +++++++++++++++ pkg/duit_core/element_type.go | 1 + pkg/duit_widget/overflow_box.go | 10 ++++++++++ 4 files changed, 34 insertions(+) create mode 100644 pkg/duit_attributes/duit_flex/overflow_box_fit.go create mode 100644 pkg/duit_attributes/overflow_box_attributes.go create mode 100644 pkg/duit_widget/overflow_box.go diff --git a/pkg/duit_attributes/duit_flex/overflow_box_fit.go b/pkg/duit_attributes/duit_flex/overflow_box_fit.go new file mode 100644 index 0000000..879db32 --- /dev/null +++ b/pkg/duit_attributes/duit_flex/overflow_box_fit.go @@ -0,0 +1,8 @@ +package duit_flex + +type OverflowBoxFit string + +const ( + Max OverflowBoxFit = "max" + DeferToChild OverflowBoxFit = "deferToChild" +) diff --git a/pkg/duit_attributes/overflow_box_attributes.go b/pkg/duit_attributes/overflow_box_attributes.go new file mode 100644 index 0000000..ceb9c0e --- /dev/null +++ b/pkg/duit_attributes/overflow_box_attributes.go @@ -0,0 +1,15 @@ +package duit_attributes + +import ( + "github.com/lesleysin/duit_go/pkg/duit_attributes/duit_alignment" + "github.com/lesleysin/duit_go/pkg/duit_attributes/duit_flex" +) + +type OverflowBoxAttributes struct { + MinWidth float32 `json:"minWidth,omitempty"` + MaxWidth float32 `json:"maxWidth,omitempty"` + MinHeight float32 `json:"minHeight,omitempty"` + MaxHeight float32 `json:"maxHeight,omitempty"` + Alignment duit_alignment.Alignment `json:"alignment,omitempty"` + Fit duit_flex.OverflowBoxFit `json:"fit,omitempty"` +} diff --git a/pkg/duit_core/element_type.go b/pkg/duit_core/element_type.go index f99d902..2a696c0 100644 --- a/pkg/duit_core/element_type.go +++ b/pkg/duit_core/element_type.go @@ -41,4 +41,5 @@ const ( Meta DuitElementType = "Meta" ListView DuitElementType = "ListView" RepaintBoundary DuitElementType = "RepaintBoundary" + OverflowBox DuitElementType = "OverflowBox" ) diff --git a/pkg/duit_widget/overflow_box.go b/pkg/duit_widget/overflow_box.go new file mode 100644 index 0000000..7e0373c --- /dev/null +++ b/pkg/duit_widget/overflow_box.go @@ -0,0 +1,10 @@ +package duit_widget + +import ( + "github.com/lesleysin/duit_go/pkg/duit_attributes" + "github.com/lesleysin/duit_go/pkg/duit_core" +) + +func OverflowBoxUiElement(attributes *duit_attributes.OverflowBoxAttributes, id string, controlled bool) *duit_core.DuitElementModel { + return new(duit_core.DuitElementModel).CreateElement(duit_core.OverflowBox, id, "", attributes, nil, controlled, 1, nil) +}