Add focused color and style for BoxView title
- May define focused color and style for title which overrides normal color and style if set. - Use these in a catalog app. - Relates #804
This commit is contained in:
@@ -48,6 +48,8 @@ public class BoxView extends AbstractView {
|
|||||||
private Integer backgroundColor = -1;
|
private Integer backgroundColor = -1;
|
||||||
private int titleColor = -1;
|
private int titleColor = -1;
|
||||||
private int titleStyle = -1;
|
private int titleStyle = -1;
|
||||||
|
private int focusedTitleColor = -1;
|
||||||
|
private int focusedTitleStyle = -1;
|
||||||
private HorizontalAlign titleAlign;
|
private HorizontalAlign titleAlign;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -149,6 +151,26 @@ public class BoxView extends AbstractView {
|
|||||||
this.titleStyle = titleStyle;
|
this.titleStyle = titleStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a focused title color. Takes precedence set from
|
||||||
|
* {@link #setTitleColor(int)}.
|
||||||
|
*
|
||||||
|
* @param focusedTitleColor the title color
|
||||||
|
*/
|
||||||
|
public void setFocusedTitleColor(int focusedTitleColor) {
|
||||||
|
this.focusedTitleColor = focusedTitleColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a focused title style. Takes precedence set from
|
||||||
|
* {@link #setTitleStyle(int)}.
|
||||||
|
*
|
||||||
|
* @param focusedTitleStyle the title style
|
||||||
|
*/
|
||||||
|
public void setFocusedTitleStyle(int focusedTitleStyle) {
|
||||||
|
this.focusedTitleStyle = focusedTitleStyle;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a title align.
|
* Sets a title align.
|
||||||
*
|
*
|
||||||
@@ -180,12 +202,22 @@ public class BoxView extends AbstractView {
|
|||||||
screen.writerBuilder().layer(getLayer()).build().border(rect.x(), rect.y(), rect.width(), rect.height());
|
screen.writerBuilder().layer(getLayer()).build().border(rect.x(), rect.y(), rect.width(), rect.height());
|
||||||
if (StringUtils.hasText(title)) {
|
if (StringUtils.hasText(title)) {
|
||||||
Rectangle r = new Rectangle(rect.x() + 1, rect.y(), rect.width() - 2, 1);
|
Rectangle r = new Rectangle(rect.x() + 1, rect.y(), rect.width() - 2, 1);
|
||||||
if (titleColor > -1) {
|
|
||||||
screen.writerBuilder().layer(getLayer()).color(titleColor).style(titleStyle).build().text(title, r, titleAlign, VerticalAlign.TOP);
|
int color = -1;
|
||||||
|
int style = -1;
|
||||||
|
if (hasFocus()) {
|
||||||
|
color = focusedTitleColor;
|
||||||
|
style = focusedTitleStyle;
|
||||||
}
|
}
|
||||||
else {
|
if (color < 0) {
|
||||||
screen.writerBuilder().layer(getLayer()).build().text(title, r, titleAlign, VerticalAlign.TOP);
|
color = titleColor;
|
||||||
}
|
}
|
||||||
|
if (style < 0) {
|
||||||
|
style = titleStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
screen.writerBuilder().layer(getLayer()).color(color).style(style).build().text(title, r, titleAlign,
|
||||||
|
VerticalAlign.TOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getDrawFunction() != null) {
|
if (getDrawFunction() != null) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import org.springframework.shell.component.view.geom.Rectangle;
|
|||||||
import org.springframework.shell.component.view.message.ShellMessageBuilder;
|
import org.springframework.shell.component.view.message.ShellMessageBuilder;
|
||||||
import org.springframework.shell.component.view.screen.Screen;
|
import org.springframework.shell.component.view.screen.Screen;
|
||||||
import org.springframework.shell.component.view.screen.Screen.Writer;
|
import org.springframework.shell.component.view.screen.Screen.Writer;
|
||||||
|
import org.springframework.shell.component.view.screen.ScreenItem;
|
||||||
import org.springframework.shell.samples.catalog.scenario.Scenario;
|
import org.springframework.shell.samples.catalog.scenario.Scenario;
|
||||||
import org.springframework.shell.samples.catalog.scenario.ScenarioComponent;
|
import org.springframework.shell.samples.catalog.scenario.ScenarioComponent;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
@@ -196,6 +197,7 @@ public class Catalog {
|
|||||||
List<String> items = List.copyOf(categoryMap.keySet());
|
List<String> items = List.copyOf(categoryMap.keySet());
|
||||||
categories.setItems(items);
|
categories.setItems(items);
|
||||||
categories.setTitle("Categories");
|
categories.setTitle("Categories");
|
||||||
|
categories.setFocusedTitleStyle(ScreenItem.STYLE_BOLD);
|
||||||
categories.setShowBorder(true);
|
categories.setShowBorder(true);
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
@@ -215,6 +217,7 @@ public class Catalog {
|
|||||||
ListView<ScenarioData> scenarios = new ListView<>();
|
ListView<ScenarioData> scenarios = new ListView<>();
|
||||||
scenarios.setEventLoop(eventLoop);
|
scenarios.setEventLoop(eventLoop);
|
||||||
scenarios.setTitle("Scenarios");
|
scenarios.setTitle("Scenarios");
|
||||||
|
scenarios.setFocusedTitleStyle(ScreenItem.STYLE_BOLD);
|
||||||
scenarios.setShowBorder(true);
|
scenarios.setShowBorder(true);
|
||||||
scenarios.setCellFactory(list -> new ScenarioListCell());
|
scenarios.setCellFactory(list -> new ScenarioListCell());
|
||||||
return scenarios;
|
return scenarios;
|
||||||
|
|||||||
Reference in New Issue
Block a user