private bool DrawDefaultHandleEntry(SettingHandle handle, Rect trimmedEntryRect, bool mouseOverEntry) { var controlRect = new Rect(trimmedEntryRect.x + trimmedEntryRect.width / 2f, trimmedEntryRect.y, trimmedEntryRect.width / 2f, trimmedEntryRect.height); GenUI.SetLabelAlign(TextAnchor.MiddleLeft); var leftHalfRect = new Rect(trimmedEntryRect.x, trimmedEntryRect.y, trimmedEntryRect.width / 2f - HandleEntryPadding, trimmedEntryRect.height); // give full width to the label if custom control drawer is used- this allows handle titles to be used as section titles var labelRect = handle.CustomDrawer == null ? leftHalfRect : trimmedEntryRect; // reduce text size if label is long and wraps over to the second line var controlInfo = handleControlInfo[handle]; var cachedTitle = controlInfo.handleTitle ?? (controlInfo.handleTitle = new CachedLabel(handle.Title)); if (cachedTitle.GetHeight(labelRect.width) > labelRect.height) { Text.Font = GameFont.Tiny; labelRect = new Rect(labelRect.x, labelRect.y - 1f, labelRect.width, labelRect.height + 2f); } else { Text.Font = GameFont.Small; } Widgets.Label(labelRect, cachedTitle.Text); Text.Font = GameFont.Small; GenUI.ResetLabelAlign(); var valueChanged = false; if (handle.CustomDrawer == null) { var handleType = handle.ValueType; if (handleType.IsEnum) { handleType = typeof(Enum); } handleDrawers.TryGetValue(handleType, out var drawer); if (drawer == null) { drawer = defaultHandleDrawer; } valueChanged = drawer(handle, controlRect, controlInfo); } else { try { valueChanged = handle.CustomDrawer(controlRect); } catch (Exception e) { HugsLibController.Logger.ReportException(e, currentlyDrawnEntry, true, $"{nameof(SettingHandle)}.{nameof(SettingHandle.CustomDrawer)}"); } } if (mouseOverEntry) { DrawEntryHoverMenu(trimmedEntryRect, handle); } return(valueChanged); }
// draws the label and appropriate input for a single setting private void DrawHandleEntry(SettingHandle handle, Rect parentRect, ref float curY, float scrollViewHeight) { var entryHeight = HandleEntryHeight; if (handle.CustomDrawer != null && handle.CustomDrawerHeight > entryHeight) { entryHeight = handle.CustomDrawerHeight + HandleEntryPadding * 2; } var skipDrawing = curY - scrollPosition.y + entryHeight <0f || curY - scrollPosition.y> scrollViewHeight; if (!skipDrawing) { var entryRect = new Rect(parentRect.x, parentRect.y + curY, parentRect.width, entryHeight).ContractedBy(HandleEntryPadding); var mouseOver = Mouse.IsOver(entryRect); if (mouseOver) { Widgets.DrawHighlight(entryRect); } var controlRect = new Rect(entryRect.x + entryRect.width / 2f, entryRect.y, entryRect.width / 2f, entryRect.height); GenUI.SetLabelAlign(TextAnchor.MiddleLeft); var leftHalfRect = new Rect(entryRect.x, entryRect.y, entryRect.width / 2f - HandleEntryPadding, entryRect.height); var labelRect = handle.CustomDrawer == null ? leftHalfRect : entryRect; // give full width to the label just in case Widgets.Label(labelRect, handle.Title); GenUI.ResetLabelAlign(); bool valueChanged = false; if (handle.CustomDrawer == null) { SettingsHandleDrawer drawer; var handleType = handle.ValueType; if (handleType.IsEnum) { handleType = typeof(Enum); } handleDrawers.TryGetValue(handleType, out drawer); if (drawer == null) { drawer = defaultHandleDrawer; } valueChanged = drawer(handle, controlRect, handleControlInfo[handle]); } else { try { valueChanged = handle.CustomDrawer(controlRect); } catch (Exception e) { HugsLibController.Logger.ReportException(e, currentlyDrawnEntry, true, "SettingsHandle.CustomDrawer"); } } if (valueChanged) { settingsHaveChanged = true; } if (mouseOver) { if (!handle.Description.NullOrEmpty()) { TooltipHandler.TipRegion(entryRect, handle.Description); } if (Input.GetMouseButtonUp(1)) { var options = new List <FloatMenuOption>(1); options.Add(new FloatMenuOption("HugsLib_settings_resetValue".Translate(), () => { ResetSetting(handle); })); Find.WindowStack.Add(new FloatMenu(options)); } } } curY += entryHeight; }