Changing icon of wxToolBarToolBase on toggle event - c++

I have a toggle button in a wxToolBar.
I'd like the button to show two different icons according its state (one icon when it's "pressed" and another when it's "released").
I tried this:
// toolbar setup:
muteBtn = toolBar -> AddCheckTool(
ID_MUTE_BTN,
wxT( "Mute" ),
wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ),
wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ),
wxT( "Enable/Disable sounds" ),
wxT( "Enable/Disable sounds" )
);
...
// EVT_BUTTON handler:
void MyFrame::MuteChanged( wxCommandEvent& event )
{
if ( event.IsChecked() )
{
Mute();
muteBtn -> SetNormalBitmap( wxBitmap( wxT( "mute.png" ), wxBITMAP_TYPE_PNG ) );
}
else
{
Unmute();
muteBtn -> SetNormalBitmap( wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ) );
}
// also tried refresh and update without success:
// toolBar -> Refresh();
// toolBar -> Update();
}
but the behavior is not the one I expect. Instead of:
startup icon: unmute.png
after first click: mute.png (Mute() called)
after second click: unmute.png (Unmute() called)
after thirth click: mute.png (Mute() called)
...
I got:
startup icon: unmute.png
after first click: unmute.png (Mute() called)
after second click: mute.png (Unmute() called)
after thirth click: unmute.png (Mute() called)
...
It seems that inside the event handler I change the icon but the bitmap is drawn only at the next click event.
I also tried adding wxToolBar::Refresh() and wxToolBar::Update() [see snippet] withouth success.
How can I get the correct behaviour?

The developers of wx confirmed that wxToolBarToolBase::SetNormalBitmap() should not be used.
I solved the problem by using the method wxToolBar::SetToolNormalBitmap:
// EVT_BUTTON handler:
void MyFrame::MuteChanged( wxCommandEvent& event )
{
if ( event.IsChecked() )
{
Mute();
toolBar -> SetToolNormalBitmap( ID_MUTE_BTN, wxBitmap( wxT( "mute.png" ), wxBITMAP_TYPE_PNG ) );
}
else
{
Unmute();
toolBar -> SetToolNormalBitmap( ID_MUTE_BTN, wxBitmap( wxT( "unmute.png" ), wxBITMAP_TYPE_PNG ) );
}
}

Related

How do I horizontally align a picker input and action buttons in a Shiny app?

The following code creates and h3 tab header, a picker input and 2 action buttons inside a class of page-header. The action buttons and slightly elevated compared to the picker input. I would like to get the action buttons to be horizontally aligned with the picker input (see red boxes in the screenshot).
How can I adjust this code to make it work.
library(shiny)
ui <- fluidPage(
div(
class = "page-header",
fluidRow(
column(
width = 8,
h3("Tab Header")
),
column(
width = 2,
pickerInput(
inputId = "picker",
label = "Picker:",
choices = c("Option 1", "Option 2", "Option 3")
)
),
column(
width = 2,
actionButton(inputId = "apply_1",
label = "Action 1",
icon = icon("play")),
actionButton(inputId = "reset_1",
label = "Action 2",
icon = icon("sync"))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
One option to horizontally align the pickerInput with the actionButtons would be to mimic the tag structure of the pickerInput, which looks like so:
<div>
<label>...</label>
<div>
....
</div>
</div>
For the label I added an invisible label by setting the color to transparent but there are probably more elegant approaches.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
div(
class = "page-header",
fluidRow(
column(
width = 8,
h3("Tab Header")
),
column(
width = 2,
pickerInput(
inputId = "picker",
label = "Picker:",
choices = c("Option 1", "Option 2", "Option 3")
)
),
column(
width = 2,
tags$div(
tags$label("Actions:", style="color: transparent"),
tags$div(
actionButton(
inputId = "apply_1",
label = "Action 1",
icon = icon("play")
),
actionButton(
inputId = "reset_1",
label = "Action 2",
icon = icon("sync")
)
)
)
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)

Handling of selectedvalue when both options are chosen

I am trying to create a dynamic chart tile when using drill-down. One of my slicers looks like this:
Here is my DAX formula for creating the snippet of the chart title:
var Standard = if(
isfiltered(yrs_data[Standard]),
if(exact(SELECTEDVALUE(yrs_data[Standard]),"Yes"),
"LOT TYPE=PROD",
"LOT TYPE=ENG"
),
"LOT TYPE=ALL"
)
The chart title works correctly except when both 'Yes' and 'No' are selected, then it incorrectly chooses "LOT TYPE=ENG", where I want it to be "LOT TYPE=ALL".
thx
Can you try this
test =
IF (
ISFILTERED ( yrs_data[Standard] ),
IF (
EXACT ( SELECTEDVALUE ( yrs_data[Standard] ), "Yes" ),
"LOT TYPE=PROD",
IF (
EXACT ( SELECTEDVALUE ( yrs_data[Standard] ), "No" ),
"LOT TYPE=ENG",
"LOT TYPE=ALL"
)
)
)

how to alter padding in shiny navbar

I'm trying to eliminate the space between this table and the left side of browser window, but when I do, it messes up the spacing of the nav bar links and title.
How can I remove padding/margin on the excelR table, without altering the padding/margin of the navbar/ui/li elements?
library(shiny)
library(excelR)
shinyApp(
ui = navbarPage("title", selected = "main",
position = "fixed-top",
tags$style(type="text/css", "body {padding-top: 70px;}"),
tags$head(
tags$style(
"body {overflow-y: hidden;}"
)
),
tags$head(
tags$style(type = "text/css", ".container-fluid {padding-left:0px;
padding-right:0px; margin-right:0px; margin-left:0px;}")
),
tabPanel("main", id = "main",
fluidPage(
excelOutput("table", width = "100%", height = "1000px")
#htmlOutput("table", width = "100%", height = "500px")
)
)
),
server = function(input, output, session) {
output$table <-renderExcel(
excelTable(
data = iris,
autoColTypes = FALSE,
autoFill = TRUE,
fullscreen = FALSE,
lazyLoading = TRUE,
search = TRUE,
tableHeight = "800px",
pagination <- NULL
)
)
}
)
You can simply add this additional css to your code:
tags$style(type = "text/css", ".navbar{padding-left:15px;
padding-right:15px ; margin-right:auto; margin-left:auto;}")
),
Hope this helps!

"tab-pane active" output when using navbarmenu as a first item in navbarpage

If navbarMenu is the first item in navbarPage, I get a “tab-pane active” output in the browser. This is a known issue. I could not find a solution or work-around, if any, hence the post. Any help is appreciated.
Using shiny_0.11.1
shinyUI(navbarPage("Regression", windowTitle = "Regression",
navbarMenu("Data",
tabPanel("Upload",
fluidRow(
column(12,
fileInput("csv_file", "Choose CSV Data File to Upload",
accept = c("text/csv",
"text/comma-separated-values",
".csv"))
)
),
tags$hr(),
dataTableOutput("csv_data_table")
),
tabPanel("Summary",
fluidRow(
column(4, offset = 4,
numericInput("datasummary_numobs_numeric",
"No. of Obs.",
value = NULL) #max = 6.0
)
),
tags$hr(),
dataTableOutput("datasummary_data_table")
)
)
))

Form can't scroll when contains list lwuit

Here's my code:
public Form getMenuForm()
{
if ( menuForm == null )
{
Form menuForm = new Form( "Tracking Main Menu" );
menuForm.setLayout( new BoxLayout( BoxLayout.Y_AXIS ) );
menuForm.setScrollable( true );
menuForm.setScrollableY( true );
menuForm.addComponent( this.getMenuList() );
for(int i=0;i<30;i++)
{
Label lblTest = new Label("hello guys");
menuForm.addComponent( lblTest );
}
menuForm.addCommand( new Command( "Exit" ) );
menuForm.setTransitionOutAnimator( CommonTransitions.createSlide( CommonTransitions.SLIDE_HORIZONTAL, true,
200 ) );
menuForm.addCommandListener( this );
}
return menuForm;
}
public List getMenuList()
{
String[] menuItems = { "Find Person", "Person Registration", "Message", "Setting" };
if ( menuList == null )
{
menuList = new List( menuItems );
menuList.setListCellRenderer( new DefaultListCellRenderer( false ) );
menuList.setSmoothScrolling( true );
menuList.setFixedSelection( List.FIXED_NONE );
menuList.addActionListener( this );
}
return menuList;
}
I only can select 4 options of list, and I CAN'T scroll down to see the bottom of screen. Do I miss something here, please help me...
You need to set menuForm to scrollable false and let the list's scrollability take over. You have nested scrollables one in another and that produces a bad user experience.
Maybe you need to do this:
menuList.setScroable(true);