mirror of https://github.com/anoshenko/rui.git
				
				
				
			Added support of AccentColor to Checkbox, ListView, and TableView
This commit is contained in:
		
							parent
							
								
									6afb518645
								
							
						
					
					
						commit
						1110375cb6
					
				
							
								
								
									
										18
									
								
								checkbox.go
								
								
								
								
							
							
						
						
									
										18
									
								
								checkbox.go
								
								
								
								
							|  | @ -112,6 +112,14 @@ func (button *checkboxData) set(tag string, value any) bool { | |||
| 	case CellVerticalAlign, CellHorizontalAlign, CellWidth, CellHeight: | ||||
| 		return false | ||||
| 
 | ||||
| 	case AccentColor: | ||||
| 		if !button.setColorProperty(AccentColor, value) { | ||||
| 			return false | ||||
| 		} | ||||
| 		if button.created { | ||||
| 			updateInnerHTML(button.htmlID(), button.session) | ||||
| 		} | ||||
| 
 | ||||
| 	default: | ||||
| 		return button.viewsContainerData.set(tag, value) | ||||
| 	} | ||||
|  | @ -278,10 +286,16 @@ func (button *checkboxData) htmlCheckbox(buffer *strings.Builder, checked bool) | |||
| 	} | ||||
| 
 | ||||
| 	buffer.WriteString(`">`) | ||||
| 
 | ||||
| 	accentColor := Color(0) | ||||
| 	if color := GetAccentColor(button, ""); color != 0 { | ||||
| 		accentColor = color | ||||
| 	} | ||||
| 
 | ||||
| 	if checked { | ||||
| 		buffer.WriteString(button.Session().checkboxOnImage()) | ||||
| 		buffer.WriteString(button.Session().checkboxOnImage(accentColor)) | ||||
| 	} else { | ||||
| 		buffer.WriteString(button.Session().checkboxOffImage()) | ||||
| 		buffer.WriteString(button.Session().checkboxOffImage(accentColor)) | ||||
| 	} | ||||
| 	buffer.WriteString(`</div>`) | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										16
									
								
								listView.go
								
								
								
								
							
							
						
						
									
										16
									
								
								listView.go
								
								
								
								
							|  | @ -322,6 +322,11 @@ func (listView *listViewData) set(tag string, value any) bool { | |||
| 			return false | ||||
| 		} | ||||
| 
 | ||||
| 	case AccentColor: | ||||
| 		if !listView.setColorProperty(AccentColor, value) { | ||||
| 			return false | ||||
| 		} | ||||
| 
 | ||||
| 	default: | ||||
| 		return listView.viewData.set(tag, value) | ||||
| 	} | ||||
|  | @ -672,12 +677,17 @@ func (listView *listViewData) getDivs(checkbox, hCheckboxAlign, vCheckboxAlign i | |||
| 
 | ||||
| 	offDivBuilder.WriteString(onDivBuilder.String()) | ||||
| 
 | ||||
| 	accentColor := Color(0) | ||||
| 	if color := GetAccentColor(listView, ""); color != 0 { | ||||
| 		accentColor = color | ||||
| 	} | ||||
| 
 | ||||
| 	if checkbox == SingleCheckbox { | ||||
| 		offDivBuilder.WriteString(session.radiobuttonOffImage()) | ||||
| 		onDivBuilder.WriteString(session.radiobuttonOnImage()) | ||||
| 		onDivBuilder.WriteString(session.radiobuttonOnImage(accentColor)) | ||||
| 	} else { | ||||
| 		offDivBuilder.WriteString(session.checkboxOffImage()) | ||||
| 		onDivBuilder.WriteString(session.checkboxOnImage()) | ||||
| 		offDivBuilder.WriteString(session.checkboxOffImage(accentColor)) | ||||
| 		onDivBuilder.WriteString(session.checkboxOnImage(accentColor)) | ||||
| 	} | ||||
| 
 | ||||
| 	onDivBuilder.WriteString("</div>") | ||||
|  |  | |||
|  | @ -125,10 +125,10 @@ type Session interface { | |||
| 	registerAnimation(props []AnimatedProperty) string | ||||
| 
 | ||||
| 	resolveConstants(value string) (string, bool) | ||||
| 	checkboxOffImage() string | ||||
| 	checkboxOnImage() string | ||||
| 	checkboxOffImage(accentColor Color) string | ||||
| 	checkboxOnImage(accentColor Color) string | ||||
| 	radiobuttonOffImage() string | ||||
| 	radiobuttonOnImage() string | ||||
| 	radiobuttonOnImage(accentColor Color) string | ||||
| 
 | ||||
| 	viewByHTMLID(id string) View | ||||
| 	nextViewID() string | ||||
|  |  | |||
|  | @ -203,7 +203,7 @@ func (session *sessionData) SetCustomTheme(name string) bool { | |||
| 
 | ||||
| const checkImage = `<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="m4 8 3 4 5-8" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5"/></svg>` | ||||
| 
 | ||||
| func (session *sessionData) checkboxImage(checked bool) string { | ||||
| func (session *sessionData) checkboxImage(checked bool, accentColor Color) string { | ||||
| 
 | ||||
| 	var borderColor, backgroundColor Color | ||||
| 	var ok bool | ||||
|  | @ -217,7 +217,9 @@ func (session *sessionData) checkboxImage(checked bool) string { | |||
| 	} | ||||
| 
 | ||||
| 	if checked { | ||||
| 		if backgroundColor, ok = session.Color("ruiHighlightColor"); !ok { | ||||
| 		if accentColor != 0 { | ||||
| 			backgroundColor = accentColor | ||||
| 		} else if backgroundColor, ok = session.Color("ruiHighlightColor"); !ok { | ||||
| 			backgroundColor = 0xFF1A74E8 | ||||
| 		} | ||||
| 	} else if backgroundColor, ok = session.Color("ruiBackgroundColor"); !ok { | ||||
|  | @ -244,16 +246,22 @@ func (session *sessionData) checkboxImage(checked bool) string { | |||
| 	return buffer.String() | ||||
| } | ||||
| 
 | ||||
| func (session *sessionData) checkboxOffImage() string { | ||||
| func (session *sessionData) checkboxOffImage(accentColor Color) string { | ||||
| 	if accentColor != 0 { | ||||
| 		return session.checkboxImage(false, accentColor) | ||||
| 	} | ||||
| 	if session.checkboxOff == "" { | ||||
| 		session.checkboxOff = session.checkboxImage(false) | ||||
| 		session.checkboxOff = session.checkboxImage(false, accentColor) | ||||
| 	} | ||||
| 	return session.checkboxOff | ||||
| } | ||||
| 
 | ||||
| func (session *sessionData) checkboxOnImage() string { | ||||
| func (session *sessionData) checkboxOnImage(accentColor Color) string { | ||||
| 	if accentColor != 0 { | ||||
| 		return session.checkboxImage(true, accentColor) | ||||
| 	} | ||||
| 	if session.checkboxOn == "" { | ||||
| 		session.checkboxOn = session.checkboxImage(true) | ||||
| 		session.checkboxOn = session.checkboxImage(true, accentColor) | ||||
| 	} | ||||
| 	return session.checkboxOn | ||||
| } | ||||
|  | @ -285,12 +293,14 @@ func (session *sessionData) radiobuttonOffImage() string { | |||
| 	return session.radiobuttonOff | ||||
| } | ||||
| 
 | ||||
| func (session *sessionData) radiobuttonOnImage() string { | ||||
| func (session *sessionData) radiobuttonOnImage(accentColor Color) string { | ||||
| 	if session.radiobuttonOn == "" { | ||||
| 		var borderColor, backgroundColor Color | ||||
| 		var ok bool | ||||
| 
 | ||||
| 		if borderColor, ok = session.Color("ruiHighlightColor"); !ok { | ||||
| 		if accentColor != 0 { | ||||
| 			borderColor = accentColor | ||||
| 		} else if borderColor, ok = session.Color("ruiHighlightColor"); !ok { | ||||
| 			borderColor = 0xFF1A74E8 | ||||
| 		} | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										10
									
								
								tableView.go
								
								
								
								
							
							
						
						
									
										10
									
								
								tableView.go
								
								
								
								
							|  | @ -588,7 +588,7 @@ func (table *tableViewData) propertyChanged(tag string) { | |||
| 			CellBorder, HeadHeight, HeadStyle, FootHeight, FootStyle, | ||||
| 			CellPaddingTop, CellPaddingRight, CellPaddingBottom, CellPaddingLeft, | ||||
| 			TableCellClickedEvent, TableCellSelectedEvent, TableRowClickedEvent, | ||||
| 			TableRowSelectedEvent, AllowSelection: | ||||
| 			TableRowSelectedEvent, AllowSelection, AccentColor: | ||||
| 			table.ReloadTableData() | ||||
| 
 | ||||
| 		case Current: | ||||
|  | @ -1350,10 +1350,14 @@ func (table *tableViewData) writeCellHtml(adapter TableAdapter, row, column int, | |||
| 		buffer.WriteString(fmt.Sprintf("%g", value)) | ||||
| 
 | ||||
| 	case bool: | ||||
| 		accentColor := Color(0) | ||||
| 		if color := GetAccentColor(table, ""); color != 0 { | ||||
| 			accentColor = color | ||||
| 		} | ||||
| 		if value { | ||||
| 			buffer.WriteString(table.Session().checkboxOnImage()) | ||||
| 			buffer.WriteString(table.Session().checkboxOnImage(accentColor)) | ||||
| 		} else { | ||||
| 			buffer.WriteString(table.Session().checkboxOffImage()) | ||||
| 			buffer.WriteString(table.Session().checkboxOffImage(accentColor)) | ||||
| 		} | ||||
| 
 | ||||
| 	default: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue