embed

package
v0.0.0-...-4b8acdf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGIF

func IsGIF(url string) bool

IsGIF returns true if the URL is a GIF URL.

Types

type ControlsBoxEnd

type ControlsBoxEnd struct {
	*gtk.Box
}

func (*ControlsBoxEnd) AddEndButton

func (ce *ControlsBoxEnd) AddEndButton(pack gtk.PositionType, button *gtk.Button)

AddEndButton adds a button into the ControlsBoxEnd.

type ControlsBoxStart

type ControlsBoxStart struct {
	*gtk.Box

	Download     *gtk.Button
	CopyURL      *gtk.Button
	OpenOriginal *gtk.Button
}

func (*ControlsBoxStart) AddStartButton

func (cs *ControlsBoxStart) AddStartButton(pack gtk.PositionType, button *gtk.Button)

AddStartButton adds a button into the ControlsBoxStart.

type Embed

type Embed struct {
	*adw.Bin
	Button    *gtk.Button
	Thumbnail *onlineimage.Picture
	// contains filtered or unexported fields
}

Embed is a user-clickable image with an open callback.

Widget hierarchy:

  • Widgetter (?)
  • Button
  • Thumbnail

func New

func New(ctx context.Context, maxW, maxH int, opts Opts) *Embed

New creates a thumbnail Embed.

func (*Embed) ActivateDefault

func (e *Embed) ActivateDefault()

ActivateDefault triggers the default function that's called by default by SetOpenURL.

func (*Embed) NotifyImage

func (e *Embed) NotifyImage(f func()) glib.SignalHandle

NotifyImage calls f everytime the Embed thumbnail changes.

func (*Embed) SetFromURL

func (e *Embed) SetFromURL(url string)

SetFromURL sets the URL of the thumbnail embed.

func (*Embed) SetHAlign

func (e *Embed) SetHAlign(align gtk.Align)

SetHAlign sets the horizontal alignment of the embed relative to its parent.

func (*Embed) SetMaxSize

func (e *Embed) SetMaxSize(w, h int)

SetMaxSize sets the maximum size of the image.

func (*Embed) SetName

func (e *Embed) SetName(name string)

SetName sets the given embed name into everything that's displaying the embed name.

func (*Embed) SetOpenURL

func (e *Embed) SetOpenURL(f func())

SetOpenURL sets the callback to be called when the user clicks the image.

func (*Embed) SetSizeRequest

func (e *Embed) SetSizeRequest(w, h int)

SetSizeRequest sets the minimum size of a widget. The dimensions are clamped to the maximum size given during construction, if any.

func (*Embed) ShrinkMaxSize

func (e *Embed) ShrinkMaxSize(w, h int)

ShrinkMaxSize sets the maximum size of the image to be the smaller of the current maximum size and the given size.

func (*Embed) Size

func (e *Embed) Size() (w, h int)

Size returns the original embed size optionally scaled down, or 0 if no images have been fetched yet or if SetSize has never been called before.

func (*Embed) URL

func (e *Embed) URL() string

URL returns the Embed's current URL.

type EmbedType

type EmbedType uint8

EmbedType indicates the type of the Embed being constructed. The type determines how it's displayed visually to the user.

const (
	EmbedTypeImage EmbedType = iota
	EmbedTypeVideo
	EmbedTypeGIF
	EmbedTypeGIFV // video GIF
)

func TypeFromURL

func TypeFromURL(url string) EmbedType

TypeFromURL returns the EmbedType from the URL.

func (EmbedType) IsLooped

func (t EmbedType) IsLooped() bool

func (EmbedType) IsMuted

func (t EmbedType) IsMuted() bool

type Opts

type Opts struct {
	// Type is the embed type. Default is Image.
	Type EmbedType
	// Provider is the image provider to use. Default is HTTPProvider.
	Provider imgutil.Provider
	// Whole, if true, will make errors show in its full information instead of
	// being hidden behind an error icon. Use this for messages only.
	Whole bool
	// CanHide, if true, will make the image hide itself on error. Use this for
	// anything not important, like embeds.
	CanHide bool
	// IgnoreWidth, if true, will cause Embed to be initialized without ever
	// setting a width request. This has the benefit of allowing the Embed to be
	// shrunken to any width, but it will introduce letterboxing.
	IgnoreWidth bool
	// Autoplay, if true, will cause the video to autoplay. For GIFs and
	// GIFVs, the user won't have to hover over the image to play it.
	Autoplay bool
	// Tooltip, if true, will cause the embed to show a tooltip when hovered.
	// If the embed errors out, a tooltip will be shown regardless.
	Tooltip bool
}

Opts contains options for Embed.

type Viewer

type Viewer struct {
	*adw.Window

	Header       *adw.HeaderBar
	ToastOverlay *adw.ToastOverlay
	Overlay      *gtk.Overlay
	Scroll       *gtk.ScrolledWindow
	Embed        *Embed

	BackButton    *gtk.Button
	ControlsStart ControlsBoxStart
	ControlsEnd   ControlsBoxEnd
	// contains filtered or unexported fields
}

TODO: In libadwaita 1.4 replace BackButton with `set_show_back_button“

func NewViewer

func NewViewer(ctx context.Context, uri string, opts Opts) (*Viewer, error)

NewViewer creates a new instance of Viewer window, representing an image viewer.

func (*Viewer) SetShowBackButton

func (v *Viewer) SetShowBackButton(show bool)

SetShowBackButton sets whether to show back button at the start of headerbar.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL