1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2009-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19 20-module(ex_slider). 21 22-behaviour(wx_object). 23 24-export([start/1, init/1, terminate/2, code_change/3, 25 handle_info/2, handle_call/3, handle_cast/2, handle_event/2]). 26 27-include_lib("wx/include/wx.hrl"). 28 29-record(state, 30 { 31 parent, 32 config 33 }). 34 35start(Config) -> 36 wx_object:start_link(?MODULE, Config, []). 37 38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 39init(Config) -> 40 wx:batch(fun() -> do_init(Config) end). 41 42do_init(Config) -> 43 Parent = proplists:get_value(parent, Config), 44 Panel = wxPanel:new(Parent, []), 45 46 %% Setup sizers 47 MainSizer = wxBoxSizer:new(?wxVERTICAL), 48 Sizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel, 49 [{label, "Horizontal wxSlider"}]), 50 Sizer2 = wxStaticBoxSizer:new(?wxHORIZONTAL, Panel, 51 [{label, "Vertical wxSlider"}]), 52 53 %% Setup slider with range from 0 to 100 54 %% and a start value of 25 55 Min = 0, 56 Max = 100, 57 StartValue = 25, 58 %% Horizontal slider (default) with label 59 Slider = wxSlider:new(Panel, 1, StartValue, Min, Max, 60 [{style, ?wxSL_HORIZONTAL bor 61 ?wxSL_LABELS}]), 62 %% Horizontal inverse slider with label 63 InverseSlider = wxSlider:new(Panel, 2, StartValue, Min, Max, 64 [{style, ?wxSL_HORIZONTAL bor 65 ?wxSL_LABELS bor 66 ?wxSL_INVERSE}]), 67 VerticalSlider = wxSlider:new(Panel, 3, StartValue, Min, Max, 68 [{style, ?wxSL_VERTICAL bor 69 ?wxSL_LABELS}]), 70 InverseVerticalSlider = wxSlider:new(Panel, 4, StartValue, Min, Max, 71 [{style, ?wxSL_VERTICAL bor 72 ?wxSL_LABELS bor 73 ?wxSL_INVERSE}]), 74 75 %% Add to sizers 76 wxSizer:add(Sizer, Slider, [{flag, ?wxEXPAND}]), 77 wxSizer:add(Sizer, InverseSlider, [{flag, ?wxEXPAND}]), 78 wxSizer:add(Sizer2, VerticalSlider, [{flag, ?wxEXPAND}, 79 {proportion, 1}]), 80 wxSizer:add(Sizer2, InverseVerticalSlider, [{flag, ?wxEXPAND}, 81 {proportion, 1}]), 82 83 wxSizer:add(MainSizer, Sizer, [{flag, ?wxEXPAND}]), 84 wxSizer:add(MainSizer, Sizer2, [{flag, ?wxEXPAND}, 85 {proportion, 1}]), 86 87 wxPanel:setSizer(Panel, MainSizer), 88 {Panel, #state{parent=Panel, config=Config}}. 89 90%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 91%% Async Events are handled in handle_event as in handle_info 92handle_event(Ev = #wx{}, State = #state{}) -> 93 demo:format(State#state.config,"Got Event ~p\n",[Ev]), 94 {noreply, State}. 95 96%% Callbacks handled as normal gen_server callbacks 97handle_info(Msg, State) -> 98 demo:format(State#state.config, "Got Info ~p\n",[Msg]), 99 {noreply, State}. 100 101handle_call(shutdown, _From, State=#state{parent=Panel}) -> 102 wxPanel:destroy(Panel), 103 {stop, normal, ok, State}; 104 105handle_call(Msg, _From, State) -> 106 demo:format(State#state.config,"Got Call ~p\n",[Msg]), 107 {reply, {error, nyi},State}. 108 109handle_cast(Msg, State) -> 110 io:format("Got cast ~p~n",[Msg]), 111 {noreply,State}. 112 113code_change(_, _, State) -> 114 {stop, ignore, State}. 115 116terminate(_Reason, _State) -> 117 ok. 118 119%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 120%% Local functions 121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 122 123