Dropdown no longer embeds tomo.ContainerBox
This commit is contained in:
		
							parent
							
								
									0c4e098680
								
							
						
					
					
						commit
						df2e8f1b07
					
				
							
								
								
									
										40
									
								
								dropdown.go
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								dropdown.go
									
									
									
									
									
								
							| @ -6,10 +6,12 @@ import "git.tebibyte.media/tomo/tomo/input" | |||||||
| import "git.tebibyte.media/tomo/tomo/event" | import "git.tebibyte.media/tomo/tomo/event" | ||||||
| import "git.tebibyte.media/tomo/objects/layouts" | import "git.tebibyte.media/tomo/objects/layouts" | ||||||
| 
 | 
 | ||||||
|  | var _ tomo.Object = new(Dropdown) | ||||||
|  | 
 | ||||||
| // Dropdown is a non-editable text input that allows the user to pick a value | // Dropdown is a non-editable text input that allows the user to pick a value | ||||||
| // from a list. | // from a list. | ||||||
| type Dropdown struct { | type Dropdown struct { | ||||||
| 	tomo.ContainerBox | 	box   tomo.ContainerBox | ||||||
| 	label *Label | 	label *Label | ||||||
| 
 | 
 | ||||||
| 	value string | 	value string | ||||||
| @ -24,28 +26,40 @@ type Dropdown struct { | |||||||
| // NewDropdown creates a new dropdown input with the specified items | // NewDropdown creates a new dropdown input with the specified items | ||||||
| func NewDropdown (items ...string) *Dropdown { | func NewDropdown (items ...string) *Dropdown { | ||||||
| 	dropdown := &Dropdown { | 	dropdown := &Dropdown { | ||||||
| 		ContainerBox: tomo.NewContainerBox(), | 		box: tomo.NewContainerBox(), | ||||||
| 		label:        NewLabel(""), | 		label:        NewLabel(""), | ||||||
| 	} | 	} | ||||||
| 	dropdown.SetRole(tomo.R("objects", "Dropdown")) | 	dropdown.box.SetRole(tomo.R("objects", "Dropdown")) | ||||||
| 	dropdown.SetAttr(tomo.ALayout(layouts.Row { true, false })) | 	dropdown.box.SetAttr(tomo.ALayout(layouts.Row { true, false })) | ||||||
| 	dropdown.Add(dropdown.label) | 	dropdown.box.Add(dropdown.label) | ||||||
| 	dropdown.Add(NewIcon(tomo.IconListChoose, tomo.IconSizeSmall)) | 	dropdown.box.Add(NewIcon(tomo.IconListChoose, tomo.IconSizeSmall)) | ||||||
| 	 | 	 | ||||||
| 	dropdown.SetItems(items...) | 	dropdown.SetItems(items...) | ||||||
| 	if len(items) > 0 { | 	if len(items) > 0 { | ||||||
| 		dropdown.SetValue(items[0]) | 		dropdown.SetValue(items[0]) | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	dropdown.SetInputMask(true) | 	dropdown.box.SetInputMask(true) | ||||||
| 	dropdown.OnButtonDown(dropdown.handleButtonDown) | 	dropdown.box.OnButtonDown(dropdown.handleButtonDown) | ||||||
| 	dropdown.OnButtonUp(dropdown.handleButtonUp) | 	dropdown.box.OnButtonUp(dropdown.handleButtonUp) | ||||||
| 	dropdown.OnKeyDown(dropdown.handleKeyDown) | 	dropdown.box.OnKeyDown(dropdown.handleKeyDown) | ||||||
| 	dropdown.OnKeyUp(dropdown.handleKeyUp) | 	dropdown.box.OnKeyUp(dropdown.handleKeyUp) | ||||||
| 	dropdown.SetFocusable(true) | 	dropdown.box.SetFocusable(true) | ||||||
| 	return dropdown | 	return dropdown | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // GetBox returns the underlying box. | ||||||
|  | func (this *Dropdown) GetBox () tomo.Box { | ||||||
|  | 	return this.box | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // SetFocused sets whether or not this dropdown has keyboard focus. If set to | ||||||
|  | // true, this method will steal focus away from whichever object currently has | ||||||
|  | // focus. | ||||||
|  | func (this *Dropdown) SetFocused (focused bool) { | ||||||
|  | 	this.box.SetFocused(focused) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Value returns the value of the dropdown. This does not necissarily have to be | // Value returns the value of the dropdown. This does not necissarily have to be | ||||||
| // in the list of items. | // in the list of items. | ||||||
| func (this *Dropdown) Value () string { | func (this *Dropdown) Value () string { | ||||||
| @ -107,7 +121,7 @@ func (this *Dropdown) handleButtonDown (button input.Button) bool { | |||||||
| 
 | 
 | ||||||
| func (this *Dropdown) handleButtonUp (button input.Button) bool { | func (this *Dropdown) handleButtonUp (button input.Button) bool { | ||||||
| 	if !isClickingButton(button) { return false } | 	if !isClickingButton(button) { return false } | ||||||
| 	if this.Window().MousePosition().In(this.Bounds()) { | 	if this.box.Window().MousePosition().In(this.box.Bounds()) { | ||||||
| 		this.Choose() | 		this.Choose() | ||||||
| 	} | 	} | ||||||
| 	return true | 	return true | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user