Implement defining screens in yaml
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
// LabelOpts defines the options for a label.
|
||||
type LabelOpts interface {
|
||||
ApplyTo(*widget.Label)
|
||||
}
|
||||
@ -19,10 +20,12 @@ type allignmentOpt struct {
|
||||
Alignment fyne.TextAlign
|
||||
}
|
||||
|
||||
// AlignmentOpt returns a LabelOpts with the specified alignment.
|
||||
func AlignmentOpt(alignment fyne.TextAlign) LabelOpts {
|
||||
return &allignmentOpt{alignment}
|
||||
}
|
||||
|
||||
// ApplyTo sets the alignment of a label to the specified alignment.
|
||||
func (a *allignmentOpt) ApplyTo(lbl *widget.Label) {
|
||||
lbl.Alignment = a.Alignment
|
||||
}
|
||||
@ -31,10 +34,12 @@ type wrappingOpt struct {
|
||||
Wrapping fyne.TextWrap
|
||||
}
|
||||
|
||||
// WrappingOpt creates a LabelOpts with the specified text wrapping option.
|
||||
func WrappingOpt(wrapping fyne.TextWrap) LabelOpts {
|
||||
return &wrappingOpt{wrapping}
|
||||
}
|
||||
|
||||
// ApplyTo applies the wrapping option to the label.
|
||||
func (w *wrappingOpt) ApplyTo(lbl *widget.Label) {
|
||||
lbl.Wrapping = w.Wrapping
|
||||
}
|
||||
@ -43,10 +48,12 @@ type textStyleOpt struct {
|
||||
Style fyne.TextStyle
|
||||
}
|
||||
|
||||
// TextStyleOpt returns the label options for the given text style.
|
||||
func TextStyleOpt(style fyne.TextStyle) LabelOpts {
|
||||
return &textStyleOpt{style}
|
||||
}
|
||||
|
||||
// ApplyTo applies the text style option to the label.
|
||||
func (t *textStyleOpt) ApplyTo(lbl *widget.Label) {
|
||||
lbl.TextStyle = t.Style
|
||||
}
|
||||
@ -55,10 +62,12 @@ type truncationOpt struct {
|
||||
Truncation fyne.TextTruncation
|
||||
}
|
||||
|
||||
// TruncationOpt returns the label options for the given text truncation option.
|
||||
func TruncationOpt(truncation fyne.TextTruncation) LabelOpts {
|
||||
return &truncationOpt{truncation}
|
||||
}
|
||||
|
||||
// ApplyTo applies the text truncation option to the label.
|
||||
func (t *truncationOpt) ApplyTo(lbl *widget.Label) {
|
||||
lbl.Truncation = t.Truncation
|
||||
}
|
||||
@ -67,14 +76,23 @@ type importanceOpt struct {
|
||||
Importance widget.Importance
|
||||
}
|
||||
|
||||
// ImportanceOpt returns the label options for the given text importance option.
|
||||
func ImportanceOpt(importance widget.Importance) LabelOpts {
|
||||
return &importanceOpt{importance}
|
||||
}
|
||||
|
||||
// ApplyTo applies the text importance option to the label.
|
||||
func (i *importanceOpt) ApplyTo(lbl *widget.Label) {
|
||||
lbl.Importance = i.Importance
|
||||
}
|
||||
|
||||
// NewLabel creates a new label widget with the given text and options.
|
||||
//
|
||||
// Arguments
|
||||
// - text: the text to be displayed on the label.
|
||||
// - opts: optional configuration options for the label.
|
||||
//
|
||||
// Returns *widget.Label: a pointer to the newly created label widget.
|
||||
func NewLabel(text string, opts ...LabelOpts) *widget.Label {
|
||||
lbl := widget.NewLabel(text)
|
||||
for _, opt := range opts {
|
||||
@ -83,6 +101,13 @@ func NewLabel(text string, opts ...LabelOpts) *widget.Label {
|
||||
return lbl
|
||||
}
|
||||
|
||||
// NewLabelWithData creates a new Label widget with the provided data and options.
|
||||
//
|
||||
// Arguments
|
||||
// - data: The string data to be displayed on the label.
|
||||
// - opts: Additional options to customize the label.
|
||||
//
|
||||
// Returns *widget.Label: a pointer to the newly created Label widget.
|
||||
func NewLabelWithData(data binding.String, opts ...LabelOpts) *widget.Label {
|
||||
lbl := widget.NewLabelWithData(data)
|
||||
for _, opt := range opts {
|
||||
@ -91,6 +116,14 @@ func NewLabelWithData(data binding.String, opts ...LabelOpts) *widget.Label {
|
||||
return lbl
|
||||
}
|
||||
|
||||
// NewUpDownLabelWithData creates a new label widget with up and down buttons.
|
||||
//
|
||||
// Arguments
|
||||
// - data: the string data to display in the label.
|
||||
// - upHandler: the function to call when the up button is clicked.
|
||||
// - downHandler: the function to call when the down button is clicked.
|
||||
//
|
||||
// Returns fyne.CanvasObject: the created widget.
|
||||
func NewUpDownLabelWithData(
|
||||
data binding.String,
|
||||
upHandler func(),
|
||||
@ -115,11 +148,25 @@ func NewUpDownLabelWithData(
|
||||
return c1
|
||||
}
|
||||
|
||||
// NewH creates a RichText widget formatted as a header of the provided level.
|
||||
//
|
||||
// Parameters:
|
||||
// - level: an integer representing the level of the text.
|
||||
// - text: a string containing the text to display.
|
||||
//
|
||||
// Returns a pointer to a RichText widget.
|
||||
func NewH(level int, text string) *widget.RichText {
|
||||
return widget.NewRichTextFromMarkdown(
|
||||
fmt.Sprintf("%s %s", strings.Repeat("#", level), text))
|
||||
}
|
||||
|
||||
// NewHWithData creates a new RichText widget formatted as a header of the provided level.
|
||||
//
|
||||
// Parameters:
|
||||
// - level: an integer representing the level of the text.
|
||||
// - data: a string binding containing the text to display.
|
||||
//
|
||||
// Returns a pointer to a RichText widget.
|
||||
func NewHWithData(level int, data binding.String) *widget.RichText {
|
||||
txt, _ := data.Get()
|
||||
w := NewH(level, txt)
|
||||
@ -130,50 +177,62 @@ func NewHWithData(level int, data binding.String) *widget.RichText {
|
||||
return w
|
||||
}
|
||||
|
||||
// NewH1 creates a new RichText widget with header level 1.
|
||||
func NewH1(text string) *widget.RichText {
|
||||
return NewH(1, text)
|
||||
}
|
||||
|
||||
// NewH1WithData creates a new RichText widget with header level 1.
|
||||
func NewH1WithData(data binding.String) *widget.RichText {
|
||||
return NewHWithData(1, data)
|
||||
}
|
||||
|
||||
// NewH2 creates a new RichText widget with header level 2.
|
||||
func NewH2(text string) *widget.RichText {
|
||||
return NewH(2, text)
|
||||
}
|
||||
|
||||
// NewH2WithData creates a new RichText widget with header level 2.
|
||||
func NewH2WithData(data binding.String) *widget.RichText {
|
||||
return NewHWithData(2, data)
|
||||
}
|
||||
|
||||
// NewH3 creates a new RichText widget with header level 3.
|
||||
func NewH3(text string) *widget.RichText {
|
||||
return NewH(3, text)
|
||||
}
|
||||
|
||||
// NewH3WithData creates a new RichText widget with header level 3.
|
||||
func NewH3WithData(data binding.String) *widget.RichText {
|
||||
return NewHWithData(3, data)
|
||||
}
|
||||
|
||||
// NewH4 creates a new RichText widget with header level 4.
|
||||
func NewH4(text string) *widget.RichText {
|
||||
return NewH(4, text)
|
||||
}
|
||||
|
||||
// NewH4WithData creates a new RichText widget with header level 4.
|
||||
func NewH4WithData(data binding.String) *widget.RichText {
|
||||
return NewHWithData(4, data)
|
||||
}
|
||||
|
||||
// NewH5 creates a new RichText widget with header level 5.
|
||||
func NewH5(text string) *widget.RichText {
|
||||
return NewH(5, text)
|
||||
}
|
||||
|
||||
// NewH5WithData creates a new RichText widget with header level 5.
|
||||
func NewH5WithData(data binding.String) *widget.RichText {
|
||||
return NewHWithData(5, data)
|
||||
}
|
||||
|
||||
// NewH6 creates a new RichText widget with header level 6.
|
||||
func NewH6(text string) *widget.RichText {
|
||||
return NewH(6, text)
|
||||
}
|
||||
|
||||
// NewH6WithData creates a new RichText widget with header level 6.
|
||||
func NewH6WithData(data binding.String) *widget.RichText {
|
||||
return NewHWithData(6, data)
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ import (
|
||||
"fyne.io/fyne/v2/theme"
|
||||
)
|
||||
|
||||
// NewWidgetBorder creates a new widget border for the given fyne.CanvasObject.
|
||||
// It does so by wrapping the object in a Stack layout with a border drawn
|
||||
// above the widget.
|
||||
func NewWidgetBorder(widget fyne.CanvasObject) fyne.CanvasObject {
|
||||
b := canvas.NewRectangle(color.Transparent)
|
||||
b.StrokeColor = theme.InputBorderColor()
|
||||
|
Reference in New Issue
Block a user