Skip to content

Commit

Permalink
move RenderStandardBox rendering to WidgetBase; Box is effectively ju…
Browse files Browse the repository at this point in the history
…st an alias name now
  • Loading branch information
kkoreilly committed Apr 16, 2024
1 parent a3f9f35 commit a3f4131
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 30 deletions.
4 changes: 0 additions & 4 deletions core/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ package core
type Box struct {
WidgetBase
}

func (bx *Box) Render() {
bx.RenderStandardBox()
}
4 changes: 2 additions & 2 deletions core/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// and/or a menu. The standard behavior is to register a click event handler with
// OnClick.
type Button struct { //core:embedder
Box
WidgetBase

// Type is the type of button.
Type ButtonTypes
Expand Down Expand Up @@ -114,7 +114,7 @@ const (
)

func (bt *Button) OnInit() {
bt.Box.OnInit()
bt.WidgetBase.OnInit()
bt.HandleEvents()
bt.SetStyles()
}
Expand Down
6 changes: 3 additions & 3 deletions core/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// Canvas is a widget that can be arbitrarily drawn to by setting
// its Draw function using [Canvas.SetDraw].
type Canvas struct {
Box
WidgetBase

// Draw is the function used to draw the content of the
// canvas every time that it is rendered. The paint context
Expand All @@ -28,14 +28,14 @@ type Canvas struct {
}

func (c *Canvas) OnInit() {
c.Box.OnInit()
c.WidgetBase.OnInit()
c.Style(func(s *styles.Style) {
s.Min.Set(units.Dp(256))
})
}

func (c *Canvas) Render() {
c.Box.Render()
c.WidgetBase.Render()

sz := c.Geom.Size.Actual.Content
szp := c.Geom.Size.Actual.Content.ToPoint()
Expand Down
12 changes: 5 additions & 7 deletions core/chooser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ import (
"cogentcore.org/core/units"
)

// Chooser is for selecting items from a dropdown list, with an optional
// edit TextField for typing directly.
// The items can be of any type, including enum values -- they are converted
// to strings for the display. If the items are of type [icons.Icon], then they
// are displayed using icons instead.
// Chooser is a drop down selection widget that allows users to choose
// one option among a list of items.
type Chooser struct {
Box
WidgetBase

// Type is the styling type of the chooser.
Type ChooserTypes
Expand Down Expand Up @@ -137,14 +134,15 @@ const (
// Chooser with a background color
// and a bottom border
ChooserFilled ChooserTypes = iota

// ChooserOutlined represents an outlined
// Chooser with a border on all sides
// and no background color
ChooserOutlined
)

func (ch *Chooser) OnInit() {
ch.Box.OnInit()
ch.WidgetBase.OnInit()
ch.HandleEvents()
ch.SetStyles()
}
Expand Down
2 changes: 1 addition & 1 deletion core/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// control the size of an element. The [Handle.Styles.Direction]
// controls the direction in which the handle moves.
type Handle struct {
Box
WidgetBase

// Min is the minimum value that the handle can go to
// (typically the lower bound of the dialog/splits)
Expand Down
4 changes: 2 additions & 2 deletions core/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// size in [units.Dp] units (1/160th of an inch). See [views.ConfigImageToolbar]
// for a toolbar with I/O buttons.
type Image struct {
Box
WidgetBase

// Image is the bitmap image.
Image *image.RGBA `xml:"-" json:"-" set:"-"`
Expand Down Expand Up @@ -77,7 +77,7 @@ func (im *Image) SetImage(img image.Image) *Image {
}

func (im *Image) Render() {
im.Box.Render()
im.WidgetBase.Render()

if im.Image == nil {
return
Expand Down
7 changes: 5 additions & 2 deletions core/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,11 @@ func (wb *WidgetBase) PopBounds() {
// Render is the method that widgets should implement to define their
// custom rendering steps. It should not be called outside of
// [Widget.RenderWidget], which also does other steps applicable
// for all widgets.
func (wb *WidgetBase) Render() {}
// for all widgets. The base [WidgetBase.Render] implementation
// renders the standard box model.
func (wb *WidgetBase) Render() {
wb.RenderStandardBox()
}

// RenderWidget renders the widget and any parts and children that it has.
// It does not render if the widget is invisible. It calls Widget.Render]
Expand Down
2 changes: 1 addition & 1 deletion core/separator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// Separator draws a separator line. It goes in the direction
// specified by [style.Style.Direction].
type Separator struct {
Box
WidgetBase
}

func (sp *Separator) OnInit() {
Expand Down
4 changes: 2 additions & 2 deletions core/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// By default, it is [states.ReadOnly]. See [views.ConfigSVGToolbar] for a
// toolbar with panning, selecting, and I/O buttons.
type SVG struct {
Box
WidgetBase

// SVG is the SVG object associated with the element.
SVG *svg.SVG `set:"-"`
Expand Down Expand Up @@ -138,7 +138,7 @@ func (sv *SVG) SizeFinal() {
}

func (sv *SVG) Render() {
sv.Box.Render()
sv.WidgetBase.Render()

if sv.SVG == nil {
return
Expand Down
6 changes: 3 additions & 3 deletions core/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// Switch is a widget that can toggle between an on and off state.
// It can be displayed as a switch, checkbox, or radio button.
type Switch struct {
Box
WidgetBase

// the type of switch that this is
Type SwitchTypes `set:"-"`
Expand Down Expand Up @@ -60,7 +60,7 @@ const (
)

func (sw *Switch) OnInit() {
sw.Box.OnInit()
sw.WidgetBase.OnInit()
sw.HandleEvents()
sw.SetStyles()
}
Expand Down Expand Up @@ -330,5 +330,5 @@ func (sw *Switch) Render() {
ist.(*Layout).UpdateStackedVisibility()
}
}
sw.Box.Render()
sw.WidgetBase.Render()
}
4 changes: 2 additions & 2 deletions core/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (ts *Tabs) UnselectOtherTabs(idx int) {
// Tab is a tab button that contains any, all, or none of a label, an icon,
// and a close icon. Tabs should be made using the [Tabs.NewTab] function.
type Tab struct { //core:no-new
Box
WidgetBase

// Type is the styling type of the tab. This property
// must be set on the parent [Tabs] for it to work correctly.
Expand Down Expand Up @@ -543,7 +543,7 @@ type Tab struct { //core:no-new
}

func (tb *Tab) OnInit() {
tb.Box.OnInit()
tb.WidgetBase.OnInit()
tb.HandleClickOnEnterSpace()
tb.SetStyles()
}
Expand Down
3 changes: 2 additions & 1 deletion core/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ type Widget interface {
// Render is the method that widgets should implement to define their
// custom rendering steps. It should not be called outside of
// [Widget.RenderWidget], which also does other steps applicable
// for all widgets.
// for all widgets. The base [WidgetBase.Render] implementation
// renders the standard box model.
Render()

// RenderWidget renders the widget and any parts and children that it has.
Expand Down

0 comments on commit a3f4131

Please sign in to comment.