Skip to content

Commit

Permalink
Apply dimming effect to market title when not selected
Browse files Browse the repository at this point in the history
  • Loading branch information
axpoems committed Mar 5, 2024
1 parent a91b58c commit f767f85
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.Subscription;

import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -51,44 +53,59 @@ public static Comparator<MarketChannelItem> sortByMarketActivity() {

public static Callback<TableColumn<MarketChannelItem, MarketChannelItem>,
TableCell<MarketChannelItem, MarketChannelItem>> getMarketLabelCellFactory() {
return column -> new TableCell<>() {
private final Label marketName = new Label();
private final Label marketCode = new Label();
private final Label numOffers = new Label();
private final HBox hBox = new HBox(10, marketCode, numOffers);
private final VBox vBox = new VBox(0, marketName, hBox);
private final Tooltip tooltip = new BisqTooltip();
return column -> {
return new TableCell<>() {
private final Label marketName = new Label();
private final Label marketCode = new Label();
private final Label numOffers = new Label();
private final HBox hBox = new HBox(10, marketCode, numOffers);
private final VBox vBox = new VBox(0, marketName, hBox);
private final Tooltip tooltip = new BisqTooltip();
private Subscription selectedMarketPin;

{
setCursor(Cursor.HAND);
hBox.setAlignment(Pos.CENTER_LEFT);
vBox.setAlignment(Pos.CENTER_LEFT);
Tooltip.install(vBox, tooltip);
}

{
setCursor(Cursor.HAND);
marketName.getStyleClass().add("market-name");
hBox.setAlignment(Pos.CENTER_LEFT);
vBox.setAlignment(Pos.CENTER_LEFT);
Tooltip.install(vBox, tooltip);
}
@Override
protected void updateItem(MarketChannelItem item, boolean empty) {
super.updateItem(item, empty);

@Override
protected void updateItem(MarketChannelItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
marketName.setText(item.getMarket().getQuoteCurrencyName());
marketCode.setText(item.getMarket().getQuoteCurrencyCode());
StringExpression formattedNumOffers = Bindings.createStringBinding(() ->
BisqEasyOfferbookUtil.getFormattedOfferNumber(item.getNumOffers().get()), item.getNumOffers());
numOffers.textProperty().bind(formattedNumOffers);
StringExpression formattedTooltip = Bindings.createStringBinding(() ->
BisqEasyOfferbookUtil.getFormattedTooltip(item.getNumOffers().get(), item.getMarket().getQuoteCurrencyName()), item.getNumOffers());
tooltip.textProperty().bind(formattedTooltip);
tooltip.setStyle("-fx-text-fill: -fx-dark-text-color;");

setGraphic(vBox);
} else {
if (selectedMarketPin != null) {
selectedMarketPin.unsubscribe();
selectedMarketPin = null;
}
numOffers.textProperty().unbind();
tooltip.textProperty().unbind();
updateStyleClass(false);

if (item != null && !empty) {
selectedMarketPin = EasyBind.subscribe(item.getSelected(), this::updateStyleClass);
marketName.setText(item.getMarket().getQuoteCurrencyName());
marketCode.setText(item.getMarket().getQuoteCurrencyCode());
StringExpression formattedNumOffers = Bindings.createStringBinding(() ->
BisqEasyOfferbookUtil.getFormattedOfferNumber(item.getNumOffers().get()), item.getNumOffers());
numOffers.textProperty().bind(formattedNumOffers);
StringExpression formattedTooltip = Bindings.createStringBinding(() ->
BisqEasyOfferbookUtil.getFormattedTooltip(item.getNumOffers().get(),
item.getMarket().getQuoteCurrencyName()), item.getNumOffers());
tooltip.textProperty().bind(formattedTooltip);
tooltip.setStyle("-fx-text-fill: -fx-dark-text-color;");

setGraphic(vBox);
} else {
setGraphic(null);
}
}

setGraphic(null);
private void updateStyleClass(boolean isSelected) {
marketName.getStyleClass().removeAll("market-name", "market-name-selected");
marketName.getStyleClass().add(isSelected ? "market-name-selected" : "market-name");
}
}
};
};
}

Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/desktop/src/main/resources/css/bisq_easy.css
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@
}

.market-selection-list .market-name .text {
-fx-fill: -fx-mid-text-color !important;
-fx-text-fill: -fx-mid-text-color !important;
}

.market-selection-list .market-name-selected .text {
-fx-fill: -fx-light-text-color !important;
-fx-text-fill: -fx-light-text-color !important;
}
Expand Down

0 comments on commit f767f85

Please sign in to comment.